Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing a parm in PHP

Status
Not open for further replies.

USADarts

Programmer
Dec 20, 2004
21
US
Need help with some PHP coding....
A list of people names come up on a web page (ex: The list is created using MySQL and PHP. Links are attached to this list. Each name/link has a seperate username. My link for each one looks as follows:


Is this correct? Would this carry the username field from names.php to selected.php?

What I need to do is carry the username to the page for further use. This page then scans through another MySQL database and selects information based on the username.

Thanks,
David
 
I'm assume you've built the links something like this:
Code:
<a href="[URL unfurl="true"]www.example.com/selected.php?name=JohnDoes">JohnDoe</a>[/URL]
<br />
<a href="[URL unfurl="true"]www.example.com/selected.php?name=BobSmith">BobSmith</a>[/URL]

then in selected.php you would retreive the username like this:
Code:
$username=$_GET['name'];

-Jer
 
Thanks,
However, am i able to use a field instead of a name?


Example:
<a href="www.example.com/selected.php?selected=$row['username']"</a>

I only have one link that loops throught the whole database. This database is added to regularly.

Thank again,
David
 
be more specific.

when you said field. do you mean text box or a column in a table or...?

Provide a sample of your code.

-Jer
 
Yes, you can... I think. If you mean something like this:

Code:
for($i = 0; $i < array_count_values(array); $i++)
{
   print("<a href=\"[URL unfurl="true"]http://example.com/selected.php?name="[/URL] . $array[$i] . "\">" . $array[$i] . "</a><br/>");
}
or
Code:
foreach($array as $name)
{
  print("<a href=\"[URL unfurl="true"]http://example.com/selected.php?name="[/URL] . $name . "\">" . $name . "</a><br/>");
}

And then on the selected page:
Code:
$name = $_GET['name'];
if($name == null || $name == "")
{
  print("Something went wrong.  All your bases are belong to us!");
}
else
{
  //cool stuff
}


[plug=shameless]
[/plug]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top