I have an MySQL syntax where I return some data for a user. Is any better way of executing the following query, where I just want to know if there is data for user X in category y.
$search_sql = " SELECT id FROM sn_news WHERE id_category = $category AND id_client = $client ";
$search_query = mysql_query($search_sql);
$search_query_result = mysql_fetch_assoc($search_query);
if($search_query_result)
{
$search_result = TRUE;
}
else
{
$search_result = FALSE;
}
I just what to get a TRUE if there is data for my query, or a FALSE if not, to later use that result in a $.post() to know what to print out and what to remove.
Note: I haven’t tried the code, but I guess it works
mysql_fetch_assoc()returnsFALSEwhen there is no row to fetch. You can check the return value like this:Tell you what, this is essentially the same as what you are doing in your original code.