Stupid question but I don't know how to search for an answer

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
andrei.mita
Forum Commoner
Posts: 65
Joined: Sun May 08, 2005 4:06 am
Location: Barlad/Romania

Stupid question but I don't know how to search for an answer

Post 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.
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post 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
User avatar
Zoram
Forum Contributor
Posts: 166
Joined: Sun Aug 18, 2002 3:28 pm
Location: Utah
Contact:

Post 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...
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

look at $_SERVER['QUERY_STRING']
User avatar
Zoram
Forum Contributor
Posts: 166
Joined: Sun Aug 18, 2002 3:28 pm
Location: Utah
Contact:

Post 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;
Post Reply