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

 

 

Link to comment
Share on other sites

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

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

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