Hello to All
I m new to PHP and Mysql, I have a problem plz help me.
my question is how to display rows from result resource in second loop, my script is like:
$_parent_id=$_GET['parent_id'];
if(!isset($_parent_id) OR $_parent_id==0){
$_parent_id=0;
}
$sql="SELECT * FROM menu WHERE parent_id=".$_parent_id;
$result=mysql_query($sql);
// this loop returns all rows
while($RS=mysql_fetch_array($result)){
echo "<a href=menu.php?parent_id=".$RS['id'].">".$RS['name']."</a> :: ";
}
// this loop does not return anything (same result resource as above)
while($ROW=mysql_fetch_array($result)){
echo "<a href=menu.php?parent_id=".$ROW1['id'].">".$ROW1['name']."</a> <br> ";
}
Please help me
Moderator: General Moderators
Re: Please help me
Instead of echoing use two separate string variables to store HTML in and after the loop echo them.
PS: Use intval() to sanitize the $_GET['parent_id'] value!
PS: Use intval() to sanitize the $_GET['parent_id'] value!
There are 10 types of people in this world, those who understand binary and those who don't
Re: Please help me
Thanks VladSun
But my question is why the same result resource does not return any row in the second loop,
or I have to query again to create new result resource?
But my question is why the same result resource does not return any row in the second loop,
or I have to query again to create new result resource?
Re: Please help me
From http://php.net/mysql_fetch_array
You may reset it by using:
So, at the end of the loop the internal data pointer is at the end of the result data.Description
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.
You may reset it by using:
Code: Select all
mysql_data_seek( $result );There are 10 types of people in this world, those who understand binary and those who don't
Re: Please help me
Thanks VladSun
greate job!!!!!!!!!!!
it works
greate job!!!!!!!!!!!
it works