Jump to content


Photo

Missing MySQL content


  • Please log in to reply
5 replies to this topic

#1 ScottRiley

ScottRiley
  • Members
  • PipPipPip
  • Advanced Member
  • 59 posts

Posted 16 August 2006 - 03:07 PM

So, I'm trying to echo all the results of an array I achieved from a query, simple enough:

<?php
             echo"Welcome ".$_SESSION['username']."!<BR>";
	echo"You have ".$rows." Business members:<BR>";
	while($array=mysql_fetch_array($result))
	{
		echo "&nbsp;&nbsp;&nbsp;&nbsp;".$array['Username']."<BR>";
	}
              ?>

However, this tells me I have 6 business users, but only echos 5 of them.  I checked the database, and I DO have 6 users, so why is it just echoing just 5?

Thanks in advance
Scott

#2 HeyRay2

HeyRay2
  • Members
  • PipPipPip
  • Advanced Member
  • 223 posts

Posted 16 August 2006 - 03:13 PM

Post the code that runs your querty, and we'll be on the right track to getting this figured out for you... ;)

#3 ScottRiley

ScottRiley
  • Members
  • PipPipPip
  • Advanced Member
  • 59 posts

Posted 16 August 2006 - 04:05 PM

$sql="SELECT * FROM southport_businesses";
	$result=mysql_query($sql);
	$rows=mysql_num_rows($result);
	$array=mysql_fetch_array($result);
code]


#4 czambran

czambran
  • Staff Alumni
  • Advanced Member
  • 52 posts
  • LocationFairfield,IA

Posted 16 August 2006 - 05:07 PM

WHen are u assigning a value to the variable $rows? Are you sure one of the username is not just a blank?
Chris
Using undefined variables in PHP is not an error, just sloppy coding practice. PHP5 Power Programming BOOK
--------------------------------------------------------------------------
PHP F.A.Q.
Linux User #394154

#5 bbaker

bbaker
  • Members
  • PipPipPip
  • Advanced Member
  • 127 posts
  • LocationNY

Posted 16 August 2006 - 05:17 PM

$sql="SELECT * FROM southport_businesses";
	$result=mysql_query($sql);
	$rows=mysql_num_rows($result);
	$array=mysql_fetch_array($result);

try removing
$array=mysql_fetch_array($result);
from this bit, since you're using it in your while statement, thus:
<?php
$sql="SELECT * FROM southport_businesses";
$result=mysql_query($sql);
$rows=mysql_num_rows($result);

echo"Welcome ".$_SESSION['username']."!<BR>";
echo"You have ".$rows." Business members:<BR>";
while($array=mysql_fetch_array($result))
{
   echo "&nbsp;&nbsp;&nbsp;&nbsp;".$array['Username']."<BR>";
}
?>



#6 ScottRiley

ScottRiley
  • Members
  • PipPipPip
  • Advanced Member
  • 59 posts

Posted 17 August 2006 - 07:57 AM

Thanks a lot bbaker, its sorted now, I just removed it like you said.  Thanks ;D




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users