0
<?php
$dbc=mysqli_connect('localhost','root','','sam_telephone');


$query="SELECT * FROM master_name";
$result=  mysqli_query($dbc,$query);

$display=mysqli_fetch_array($result);

echo $display['f_name']; /// its show me the result  which is fine 

// but when i apply while loop it does not show any thing.

while($y = mysqli_fetch_array($result)){
    echo $y['f_name'];
}
// $y['f_name'] should give me a result becuase it showing me the result on line
10 why its not working on this line i dont know 



?>
4
Contributors
6
Replies
22
Views
3 Years
Discussion Span
Last Post by arifkutty
1

Are you sure that there is more than one result being returned?

Edited by Assembly Guy

1

^^ By the second mysqli_fetch call the pointer is on the second record, so if only one record is returned, the second call will be empty. I think.

0

thanks Assembely Guys---- the things is that when i tried to get the result for echo $display['f_name']; (in line 10) it work fine it give the result, but it does not give me the result for $y['f_name']; in line 15

the things is that when i delete my line no. 10 which is $display['f_name']; than it give me result for $y['f_name'];

i think that wat difol is mentoning, but i did not understand fully what he is saying.

as i see it i echo the result once so it should show me the result, than i ran the while loop and want echo some thing so it should do that too,

diafol what do you meen by this

1

Yes @diafol is correct,you can only iterate the result once using mysqli_fetch_array(),however if for some reason you still want to call the query again,then before calling it another time set the pointer back to the beginning using mysqli_data_seek() method .

So just reset the result pointer to the beginning

<?php
   $dbc=mysqli_connect('localhost','root','','sam_telephone');
$query="SELECT * FROM master_name";
$result=  mysqli_query($dbc,$query);
$display=mysqli_fetch_array($result);
echo $display['f_name']; /// its show me the result  which is fine 
// but when i apply while loop it does not show any thing.
mysqli_data_seek($result, 0);
while($y = mysqli_fetch_array($result)){
    echo "here". $y['f_name'];
}
// $y['f_name'] should give me a result becuase it showing me the result on line
//10 why its not working on this line i dont know 
?>
0

thanks IIM yah its work fine, and thanks for explanation too,
diafol and no i dont have to fetch it twice, i was just checking that weather the query is working or not in the 10th line and than i got confused why i did not work second time, but its good i learn some thing by my mistakes

Thanks for help guys

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.