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> Link to comment https://forums.phpfreaks.com/topic/142336-php-to-mysql-problem/ 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? Link to comment https://forums.phpfreaks.com/topic/142336-php-to-mysql-problem/#findComment-745793 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. Link to comment https://forums.phpfreaks.com/topic/142336-php-to-mysql-problem/#findComment-745807 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! Link to comment https://forums.phpfreaks.com/topic/142336-php-to-mysql-problem/#findComment-745824 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.