Is there a simpler/more compact way to code this?
The query is the same on the 2 tables:
I use MySQL 3.23.58, so UNION is not possible. I found this alternative, but it doesn't look much better to me:
Any suggesions?
Thanks
FnL
The query is the same on the 2 tables:
Code:
$sql = "SELECT id FROM users_intake WHERE users_id=5 AND timeStamp LIKE '2005%'";
$result = mysql_query($sql);
$inside1 = mysql_fetch_object($result);
$sql = "SELECT id FROM users_state WHERE users_id=5 AND timeStamp LIKE '2005%'";
$result = mysql_query($sql);
$inside2 = mysql_fetch_object($result);
if (!$inside1 and !$inside2) {
echo "no";
} else {
echo "yes";
}
Code:
$sql = "CREATE TEMPORARY TABLE temp_union TYPE=HEAP SELECT id FROM users_intake WHERE users_id=5 AND timeStamp LIKE '2005%'";
mysql_query($sql) or die (mysql_error());
$sql = "INSERT INTO temp_union SELECT id FROM users_state WHERE users_id=5 AND timeStamp LIKE '2005%'";
mysql_query($sql) or die (mysql_error());
$sql = "SELECT id FROM temp_union";
$result = mysql_query($sql) or die (mysql_error());
$sql = "DROP TABLE temp_union";
mysql_query($sql) or die (mysql_error());
$inside = mysql_fetch_object($result);
if (!$inside) {
echo "no";
} else {
echo "yes";
}
Thanks
FnL