knaj11 Posted April 4, 2010 Share Posted April 4, 2010 i want each result of my query to have a link or be in a <a href =" "> tag.. code is this... $query = "select artist from lyrics where artist like 'a%' order by artist ASC"; $result = mysql_query($query) or die ("Error in query: $query . " . mysql_query()); if (mysql_num_rows($result) > 0) { while ($row = mysql_fetch_object($result)) { ?> <?php echo $row->artist; ?><br> <?php } } else { echo 'No Content'; } the result of this code is just this.... Adam Sandler Aqua Avril Lavigne all w/o links... how can i have the resulting queries have links??? Link to comment https://forums.phpfreaks.com/topic/197525-a-href-to-each-result-in-a-query/ Share on other sites More sharing options...
Matthias_ Posted April 4, 2010 Share Posted April 4, 2010 $query = "select artist from lyrics where artist like 'a%' order by artist ASC"; $result = mysql_query($query) or die ("Error in query: $query . " . mysql_query()); if (mysql_num_rows($result) > 0) { while ($row = mysql_fetch_object($result)) { echo "<a href = \"somepage.php\">$row->artist;</a>"; } } else { echo 'No Content'; } Not sure if it is echo "<a href = \"somepage.php\">$row->artist;</a>"; or echo "<a href = \"somepage.php\">$row->artist</a>"; Link to comment https://forums.phpfreaks.com/topic/197525-a-href-to-each-result-in-a-query/#findComment-1036693 Share on other sites More sharing options...
GoneNowBye Posted April 4, 2010 Share Posted April 4, 2010 echo('<a href="view_artist_details.php?id='.$row->id.'">'.$row->artist.'</a><br>'); your welcome Link to comment https://forums.phpfreaks.com/topic/197525-a-href-to-each-result-in-a-query/#findComment-1036704 Share on other sites More sharing options...
knaj11 Posted April 4, 2010 Author Share Posted April 4, 2010 thanks alot both of you it really did work... Link to comment https://forums.phpfreaks.com/topic/197525-a-href-to-each-result-in-a-query/#findComment-1036744 Share on other sites More sharing options...
knaj11 Posted April 6, 2010 Author Share Posted April 6, 2010 bout the double post.... i think you got it all wrong... my first post w/ subject "SELECT QUERY HELP" was on how to query something base on its first letter.... my second post w/subject "a href to each result in a query" was on how my result queries to have links on it... just to clear things up mod fenway.. im not sure if my pm for you was sent it was not in my sent items so i did it here instead. Link to comment https://forums.phpfreaks.com/topic/197525-a-href-to-each-result-in-a-query/#findComment-1037731 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.