Jump to content

PHP TO MYSQL PROBLEM


DEVILofDARKNESS

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.