Can you see a problem with this query??? Please take a peek.
Posted: Wed May 29, 2002 10:48 pm
Okay...I'm baffled. If I have a query:
I have 4 rows returned. If I then use the query:
I have 0 rows returned. Why is this happening? All that's been added are the two conditional variables ($app_id and $cat_id), which don't exist in this case, and so should be passed-over by the script (so I think). Notice that the query still returns correct values with the other conditional variable ($man_date) missing. Ugh! What am I doing wrong? 
Code: Select all
<?
include("kb_includes.php");
$title = "Test";
head($title,$title);
chec36_db_connect() or die("Cannot connect");
$query = "SELECT DISTINCT kb_record.question, kb_record.resolution, kb_record.kb_record_id, kb_record.recordno, complete_record.kb_record_id
FROM kb_record, complete_record
WHERE kb_record.kb_record_id = complete_record.kb_record_id
AND kb_record.comp_manual='T'";
//search for manual records with a specific date
if(IsSet($man_date))
$query .= " AND kb_record.dateadd_manual='$man_date'";
//group by and order by
$query .= " ORDER BY kb_record.recordno";
$result = mysql_query($query);
echo mysql_num_rows($result);
?>Code: Select all
<?
include("kb_includes.php");
$title = "Test";
head($title,$title);
chec36_db_connect() or die("Cannot connect");
$query = "SELECT DISTINCT kb_record.question, kb_record.resolution, kb_record.kb_record_id, kb_record.recordno, complete_record.kb_record_id
FROM kb_record, complete_record
WHERE kb_record.kb_record_id = complete_record.kb_record_id
AND kb_record.comp_manual='T'";
//search for a specific application, if applicable
if($app_id <> 'all_apps')
$query .= " AND complete_record.app_id='$app_id'";
//search for a specific category, if applicable
if($cat_id <> 'all_cats')
$query .= " AND complete_record.cat_id='$cat_id'";
//search for manual records with a specific date
if(IsSet($man_date))
$query .= " AND kb_record.dateadd_manual='$man_date'";
//group by and order by
$query .= " ORDER BY kb_record.recordno";
$result = mysql_query($query);
echo mysql_num_rows($result);
?>