-1

We are wondering how we would add parameters to the following script so that each section can be called separately.

<?php
// This is the content we want to display
$data = <<<EOT
<div class="topbar">
My Text goes here
</div>
EOT;
// Output JavaScript code to write the data
printf('document.write(unescape("%s"));',
  rawurlencode($data));
?>

so what we would like to do is be able to call a single section or div section by using something like "http://my website.com/thisscript?n=5" we just need to be able to output each section individually without the rest.

Thank you.

3
Contributors
32
Replies
33
Views
7 Years
Discussion Span
Last Post by almostbob
0

I would think you could just throw it into an if statement no?

if($something <<condition here>>){
$data = <<<EOT
<div class="topbar">
My Text goes here
</div>
EOT;
// Output JavaScript code to write the data
printf('document.write(unescape("%s"));',
  rawurlencode($data));  }
else { <<do something here>> }

Something like that maybe?

0

Well unfortunately im relatively new to php so im not entirely sure what the above means.

If you could provide a little explenation that would be great.

0

Well you only have one div there. Do you want it to display if a certain condition exists, for example > if this button is clicked, show this div ? Not sure what you mean by displaying it separately.

0

so if we use this

<?php
// This is the content we want to display
$data = <<<EOT
<div class="topbar">
My Text goes here
</div>
<div class="topbar1">
My Text goes here
</div>
EOT;
// Output JavaScript code to write the data
printf('document.write(unescape("%s"));',
  rawurlencode($data));
?>

We would like to be able to call and display each div separately. Or show the text inside the divs individually with a call to them.

0

What we are trying to achieve it to update text on different pages with one file, so we need to have div 1 display on one page and div 2 display on another when we link to this file.

0

First I would think you want to echo your html output if you are nesting it a <?php tag like so

<?php
// This is the content we want to display
$data = <<<EOT
echo '
<div class="topbar">
My Text goes here
</div>';

So if you click "link1" topbar div should show on that page and if you click "link2" topbar1 div should show on a different page?
?>

0

ok when I do that it shows both of the messages how would I seperate them to call them differently?
Also I am not trying to use buttons to call them, I am using javascript to call the output and inject it into the html page.

0

What does the script look like that you are inserting into the head of the document?

0

Sorry, was going to say something else here but realized it didn't pertain to your problem

Edited by CFROG: n/a

0

Ok in short all I am trying to do is use one file to insert text dynamicly to update page, so here is what I am doing.

So all I need to be able to do is some how output the different sections so I can use links like such http://index.php?text=this to show the text from the specific div tag or id tag.

Im sorry this is hard but Im still in the begining stages of learning php.

0

using :: file.php?text=this as example

if else

<?php
if (!$text) {die('No text selected');}
elseif($text='this') {echo '<div class="topbar">This Text goes here</div>'; }
elseif($text='that') {echo '<div class="topbar">That Text goes here</div>'; }
?>

switch / case

switch ($text) {
case '':
die('No text selected');
break;
case 'this':
echo '<div class="topbar">This Text goes here</div>';        
break;
case 'that':
echo '<div class="topbar">That Text goes here</div>';        
break;
}

Edited by almostbob: n/a

0

There ya' go, if anyone has the solution to your problem Almostbob is your guy. Sorry I couldn't be of more help, still a little confused about what you're trying to do.

0

If you just want the text to show in your URL just incorporate it into your link

echo '<a href="my_link.php?text=".$text."">';
0
<?php
if (!$text) {die('No text selected');}
elseif($text='this') {echo '<div class="topbar">anything you like, once php has processed it its just html goes here</div>'; }
elseif($text='that') {echo '<div class="topbar">anything else you like, once php has processed it its just html goes here</div>'; }
 
