Shockhazard30 Posted February 9, 2010 Share Posted February 9, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/191478-query-not-working-the-way-i-want-it-to/ Share on other sites More sharing options...
jskywalker Posted February 9, 2010 Share Posted February 9, 2010 how many times do you do a "mysql_fetch_assoc"? for a nice example look at: http://php.net/manual/en/function.mysql-fetch-assoc.php Quote Link to comment https://forums.phpfreaks.com/topic/191478-query-not-working-the-way-i-want-it-to/#findComment-1009394 Share on other sites More sharing options...
Shockhazard30 Posted February 9, 2010 Author Share Posted February 9, 2010 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 />"; } Quote Link to comment https://forums.phpfreaks.com/topic/191478-query-not-working-the-way-i-want-it-to/#findComment-1009400 Share on other sites More sharing options...
Shockhazard30 Posted February 9, 2010 Author Share Posted February 9, 2010 That is not quite working properly, It doesn't look like it pulls the first record from the data base. Any other ideas? Quote Link to comment https://forums.phpfreaks.com/topic/191478-query-not-working-the-way-i-want-it-to/#findComment-1009404 Share on other sites More sharing options...
jskywalker Posted February 9, 2010 Share Posted February 9, 2010 how often does the "mysql_fetch_array" gets executed before you echo the results? it think you do it 2 (two) times.... Quote Link to comment https://forums.phpfreaks.com/topic/191478-query-not-working-the-way-i-want-it-to/#findComment-1009416 Share on other sites More sharing options...
Shockhazard30 Posted February 9, 2010 Author Share Posted February 9, 2010 Thanks, I just pulled out the first one and left the while loop in... I am sure you can see I am new to this stuff. I appreciate the help. Quote Link to comment https://forums.phpfreaks.com/topic/191478-query-not-working-the-way-i-want-it-to/#findComment-1009493 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.