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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hyperlink in Query Results? 1

Status
Not open for further replies.

skicamel

Programmer
Dec 24, 2001
126
US
Using a basic query for example...

The search page asks for a name. You enter "Dan". This pulls up in a table on the results page something similar to this:

ID Name Email
17 Dan dan@email.address
35 Daniel Daniel@email.address
64 Danielle danielle@email.address

The goal here, is to have the ID fields show up as links to another results page, say, pulling activity from a log table.

I don't mind doing the research to get the syntax properly, but if anyone can point me in the right direction, that would be much appreciated.
 
Something like this?

[Assuming you already have the database table set up and have a db connection before this in the PHP script...]

$result = mysql_query("SELECT id, name, email FROM users WHERE name LIKE '%$srchstring%'");
while ($myrow = mysql_fetch_array($result)) {
$id = $myrow['id'];
$name = $myrow['name'];
$email = $myrow['email'];
echo (&quot;<TR><TD><A HREF='}

That's off the top of my head, but hope it might give you some direction... :)
Matt
matt@paperlove.org
If I can help, I will.
 
It seems my downfall continues to be using MSSQL insted of MySQL. I never could get the mssql syntax to pull anything. Through much help from this site, I've gotten the odbc pulls working. Odbc_fetch_array doesn't work in PHP 4. I'll keep trying to figure this out working off the above reply (Thanks), but I'll post the base I'm working off of so anyone with the desire can take a crack at it.

$result = odbc_exec($conn, &quot;select num,name,email from users where name like '%$name%' or email like '%$name%' order by name asc&quot;);

for ($i = 1; $i <= odbc_num_fields($result); $i++)
{
echo &quot;<th>&quot;.ucfirst(odbc_field_name($result,$i)).&quot;</th>&quot;;
}

while ($row = odbc_fetch_row($result))
{
echo &quot;<tr>&quot;;
for ($i = 1; $i <= odbc_num_fields($result); $i++)
{
echo &quot;<td>&quot;.(odbc_result($result,$i)).&quot;</td>&quot;;
}
echo &quot;</tr>&quot;;
}
 
Checked out the workaround for odbc_fetch_array in the online manual. The below does exactly what I was after. Couldn't have done it without your help, Matt. Thanks.

$result = odbc_exec($conn_id,$query);

for ($i = 1; $i <= odbc_num_fields($result);$i++)
{
echo &quot;<th>&quot;.ucfirst(odbc_field_name($result,$i)).&quot;</th>&quot;;
}
while (odbc_fetch_into($result,$myrow))
{

$id = $myrow[0];
$name = $myrow[1];
$email = $myrow[2];
echo (&quot;<TR><TD><A HREF='results.php?id=$id'>$id</A></TD><TD>$name</TD><TD>$email</TD></TR>&quot;);
}
 
Just a note to beginners.. Remember that you have to escape the quotes in the link -
<a href=\&quot;mypage.php?var1=$var1&var2=$var2\&quot;>
-Nukoi
I know my stuff.. Hire me.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top