I figured I was 'ok' with php, but i am not sure now... I can't fix this error... I get errors "Warning: mysql_num_rows(): supplied argument is not a valid MySQL result .." $num = mysql_num_rows(mysql_query('select * from all_items where pid=' . $rs0['id'])); same error here: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result $rs_t0 = mysql_fetch_array( mysql_query( 'select * from all_images where pid=' . $rs0['id'] . ' group by pid' ) ); thanks for looking!
First off, get rid of mysql_ - it's been deprecated for ages, and is NOT recommended for use. Use mysqli_ or PDO instead. First of, are you sure there's actually a value in the $rs0['id'] variable? Second, never use unescaped values directly in a query (I'm assuming this comes from somewhere semi safe, but still, don't). Try this: $id = $rs0['id']; $num = mysql_num_rows(mysql_query("SELECT * FROM all_items WHERE pid = '$id'")); PHP:
@PoPSiCLe has it quite right that you shouldn't be using mysql_ functions -- we've been told for NINE YEARS to stop doing that, which is why there are now giant red warning boxes in the manual to that end! _num_rows is unreliable on SELECT, and if all you want is a count, you should be using COUNT! Retrieving all records and then throwing them away is a COLOSSAL waste of processing time and internal bandwidth/memory. It just makes massive amounts of overhead you aren't even using! A PDO version of that would look something like this: (assumes $db is a connected PDO object) $statement = $db->prepare(' SELECT COUNT(*) FROM all_items WHERE pid = :pid '); $statement->execute([':pid' => $rs0['id']]); $num = $statement->fetchColumn(); Code (markup): Your second one would be something like: $statement = $db->prepare(' SELECT * FROM all_images WHERE pid = :pid GROUP BY pid '); $statement->execute([':pid' => $rs0['id']]); Code (markup): Though I would suspect given your errors that $rs0['id'] might not exist or resolve properly as @PoPSiCLe suggested. Some other advice, linefeeds and tabs are your friend; and see how I made the SQL functions uppercase and field/variable references lowercase? That's just good practice for code clarity. Cramming everything on one hard to read line is how you make mistakes. Really though, your first step should be to drag it kicking and screaming into THIS century.