glennn.php Posted September 8, 2008 Share Posted September 8, 2008 i don't mind if someone could point me to the right tutorial, but i haven't had any luck finding one for this particular issue (either way, i could use a little help): i've got an array, $offering, which would return something like 03, 04, 08 foreach ($offering as $f) { $deg = $f; echo $deg; // gives me 030408 - fine... } while foreach ($offering as $f) { $deg = $f; } echo $deg; // gives me 08 - so i can only assume that $result = mysql_query("SELECT COUNT(*) FROM administrators WHERE fice IN (SELECT fice FROM characteristics WHERE carnegie_code = '$carn_class' AND offering = '$deg') ") or die(mysql_error()); is only going to return those with fields 'offering' containing 08... can someone please show me how to search for ALL the values for that field...? i really appreciate it... GN Link to comment https://forums.phpfreaks.com/topic/123295-solved-little-help-using-an-array-in-a-query/ Share on other sites More sharing options...
GingerRobot Posted September 8, 2008 Share Posted September 8, 2008 If you're asking what I think you are, see this post: http://www.phpfreaks.com/forums/index.php/topic,215379.msg984429.html#msg984429 The query in that post would return rows where the name is either tom,dick or harry. Link to comment https://forums.phpfreaks.com/topic/123295-solved-little-help-using-an-array-in-a-query/#findComment-636753 Share on other sites More sharing options...
glennn.php Posted September 8, 2008 Author Share Posted September 8, 2008 well, i think it's close - if this returns 030408 and not 03,04,08 $offering = $_GET['highest_deg']; foreach ($offering as $f) { $deg = $f; echo $deg; // gives me 030408 - fine... } that didn't quite work - what am i missing? $result = mysql_query("SELECT COUNT(*) FROM administrators WHERE fice IN (SELECT fice FROM characteristics WHERE offering IN '".join("','",$f)."'") or die(mysql_error()); i don't know how to see the difference in this array $array = array('tom','dick','harry'); and this one $offering = $_GET['highest_deg']; thanks Link to comment https://forums.phpfreaks.com/topic/123295-solved-little-help-using-an-array-in-a-query/#findComment-636779 Share on other sites More sharing options...
glennn.php Posted September 8, 2008 Author Share Posted September 8, 2008 is this where explode() comes into play... ? Link to comment https://forums.phpfreaks.com/topic/123295-solved-little-help-using-an-array-in-a-query/#findComment-636780 Share on other sites More sharing options...
GingerRobot Posted September 8, 2008 Share Posted September 8, 2008 You were missing a closing parenthesis in your query. Try: $result = mysql_query("SELECT COUNT(*) FROM administrators WHERE fice IN (SELECT fice FROM characteristics WHERE offering IN '".join("','",$f)."')") or die(mysql_error()); As for the array, I assume $_GET['highest_deg'] is the array of values you need to be matching against? Link to comment https://forums.phpfreaks.com/topic/123295-solved-little-help-using-an-array-in-a-query/#findComment-636804 Share on other sites More sharing options...
glennn.php Posted September 8, 2008 Author Share Posted September 8, 2008 yes, that's the array i was matching against... this did it for me, thanks very much, GingerRobot. Topic Solved... $offering = $_POST['highest_deg']; $offering_sql = implode(',',$offering); $result = mysql_query("SELECT COUNT(*) FROM administrators WHERE fice IN (SELECT fice FROM characteristics WHERE offering IN ($offering_sql)) ") or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/123295-solved-little-help-using-an-array-in-a-query/#findComment-636808 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.