Jump to content

[SOLVED] little help using an array in a query


glennn.php

Recommended Posts

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

 

 

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.

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

 

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?

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());

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.