switch ($text) {
case '':
die('No text selected');
break;
case 'this':
echo '<div class="topbar">anything you like, once php has processed it its just html goes here</div>';        
break;
case 'that':
echo '<div class="topbar">anything else you like, once php has processed it its just html goes here</div>'; 
include ("./menu.php"); 
echo "<br class='dontprint'><p style='margin:0;padding:0'>Property rules<br>All  properties are subject to the following landlord's rules<br>Characters in <i>italic</i> text refer to definitions, acts, and regulations. <br><b><i>Motor Vehicle Act 1989 R.S.,c.293,s.1</i></b> hereafter referred to as (<b><i>MVA</i></b>)<br><b><i>Protection of Property Act 1989 R.S.,c.363,s.1.</i></b> hereafter referred to as (<b><i>PPA</i></b>) <br><b><i>Residential Tenancies Act 1989 R.S.,c.401,s.1</i></b> hereafter referred to as (<b><i>RTA</i></b>) <br><b><i>Domestic Violence Intervention Act. 2001, R.S.,c. 29, s. 1. </i></b><i> </i>hereafter referred to as (<b><i>DVIA</i></b>)<br><b><i>Smoke-free Places Act. 2002 R.S.,c.12.s.1</i> </b>hereafter referred to as (<b><i>SFPA</i></b>)<br>All regulation definitions and interpretation of the above and all Federal Provincial and Local Laws bylaws and Regulations are confirmed.<br><b>Discrimination is unlawful.</b> The intent of this and all other  Apartments documents is not to discriminate. At all times, any word, phrase, mode of speech, that may be considered gender specific or exclusive is to be read and interpreted as gender neutral or inclusive.<br><b>Definitions:</b> For the purpose of these rules:<br><blockquote style=\"margin:0; margin-left:15px;padding:0;\"><b>Tenant </b>shall be those residents signatory to the lease<br><b>Resident</b> shall include all persons lawfully resident in the property(<i>RTA</i>)<br><b>Guest</b> shall include all visitors of any tenant or resident, and any tradesman employed by any tenant or resident, and any person not lawfully a resident <i>(RTA)</i>.<br><b>Derelict Vehicle</b> shall include any vehicle not currently registered insured and within inspection date for operation on public roads in the province of Nova Scotia.<br><b>Off Road Vehicle </b>shall include any vehicle not permitted to be registered for normal operation on public roads in the province of Nova Scotia, <b><u>and</u></b> disregarding any registration of the vehicle shall include any boat trailer travel trailer fifth wheel trailer motor home bus or camper.<br><b>Notice of breach of rule</b> shall be any written notice by the landlord or his agent delivered in hand, to the mailbox, or under the apartment door of the residence notifying the tenant of any breach of rule.<br><b>Proof of delivery </b>shall be the dated signature of the landlord or his agent on the landlord copy of the written notice of breach of rule, or any dated note in the landlord's diary, of the delivery of notice of breach of rule.</blockquote><h3 style='margin:0;padding:0;'>Public Safety</h3><ol style='margin-top:0;'><li>The breach of any property &quot;Public Safety&quot; or &quot;Amenity&quot; rule by any tenant resident or guest, shall unless immediately rectified, be grounds to issue a notice to quit <i>RTA.</i>10(7A) (five day notice to quit) to the responsible tenant.<li>Any second or subsequent breach by any tenant resident or guest of any property &quot;Public Safety&quot; or &quot;Amenity&quot; rule shall be grounds to issue a notice to quit <i>RTA.</i>10(7A) to the responsible tenant. <li>Tenants are responsible, and liable, for the conduct and actions of all residents and guests.<li>Guests have no implicit right to enter the property and must leave if asked by the landlord or his agent to vacate the property.";

echo "thats the idea anyway";
break;
}
?>

Edited by almostbob: n/a

0

When I was asking about how I would use it in a link, I was wondering how I would call each section by a link so that only that section of text showed.

0

I would think you would just use the link like

echo '<a href="my_link.php?text=".$text."">';

have the link point to the page your are updating and then use GET

$text=$_GET['text'];

Then use a conditional if statement like AlmostBob showed you to display the text according the value of $text passed through the URL

0

the problem that I am having is that im using javascript to display this on html pages

0

AlmostBob would the guy to help you there. Is the Java necessary or could you just code it differently using php?

0

well I have the javascript part done its just this part that I need to get done. Now here is what the javascript tutorial said about the php part

The examples so far assume that every website would display the same syndicated content, but you can use parameters to customize the output for each of your syndication partners.

For example, if your PHP script accepted a parameter n, then you could specify n=5 when you fetch the JavaScript syndication file:

0

At this moment the only thing I can get to display on his code is "No text selected" So im still working on getting it to display the sections of the php.

0

Even though Im not sure what a variable is well not completely anyways, but im guessing its the $text='this' in the code, but question is why it the code not working when it should be.

Oh and the $n=5 was just an example

Im so lost :( but i need to learn it so, thanks for your patience :)

0

Yes, $text='this' is the variable. Actually $text is the variable and 'this' is it's value. There are many ways to assign a value to a variable. What part of your script is asking for a variable from php ?

0

No part is asking for the variable, I just use javascript to pull information from a url, so I just need the script to be able to parse the information into sections.

From what I understand almostbobs script would allow me to pull information from the sections using script.php?text=this but when I try that it displays nothing.

Do you have any ideas why its not displaying anything when I believe it should be.

0

why javascript
javascript is blocked on a large proportion of the potential market
passing as a url, the page is being reloaded
best practice; prepare the page serverside, then you can be sure its working as intended
the whole thing appears to be able to be a single php script,
but the description of the task, is terribly incomplete,
post the code in whole there may be something simple

IF you want to integrate javascript and php examine AJAX

Edited by almostbob: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.