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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.