Author Topic: Query not working the way I want it to  (Read 121 times)

0 Members and 1 Guest are viewing this topic.

Offline Shockhazard30Topic starter

  • Irregular
    • View Profile
Query not working the way I want it to
« on: February 09, 2010, 08:18:11 AM »
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

Offline jskywalker

  • Enthusiast
  • Gender: Male
    • View Profile
Re: Query not working the way I want it to
« Reply #1 on: February 09, 2010, 08:41:49 AM »
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

Offline Shockhazard30Topic starter

  • Irregular
    • View Profile
Re: Query not working the way I want it to
« Reply #2 on: February 09, 2010, 09:20:10 AM »
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 />";
	
}

Offline Shockhazard30Topic starter

  • Irregular
    • View Profile
Re: Query not working the way I want it to
« Reply #3 on: February 09, 2010, 09:36:08 AM »
That is not quite working properly, It doesn't look like it pulls the first record from the data base. Any other ideas?

Offline jskywalker

  • Enthusiast
  • Gender: Male
    • View Profile
Re: Query not working the way I want it to
« Reply #4 on: February 09, 2010, 10:04:45 AM »
how often does the "mysql_fetch_array" gets executed before you echo the results?

it think you do it 2 (two) times....

Offline Shockhazard30Topic starter

  • Irregular
    • View Profile
Re: Query not working the way I want it to
« Reply #5 on: February 09, 2010, 11:56:28 AM »
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.
« Last Edit: February 09, 2010, 12:05:36 PM by Shockhazard30 »

PHP Freaks Forums

« on: »

Tired of these ads? Purchase a supporter subscription to get rid of them.