-3

I want to fetch all rows in mysql but it returns only 1. I have tried this out:

while($info=mysql_fetch_all($query2, mysql_assoc))
{

but it is not working. Please help me out.

Priyansh Goel
  • 2,660
  • 1
  • 13
  • 37
  • 1
    You need to post your actual code, not just a one-line excerpt. Questions seeking debugging help ("**why isn't this code working?**") must include the desired behavior, a *specific problem or error* and *the shortest code necessary* to reproduce it **in the question itself**. Questions without **a clear problem statement** are not useful to other readers. See: [How to create a Minimal, Complete, and Verifiable example.](http://stackoverflow.com/help/mcve) – elixenide Jun 12 '16 at 16:19
  • $query2=mysql_query("SELECT * FROM websitee WHERE poster='$_SESSION[user_name]' ORDER BY id DESC LIMIT $offset, $rowsperpage"); $num=mysql_num_rows($query2); if($num==0) { echo"
    No topics yet
    "; } else { echo"

    HOTTEST UPDATES


    "; while($info=mysql_fetch_all($query2, mysql_assoc)) { $id=$info["id"]; $ftp=$info["ftp"]; $server=$info["server"]; $password=$info["password"]; }
    – Coded Firstimage Jun 12 '16 at 16:26
  • 1
    No, please don't post it in a comment. [Edit] your question and add some proper formatting. Also, `mysql_fetch_all` implies that it fetches all rows. In that case, looping over it makes no sense, which is your main problem right there. And please [don't use `mysql_*`](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php?rq=1), anyway. The `mysql_*` functions are outdated, [deprecated](http://us3.php.net/manual/en/intro.mysql.php), and insecure. Use [`MySQLi`](http://us3.php.net/manual/en/book.mysqli.php) or [`PDO`](http://us3.php.net/manual/en/intro.pdo.php). – elixenide Jun 12 '16 at 16:28
  • `mysql_fetch_all` is not standard function (`mysqli_fetch_all` is) but I'd assume it returns all the data in some iterable form and shouldn't be used with `while` like in your code – malarzm Jun 12 '16 at 16:32
  • Am badly in need of solution complete line are not allow to be posted please help me edit it in post from my resent comment thanks – Coded Firstimage Jun 12 '16 at 16:32
  • Please note: **The functions named `mysql_xxx()` are obsolete and have been removed from the latest PHP versions.** If you continue using them, your code will not work when you need to upgrade your PHP. You **urgently** need to rewrite your code to use the PDO or mysqli libraries instead. See http://www.phptherightway.com/#databases for good instructions on these methods. – Spudley Jun 12 '16 at 17:28

1 Answers1

0

Quick fix is to replace mysql_fetch_all to mysql_fetch_assoc:

$query2=mysql_query("SELECT * FROM websitee 
  WHERE poster='$_SESSION[user_name]' 
  ORDER BY id DESC LIMIT $offset, $rowsperpage"); 
$num=mysql_num_rows($query2); 
if($num==0) { 
  echo"<div class='msg'>No topics yet</div>"; 
} else { 
  echo"<br/><br/><div align='center' class='b_head'><strong>HOTTEST UPDATES</strong></div><div class='center'><span class='style18'></span></div><br><br> ";
  while($info=mysql_fetch_assoc ($query2)) { 
    $id=$info["id"]; $ftp=$info["ftp"]; $server=$info["server"];
    $password=$info["password"]; 
    print_r($info);
  }
} 

But you should stop using mysql_* functions and use mysqli or pdo.

Alex
  • 16,739
  • 1
  • 28
  • 51