-1

When i use this this is how it loads : Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /public_html/php/application/views/admin/index.php on line 20 User Name ID

Please Help:

<?php 

$con = mysql_connect("hostname","user","password");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

  mysql_select_db("db", $con);

  $result = mysql_query("SELECT * FROM users ORDER user_id");

  echo "<table border='0'>
<tr>
<th>User Name</th>
<th>ID</th>
</tr>";

while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['user_name'] . "</td>";
  echo "<td>" . $row['user_id'] . "</td>";
  echo "</tr>";
  }
echo "</table>";

mysql_close($con);

?>

Thanks josh_24_2

ub3rst4r
  • 2,346
  • 24
  • 33
josh_24_2
  • 13
  • 2

1 Answers1

1

Boolean means your query didn't run. In this case, it seems that you have missed by in your query:

Change:

SELECT * FROM users ORDER user_id

to:

SELECT * FROM users ORDER by user_id

Edit: NEVER EVER post your ACTUAL login and password on a site asking for help. Anyone can now view the revision that I made (to at least hide it from the initial view) and get your info. I would suggest getting it changed now that it is out there for the world to see.

Secondly, you are also using mysql_* functions. These are old and dusty. If you are just starting out, please find a PDO tutorial to follow, it will be much safer (and better) in the long run.

Fluffeh
  • 32,630
  • 16
  • 65
  • 80