DEVILofDARKNESS Posted January 25, 2009 Share Posted January 25, 2009 The following code works perfect with my database and gives me a list with PName and UName. The problem is that they all have the same link? What have I done wrong? <html> <head><title>Gedichten</title> </head> <body> <?php require_once 'config.php'; // our database settings $conn = mysql_connect($dbhost,$dbuser,$dbpass) or die('Error connecting to mysql'); mysql_select_db($dbname); $query = sprintf("SELECT URL FROM liefde ORDER BY PName DESC"); $result = mysql_query($query); while($urlgedicht = mysql_fetch_array($result)) { $query = sprintf("SELECT PName,UName,PText From liefde ORDER BY PName DESC"); $result = mysql_query($query); while($gedichten = mysql_fetch_array($result)) { print "<ul><li><a href={$urlgedicht['URL']}.htm>{$gedichten['PName']} | {$gedichten['UName']}</a></li></ul>"; } } ?> </body> </html> Quote Link to comment Share on other sites More sharing options...
krv Posted January 25, 2009 Share Posted January 25, 2009 ugh messy. $query = " SELECT Pname,Uname,PText,URL FROM liefde ORDER BY PName DESC"; why do you have 2 whiles if its same table? Quote Link to comment Share on other sites More sharing options...
Mikedean Posted January 25, 2009 Share Posted January 25, 2009 I think the following code will do what you want. $query = sprintf("SELECT PName,UName,PText,URL FROM liefde ORDER BY PName DESC"); $result = mysql_query($query); while($urlgedicht = mysql_fetch_array($result)) { print "<ul><li><a href={$urlgedicht['URL']}.htm>{$urlgedicht['PName']} | {$urlgedicht['UName']}</a></li></ul>"; } Basically removing the second query. Quote Link to comment Share on other sites More sharing options...
DEVILofDARKNESS Posted January 25, 2009 Author Share Posted January 25, 2009 Thank you, I just looked over it again andagain , stupid Me! Quote Link to comment 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.