web.dork Posted April 1, 2007 Share Posted April 1, 2007 1:30am and I'm stumped... So I've created a database that has the following fields: id (int) lastname (varchar) firstname (varchar) etc etc I'm able to query the DB and produce the FULL field list results as I need them (in DESC order), but my question is how do I generate the field 'id' into a hyperlink that will be formatted as mysite.com/query.php/id=(id number)? Any help would be greatly appreciated! Link to comment https://forums.phpfreaks.com/topic/45120-solved-hyperlinking-a-single-field-from-a-mysql-query-using-php/ Share on other sites More sharing options...
web.dork Posted April 1, 2007 Author Share Posted April 1, 2007 BTW... here is some of my code.... <? $hostname="myhost.com"; $u="myuname"; $p="mypass"; $db="mydb"; $link = mysql_connect($hostname,$u, $p) OR DIE ("Unable to connect to database! Please try again later."); if (! $link) die("Couldn't connect to MySQL"); mysql_select_db($db , $link) or die("Couldn't open $db: ".mysql_error()); $result = mysql_query( "SELECT * FROM `Mytable` ORDER BY `Mytable` . `lastupdated` ASC LIMIT 0, 30" ) or die("SELECT Error: ".mysql_error()); $num_rows = mysql_num_rows($result); print "<center><table width=800 border=1><tr><td><font face=arial size=2/>Full List</td></tr></table></center>"; print "<center><table width=800 border=1>\n"; while ($get_info = mysql_fetch_row($result)){ print "<tr>\n"; foreach ($get_info as $field) print "<td><font face=arial size=2/>$field</font></td>\n"; print "</tr>\n"; } print "</table></center>\n"; mysql_close($link); ?> Link to comment https://forums.phpfreaks.com/topic/45120-solved-hyperlinking-a-single-field-from-a-mysql-query-using-php/#findComment-219049 Share on other sites More sharing options...
shocker-z Posted April 1, 2007 Share Posted April 1, 2007 $query = mysql_query("SELECT * FROM tablename ORDER BY lastname DESC"); while ($row=mysql_fetch_array($query)) { echo "<a href='http://www.mysite.com/query.php?id=$row[id]'>$row[firstname] $row[lastname]</a> <Br>"; } That will echo a link call what ever there name is with the appropriate ID in the link. EDIT: Your code wont be able to do it as your looping field which needs to be held in an array to do it the simplest way also you table code below need to be change as its not correct at the minute. print "<center><table width=800 border=1><tr><td><font face=arial size=2/>Full List</td></tr></table></center>"; print "<center><table width=800 border=1>\n"; while ($get_info = mysql_fetch_row($result)){ print "<tr>\n"; foreach ($get_info as $field) print "<td><font face=arial size=2/>$field</font></td>\n"; print "</tr>\n"; } print "</table></center>\n"; mysql_close($link); ?> should be print "<center><table width=800 border=1><tr><td><font face=arial size=2/>Full List</td></tr></table></center>"; print "<center><table width=800 border=1>\n"; while ($get_info = mysql_fetch_row($result)){ print "<tr>\n"; foreach ($get_info as $field) print "<td><font face=arial size=2/>$field</font></td>\n"; } print "</tr>\n"; } print "</table></center>\n"; mysql_close($link); ?> Changed the print "</tr>\n"; because if its inside the loop then it echos it on every field but i take it you want it as a table all fields going across the top and then next row and next row and so on... also added an extra brace as you hadnt closed you while loop Regards Liam Link to comment https://forums.phpfreaks.com/topic/45120-solved-hyperlinking-a-single-field-from-a-mysql-query-using-php/#findComment-219050 Share on other sites More sharing options...
web.dork Posted April 1, 2007 Author Share Posted April 1, 2007 Sweeeeeeeet! Worked like a charm!!!! Many thanx Liam.... now I'll be able to sleep tonite (eventually)... Link to comment https://forums.phpfreaks.com/topic/45120-solved-hyperlinking-a-single-field-from-a-mysql-query-using-php/#findComment-219052 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.