Page 1 of 1
Stupid question but I don't know how to search for an answer
Posted: Mon May 16, 2005 4:18 pm
by andrei.mita
It's really a stupid question but I don't know how to look for it with google or anything else. I wrote a php script (with your help) that get's all the users from a db and displays them as links to another page. The other page will load the entire row in the db for the user you clicked on. I wanted to know how to make the last page understand wich user's info to show. Don't know for sure how to explain it but I think that something like
Code: Select all
example_page.php?username=user_from_db
should do the job. It is corect? Can you please point me to some other info for the "?" usage in php.
Thanks.
PS: I wouldn't ask so many stupid questions and I would read more on my own but I have a deadline for presenting my first php website.
Posted: Mon May 16, 2005 4:29 pm
by Burrito
anything after the ? will be considered a variable in PHP (and pretty much any other web scripting language).
in your case, as long as the user name is unique, you could query the database for that user name and return all of the information about that user name.
use the $_GET['varname'] array for your variable(s). To add more variables to the url string, separate them with the & sign.
ex:
http://www.mydomain.com/mypage.php?myva ... myvar2=jim
Posted: Tue Jul 12, 2005 11:22 am
by Zoram
I'm trying to figure out a way to detect if the ? has been used in the address so that I can add an extra variable in the address bar or whether the code needs to add the ?...
for example:
I want to have a funtion that will add a variable to the current address as a link.
Current Page: page.php?Print=Full
inside page I add a AddVarLink("Show=10") as a link. The idea is that the function would return the PHP_SELF but as page.php?Print=Full&Show=10 or if the Print=Full wasn't in the original page it would return page.php?Show=10
Any Ideas...
Posted: Tue Jul 12, 2005 12:08 pm
by Burrito
look at $_SERVER['QUERY_STRING']
Posted: Tue Jul 12, 2005 12:15 pm
by Zoram
Thanks, This is what I came up with:
Code: Select all
$pre = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
return ($_SERVER['QUERY_STRING'])? $pre . "?" . $_SERVER['QUERY_STRING'] . "&" . $addPortion : $pre . "?" . $addPortion;