siamsam Posted August 31, 2010 Share Posted August 31, 2010 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! What am I doing wrong? Link to comment https://forums.phpfreaks.com/topic/212210-implode-help/ Share on other sites More sharing options...
AbraCadaver Posted August 31, 2010 Share Posted August 31, 2010 This is fetching the first row: $row_getCAT = mysql_fetch_assoc($getCAT); So it is gone from the result and isn't available in your while loop. It doesn't appear that you need that, comment it out. Link to comment https://forums.phpfreaks.com/topic/212210-implode-help/#findComment-1105791 Share on other sites More sharing options...
siamsam Posted August 31, 2010 Author Share Posted August 31, 2010 Thanks so much, that worked! I really appreciate the help. Link to comment https://forums.phpfreaks.com/topic/212210-implode-help/#findComment-1105807 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.