Jump to content

implode help


siamsam

Recommended Posts

I am having trouble with passing the results of this first query into the next. I first query the db to get the sub id's that belong to the cat id coming through the url. This query gives me the correct results.

 

//query for subcat id

$var1_getCAT = "-1";
if (isset($_GET['cat'])) {
  $var1_getCAT = (get_magic_quotes_gpc()) ? $_GET['cat'] : addslashes($_GET['cat']);
}
mysql_select_db($database_conntest, $conntest);
$query_getCAT = sprintf("SELECT subs.subcat_id, subs.subcategory FROM subs WHERE subs.cat_id = %s ORDER BY subcat_id", GetSQLValueString($var1_getCAT, "int"));
$getCAT = mysql_query($query_getCAT, $conntest) or die(mysql_error());
$row_getCAT = mysql_fetch_assoc($getCAT);
$totalRows_getCAT = mysql_num_rows($getCAT);

 

Then, I use the array $subCATS in the next query to search the results that are in that array:

 

//set var for subs
$subCATS = array();
while ($row = mysql_fetch_assoc($getCAT)) {
$subCATS[] = $row['subcat_id'];
}
$subCATS = implode( ', ', $subCATS);


$query_rsSearch = "SELECT advs.adv_id, cinfo.c_id, FROM cinfo LEFT JOIN advs USING (adv_id) WHERE (cinfo.subcat_id IN ($subCATS) OR cinfo.subcat_id2 IN ($subCATS)) ORDER BY RAND()";

 

If I put exit in front of the second query, I see that the array is dropping the first result. For example, if the first query returns (2, 3, 4, 6, 9, 52), the value of the $subCATS array in the second query is only searching in (3, 4, 6, 9, 52).

 

I hope this makes sense. I am not sure why it would only drop the first result. I figured it would either work or not work, not just partially work - it has thrown my brain into a do while loop that is making me dizzy!  :confused: What am I doing wrong?

 

Link to comment
https://forums.phpfreaks.com/topic/212210-implode-help/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.