skip to Main Content

I have just used a select with a select for the first time. It seems to work and I am getting the desired result when I run it in phpMyAdmin. However, when I then use $variable = mysql_num_rows($queryresult); I get nothing. I guess it is null or something as it won’t echo. This is the query:

$resultxl = mysql_query(select * from (Select * from mon_content_lid where mon_date_last!='0000-00-00' ORDER BY lid, mon_date_last desc) as x group by `lid`);
$numx1 = mysql_num_rows($resultxl);
echo $numx1;

No result.

2

Answers


  1. If I see it right (didn’t tried it out), you do a SELECT an put the result in a virtual column x, so in my opinion, x should be the only delivered column. This one you group by ‘lid’.

    select * from (...) as x group by `lid`
    

    So ‘lid’ is, if it is quoted, a text, not a column-name. Try the query qithout the “group” and dump the cursor, maybe you see some results.

    Login or Signup to reply.
  2. Don’t use mysql, use the mysqli functions.
    If i’m right you can’t use the mysql functions in php7 anymore

    $db = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
    $sql = "Here your sql query";
    $query_result = mysqli_query($db, $sql);
    $number = mysqli_num_rows($query_result);
    echo $number;
    

    I didn’t test is, but i think this should work.
    If it still don’t work try to see if there are any errors.

    die(mysqli_error($db));
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search