Jump to content


Photo

Php / Mysql select issue


  • Please log in to reply
5 replies to this topic

#1 Prank

Prank
  • Members
  • PipPip
  • Member
  • 25 posts
  • LocationSydney, AUS

Posted 30 August 2006 - 03:59 AM

Hi Guys,

I have a table with 5 records in it, when I select the records (even just using SELECT * FROM cars) it will sometimes retrieve 3 records and sometimes 4, never the whole amount. I have never seen this happen before. If I run the query in phpmyadmin it returns all records. I dont understand how this could happen, the Statement could not be more simple.

Anyone know why this could be happening?

Christian
The way to a mans stomach is through his heart.

#2 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 30 August 2006 - 05:27 AM

please post the code that you are using to retrieve and display the information.
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#3 Prank

Prank
  • Members
  • PipPip
  • Member
  • 25 posts
  • LocationSydney, AUS

Posted 30 August 2006 - 05:31 AM

Its happening in several places, each with re-written code.

The code couldnt be more simple.

Heres one example;
        $q = "SELECT * FROM cars";
	$qr = mysql_query($q) or die(mysql_error());
	$r = mysql_fetch_assoc($qr);

	echo '<strong>Select a link category</strong><br />';

	while($r = mysql_fetch_assoc($qr)){

		echo '<a href="links.php?do=listlinks&cat='.$r['name'].'">'.$r['name'].'</a><br />';

	} // while

Thanks.
The way to a mans stomach is through his heart.

#4 Satria Ox41464b

Satria Ox41464b
  • Members
  • PipPip
  • Member
  • 18 posts

Posted 30 August 2006 - 05:33 AM

<?php
        $q = "SELECT * FROM cars";
	$qr = mysql_query($q) or die(mysql_error());
	$r = mysql_fetch_assoc($qr); // <- You already get one row here

	echo '<strong>Select a link category</strong><br />';

	while($r = mysql_fetch_assoc($qr)){
        // and ofcourse overhere total loops will be minus one of total rows
		echo '<a href="links.php?do=listlinks&cat='.$r['name'].'">'.$r['name'].'</a><br />';

	} // while
?>


#5 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 30 August 2006 - 05:34 AM

howcome you do a mysql_fetch_assoc, and then do a loop with it again? when you do it the first time, it increments the internal pointer, so that when you start your loop, it starts on the next position, so you're missing out on echoing the first row.
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#6 Prank

Prank
  • Members
  • PipPip
  • Member
  • 25 posts
  • LocationSydney, AUS

Posted 30 August 2006 - 05:37 AM

Ahh crap, I didnt even pick up on that.

Thanks heaps.
The way to a mans stomach is through his heart.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users