some clarification with Databa communication using php,mysql

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
harishreddy
Forum Newbie
Posts: 5
Joined: Sun Mar 08, 2009 12:22 am

some clarification with Databa communication using php,mysql

Post by harishreddy »

$query="select * from emp where ename='$ename' and empno='$empno'";
print "<br>".$query;
$result=mysql_query($query);
print "<br>".$result."<br>";
//print if($result);
if($result)
{
print_r(mysql_fetch_array($result));
while($row=mysql_fetch_array($result))
{
echo "This is from Stalinreddy";
echo "<br>".$row['ename'];
}

}


in the above code with in the if loop only one statement (i.e if we write print_r() first then it will excuted other wise whil)either print_r() or while loop is excuted ,(both are not excuted),can any body give me a explanation
JeffG
Forum Commoner
Posts: 35
Joined: Wed Jan 30, 2008 1:42 pm
Location: Newbury, UK

Re: some clarification with Databa communication using php,mysql

Post by JeffG »

As the manual clearly states:
Remember that print_r() will move the array pointer to the end. Use reset() to bring it back to beginning.
Edit: No it's not that because you are calling mysql_fetch_array twice.

Try this (also from the manual):
array mysql_fetch_array ( resource $result [, int $result_type] )

Returns an array that corresponds to the fetched row and moves the internal data pointer ahead.
Post Reply