-1

Plz Help i Dont know what is wrong in this function ....

$gsql = "SELECT * FROM posts WHERE group='$group_name' ORDER BY postdate DESC LIMIT 0,20";
$gquery = mysqli_query($db_conx, $gsql);
$gstatusnumrows = mysqli_num_rows($gquery);

while ($grow = mysqli_fetch_array($gquery, MYSQLI_ASSOC)) {

and it keeps saying this error :-

Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in D:\group.php on line 3

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in D:\group.php on line 5
Yassin
  • 1,049
  • 11
  • 15

1 Answers1

5

That means your query failed.

[mysqli_query] returns FALSE on failure. For successful SELECT, SHOW, DESCRIBE or EXPLAIN queries mysqli_query() will return a mysqli_result object. For other successful queries mysqli_query() will return TRUE.

So use mysqli_error to find out what you did wrong. In this case, though, it's because you have a column named "group". GROUP is a reserved word in MySQL. To be on the safe side, ALL database, table and column names SHOULD be enclosed in backticks ` to prevent any possible ambiguity.

Niet the Dark Absol
  • 320,036
  • 81
  • 464
  • 592
  • Another way to avoid ambiguity which does not require the use of backticks is to qualify all column references with a table name or (preferably) a table alias, e.g. `SELECT p.* FROM posts p WHERE p.group = ... ORDER BY p.postdate ... `. This has the additional benefit (when more than one table is referenced), of avoiding ambiguous column references. – spencer7593 Jun 11 '13 at 14:15
  • thanks alot for your help i changed my column name in my database and it worked thanks a lot :) – Yassin Jun 11 '13 at 14:16