Jump to content

Recommended Posts

why do i get a single value of array when doing print_r 

the page contain more than 10,000 record

i dont understand as you can see everything is fine can you tell me the possible solution or error

 

$qry = "SELECT * FROM categories ";
$result=mysql_query($qry);
$total = mysql_fetch_array($result);
print_r($total);

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/64964-solved-help-crazy-output/
Share on other sites

use an associative array. I don't understand why you want want to return your results they way you are doing it. I tend to always use a while loop

 


while($row = mysql_fetch_assoc($result)) {
  echo $row['field in db you want'];

  or do something else with it
}

even if i do that i get single result. like what ive said i have morethan 10, 000 record but when i do the fetch thing it returns only one record???? we have a test server which i test this using php myadmin and everything works fine .

 

can you tell me the possible error im doing

just humor me and run this version

<?php
$q = "SELECT * FROM categories";
$result = mysql_query($q) or die(mysql_error());
$total = mysql_fetch_assoc($result);
$rows = mysql_num_rows($result);
echo "Number of Rows: ".$rows."<br/><br/><br/>";
print_r($total);
?>

and then view its source

 

$qry = "SELECT * FROM categories ";
$result=mysql_query($qry);
$total = mysql_fetch_array($result);
print_r($total);

 

You do the query, you get the first record, you print_r its contents.

 

Why would you expect more than one record with that code?

barand i think when you print_r your fetch thing it will return the whole content i see my error

 

and the error is that i have the same variable name so when the loop run it gets overwriten

its really hard to find the error because this is big site and it have thousands of lines

 

any way thanks

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.