Code: Select all
$query1 = mysql_query("SELECT id FROM table WHERE var1 = '$value'");
$number = mysql_num_rows($query1);
$query2 = mysql_query("SELECT field1, field2 FROM table WHERE var1 = '$value' ORDER BY field1 DESC LIMIT 1");Moderator: General Moderators
Code: Select all
$query1 = mysql_query("SELECT id FROM table WHERE var1 = '$value'");
$number = mysql_num_rows($query1);
$query2 = mysql_query("SELECT field1, field2 FROM table WHERE var1 = '$value' ORDER BY field1 DESC LIMIT 1");Code: Select all
$query = mysql_query("SELECT id, field1, field2 FROM table WHERE var1 = '$value' ORDER BY field1 DESC LIMIT 1");
$number = mysql_num_rows($query);if I do a DESC LIMIT 1, the $number will only show up as 1 row, because that's what I'm limiting the query to.nyy2000 wrote:How about this?Code: Select all
$query = mysql_query("SELECT id, field1, field2 FROM table WHERE var1 = '$value' ORDER BY field1 DESC LIMIT 1"); $number = mysql_num_rows($query);
Code: Select all
$query=mysql_query("SELECT id, field1, field2 FROM table WHERE var1='$value'");Code: Select all
$query=<<<END_QUERY
SELECT id, field1, field2 FROM table WHERE var1='$value'
END_QUERY
$result=mysql_query($query);I can't agree more... I prefer:nielsene wrote: I personally find the growing convention by many people on this forum to stick the result of mysql_query into a variable called $query very confusing.
Code: Select all
$query = "SELECT|INSERT|UPDATE|DELETE| ...";
$rs = mysql_query($query); // $rs as in resultsetCode: Select all
$query = mysql_query("SELECT id FROM forumentries WHERE topicid = '".$array['id']."'");
$replies = mysql_num_rows($query2) - 1;
$lastpostarray = mysql_fetch_assoc(mysql_query("SELECT time, author FROM forumentries WHERE topicid = '".$array['id']."' ORDER BY time2 DESC LIMIT 1"));Code: Select all
$query = mysql_query("SELECT time, author FROM forumentries WHERE topicid = '".$array['id']."'")
$replies = mysql_num_rows($query) - 1;
$lastpost = mysql_fetch_assos("---- first row of array here ----");Code: Select all
$query = mysql_query("SELECT time, author FROM forumentries WHERE topicid = '".$array['id']."'")
$replies = mysql_num_rows($query) - 1;
$lastpost = mysql_fetch_assos("---- first row of array here ----");If you wanted to build an array with all your rows you should have used a while loop.Return Values
Returns an associative array that corresponds to the fetched row, or FALSE if there are no more rows.
Code: Select all
$lastpost = mysql_fetch_assos("---- first row of query result here ----");Code: Select all
$array = mysql_fetch_array($query);