ananaz Posted December 24, 2010 Share Posted December 24, 2010 Hello im wondering how i can make a hyperlinks adress be a set after a variable. this is my php: $result1 = mysql_query("SELECT id, namn, url FROM stuff ORDER BY id desc limit 1;"); $result2 = mysql_query("SELECT id, namn, url FROM stuff ORDER BY id desc limit 1,1;"); <html> <a href="???"> <p class="note-general"> The first link </p> <a href="???"> <p class="note-general"> The the second link </p> </html> The important thing is that the url from $result1 will link under "the first link" and url from $result2 link under "the second link". Quote Link to comment https://forums.phpfreaks.com/topic/222575-php-variable-in-hyperlink/ Share on other sites More sharing options...
revraz Posted December 24, 2010 Share Posted December 24, 2010 <a href=<?php $row1 = mysql_fetch_row($result1);echo $row1[2];?> > <p class="note-general"> The first link </p> <a href=<?php $row2 = mysql_fetch_row($result2);echo $row2[2];?> > <p class="note-general"> The second link </p> Quote Link to comment https://forums.phpfreaks.com/topic/222575-php-variable-in-hyperlink/#findComment-1151078 Share on other sites More sharing options...
revraz Posted December 24, 2010 Share Posted December 24, 2010 But you can do it with 1 query instead of two if you just loop through the two results. Quote Link to comment https://forums.phpfreaks.com/topic/222575-php-variable-in-hyperlink/#findComment-1151079 Share on other sites More sharing options...
ananaz Posted December 24, 2010 Author Share Posted December 24, 2010 will: <?php $row1 = mysql_fetch_row($result1);echo $row1[2];?> take the url field data from the row selected? Quote Link to comment https://forums.phpfreaks.com/topic/222575-php-variable-in-hyperlink/#findComment-1151080 Share on other sites More sharing options...
floridaflatlander Posted December 24, 2010 Share Posted December 24, 2010 I'd do it like this $result1 = mysql_query("SELECT id, namn, url FROM stuff ORDER BY id desc limit 1;") $link1 = $result1; $result2 = mysql_query("SELECT id, namn, url FROM stuff ORDER BY id desc limit 1,1;"); $link2 = $result2; <html> <a href="<echo ''.$link1.'';?>"> <p class="note-general"> The first link </p></a> <a href="<echo ''.$link2.'';?>"> <p class="note-general"> The the second link </p></a> </html> (should the href be inside of the p tag?) Quote Link to comment https://forums.phpfreaks.com/topic/222575-php-variable-in-hyperlink/#findComment-1151081 Share on other sites More sharing options...
ananaz Posted December 24, 2010 Author Share Posted December 24, 2010 but i only want to have the url data in the hyperlink href should be outside Quote Link to comment https://forums.phpfreaks.com/topic/222575-php-variable-in-hyperlink/#findComment-1151082 Share on other sites More sharing options...
revraz Posted December 24, 2010 Share Posted December 24, 2010 That won't work, only thing you'll do there is echo the resource id. Quote Link to comment https://forums.phpfreaks.com/topic/222575-php-variable-in-hyperlink/#findComment-1151083 Share on other sites More sharing options...
ananaz Posted December 24, 2010 Author Share Posted December 24, 2010 solved it thank you Quote Link to comment https://forums.phpfreaks.com/topic/222575-php-variable-in-hyperlink/#findComment-1151086 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.