Code: Select all
$result = mysql_query("SELECT * FROM table1 WHERE active = 1")Code: Select all
mysql_num_rows($result);Is there a better way?
Thanks for reading.
Moderator: General Moderators
Code: Select all
$result = mysql_query("SELECT * FROM table1 WHERE active = 1")Code: Select all
mysql_num_rows($result);Code: Select all
SELECT COUNT(*) AS total FROM TABLE
Code: Select all
//First query, count the number of rows in one table
$result = mysql_query("SELECT COUNT(*) FROM `posts` WHERE `email` = '$email'") or die(mysql_error());
if (mysql_result($result, 0, 0) == 1)
{
$key = makeKey();
//Third query, update another table
mysql_query("UPDATE `users` SET `Key` = '$key' WHERE `Email` = '$email'") or die(mysql_error());
}
else
{
//The third query, return a result set instead of updating the table row
$result = mysql_query("SELECT Key FROM users WHERE Email = '$email'") or die(mysql_error());
}
Code: Select all
/*Something Like*/
IF (COUNT(*) FROM posts WHERE email = '$email') = 1 (UPDATE users SET Key = '$key' WHERE Email = '$email') ELSE (SELECT Key FROM users WHERE Email = '$email');
I think when you use the word "cram" on non-nested SQL, its best to use multiple SQL statements