954,585 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to add parameters to a php script

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.

valonesal
Junior Poster
121 posts since Aug 2009
Reputation Points: 10
Solved Threads: 2
 

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?

CFROG
Posting Pro in Training
408 posts since Jul 2009
Reputation Points: 21
Solved Threads: 31
 

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.

valonesal
Junior Poster
121 posts since Aug 2009
Reputation Points: 10
Solved Threads: 2
 

What sections do you want to call separately? Sections of the code itself?

CFROG
Posting Pro in Training
408 posts since Jul 2009
Reputation Points: 21
Solved Threads: 31
 

we just want to call the text in the div tags seperately

valonesal
Junior Poster
121 posts since Aug 2009
Reputation Points: 10
Solved Threads: 2
 

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.

CFROG
Posting Pro in Training
408 posts since Jul 2009
Reputation Points: 21
Solved Threads: 31
 

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.

valonesal
Junior Poster
121 posts since Aug 2009
Reputation Points: 10
Solved Threads: 2
 

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.

valonesal
Junior Poster
121 posts since Aug 2009
Reputation Points: 10
Solved Threads: 2
 

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?
?>

CFROG
Posting Pro in Training
408 posts since Jul 2009
Reputation Points: 21
Solved Threads: 31
 

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.

valonesal
Junior Poster
121 posts since Aug 2009
Reputation Points: 10
Solved Threads: 2
 

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

CFROG
Posting Pro in Training
408 posts since Jul 2009
Reputation Points: 21
Solved Threads: 31
 

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

CFROG
Posting Pro in Training
408 posts since Jul 2009
Reputation Points: 21
Solved Threads: 31
 

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.

valonesal
Junior Poster
121 posts since Aug 2009
Reputation Points: 10
Solved Threads: 2
 

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;
}
almostbob
Posting Sensei
3,149 posts since Jan 2009
Reputation Points: 571
Solved Threads: 376
 

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.

CFROG
Posting Pro in Training
408 posts since Jul 2009
Reputation Points: 21
Solved Threads: 31
 

how will I be able to use it for urls?

valonesal
Junior Poster
121 posts since Aug 2009
Reputation Points: 10
Solved Threads: 2
 

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."">';
CFROG
Posting Pro in Training
408 posts since Jul 2009
Reputation Points: 21
Solved Threads: 31
 
<?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 rulesAll  properties are subject to the following landlord's rulesCharacters in <i>italic</i> text refer to definitions, acts, and regulations. <b><i>Motor Vehicle Act 1989 R.S.,c.293,s.1</i></b> hereafter referred to as (<b><i>MVA</i></b>)<b><i>Protection of Property Act 1989 R.S.,c.363,s.1.</i></b> hereafter referred to as (<b><i>PPA</i></b>) <b><i>Residential Tenancies Act 1989 R.S.,c.401,s.1</i></b> hereafter referred to as (<b><i>RTA</i></b>) <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>)<b><i>Smoke-free Places Act. 2002 R.S.,c.12.s.1</i> </b>hereafter referred to as (<b><i>SFPA</i></b>)All regulation definitions and interpretation of the above and all Federal Provincial and Local Laws bylaws and Regulations are confirmed.<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.<b>Definitions:</b> For the purpose of these rules:<blockquote style=\"margin:0; margin-left:15px;padding:0;\"><b>Tenant </b>shall be those residents signatory to the lease<b>Resident</b> shall include all persons lawfully resident in the property(<i>RTA</i>)<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>.<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.<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.<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.<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;
}
?>
almostbob
Posting Sensei
3,149 posts since Jan 2009
Reputation Points: 571
Solved Threads: 376
 

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.

valonesal
Junior Poster
121 posts since Aug 2009
Reputation Points: 10
Solved Threads: 2
 

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

CFROG
Posting Pro in Training
408 posts since Jul 2009
Reputation Points: 21
Solved Threads: 31
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You