problem related to the fucntion mysql_num_rows($qResult) ...

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
code_warrior
Forum Newbie
Posts: 1
Joined: Thu Aug 24, 2006 10:09 pm

problem related to the fucntion mysql_num_rows($qResult) ...

Post by code_warrior »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


when i use 

"$rows = mysql_num_rows($qResult);"
where "mysql_num_rows($qResult)" is a built in PHP function.

$rows containts all the rows effected by passed $qResult.

assume the $rows containts rows of a table which has headings as 
"name", "address", "phone". 

if we try to acess them via a loop we write it as :

code snippet - A

Code: Select all

function printMembers($qResult)
{
while ($arow = mysql_num_rows($qResult))
{
  $temp = "<table><tr><td>". $arow["name"]."</td></tr>";
  $temp .= "<tr><td>".$arow["address"]."</td></tr>";
  $temp .= "<tr><td>".$arow["phone"]."</td></tr></table>";
  print $temp; //this will print one row at time

}
}


code snippet - B

Code: Select all

function printMemberName($qResult)
{
	$userNameStore = mysql_num_rows($qResult)	$userNameDisplay = $userNameStore["name"];
	return $userNameDisplay; //should return user's name
}
in the PHP code block if i call code snippet - B before snippet - A it doesnt return the user's "name" from the
"printMemberName()" and also it doesnt print all the rows from
"printMembers()".

Why is that? I have used the reset() functions to reset the array pointer of the $qResult to the base element but it doesnt work gives an error. How do i call the code snippet - B before code snippet - A to print the users details as, user's name displays seperate and it follows the complete details of the user in a form of a table!

i hope my question is clear :(

cheers


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Image
[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1 wrote:1. Select the correct board for your query. Take some time to read the guidelines in the sticky topic.
mysql_num_rows() returns the number of records found to match your query. You appear to want mysql_fetch_assoc().
Post Reply