Jump to content

Query not working the way I want it to


Shockhazard30

Recommended Posts

This query is supposed to pull the three links that are in the database out, but instead it pulls the first link out and displays it three times? any suggestions?

 

$conn  = mysql_connect("localhost", "root", "pass");
$select = mysql_select_db("main", $conn);
$sql = "SELECT * FROM links";
$result = mysql_query($sql);
$row = mysql_fetch_assoc($result);
$addy = $row["address"];
$display = $row["linkdisplay"];
   

	 for ($i = 0; $i < 3; $i++){
		print "<A Class = 'link1' HREF='$addy'>$display</a>";
	 }//end for

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/191478-query-not-working-the-way-i-want-it-to/
Share on other sites

Thanks for the resource this is what I have now:

$conn  = mysql_connect("localhost", "root", "pass");
$select = mysql_select_db("main", $conn);
$sql = "SELECT * FROM links";
$result = mysql_query($sql);
$row = mysql_fetch_assoc($result);

$linkdata = "<A Class = 'link1' HREF='";
$blinkdata = "'>";

while($row = mysql_fetch_array($result)){
echo "$linkdata" . $row['address'] . "$blinkdata" . $row['linkdisplay'] . "</a>";
//echo $row['address']. " - ". $row['linkdisplay'];
echo "<br />";
}

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.