Jump to content

PHP switch, case, and passing info from one page to another


rawkhopper

Recommended Posts

Hi guys,  I am very new to php and when I started this project I thought I was keeping it simple to just reduce cutting and pasting to a bunch of different pages updates.  Anyway I settled on php with a main page with switch and case to get the job done.  The page works beautifully with one known exception.  One of my pages calls a php page (that I did not write) and uses a ? appended to the URL to pass arguments? to the php page.  If I set the default case to the php page that the arguments need to pass through to then all works well.  But if I set the default to any other page the argument is sent to the default page.  Is there a way to pass the argument to the appropriate page?  I have tried to search for the answer but due to my lack of knowledge I am unsure how to search for the answer. 

 

So to rephrase I have a simple php page that uses switch and case to call other php pages that are really just html.  One of the pages called through a case is a true php page that I did not write.  Arguments, or whatever you call them, are passed through to the php page through a ? in the address bar.  Unfortunately I can only pass arguments in the address bar to the default case.  Can anyone help me send these arguments to a non default page?

Link to comment
Share on other sites

Arrg asked the question but now I feel so stupid.  I did not look to see how the php script that is not mine is sending arguments to itself.  Anyway I figured out what is going on and a slight mod to the script that I did not write will work. Sorry I can't really post examples as that would take too much work since I would have to know more about the php that I didn't write.  My guess is that posting a link to a site is probably frowned upon.  But thanks for the willingness to help out a newb. 

Link to comment
Share on other sites

Well your comment

If your switch is just including pages then it shouldn't be a problem, since the included page can access the $_GET global.

helped me to think about how the other php script (that I didn't write) sent arguments to itself.  It simply tacks on the end of the address its arguments.  I needed to tack my argument into that script.

 

simple example hope it helps

 

$titleLink = sprintf("<a href='?Sermon=%d'>%s</a>", $row['Id'], htmlspecialchars($row['Title']));

 

the script I did not write used this to create a page for a specific audio file.

Unfortunately that will simply pass through to the default page on my php.

 

so I changed my script to include a dummy page that shows every audio file in the database.

case "everything":
$sermonsWebPart = GetSermonsWebPart(array('DefaultSinceWeeks' => All));
@include ('sermonsbanner.php');
@include ('sermons.php');
break;

 

then I modified the line in the script i did not write to

 

             

$titleLink = sprintf("<a href='?cmd=everything&Sermon=%d'>%s</a>", $row['Id'], htmlspecialchars($row['Title']));

 

This then passes the argument through to the appropriate script.

And now I have a working script.

 

Thanks for that little tip.  Sometimes it just takes a couple words to make me rethink things.  Thanks a bunch!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.