Page 1 of 1

Array question.. easy

Posted: Wed Feb 09, 2005 10:04 pm
by s.dot
I'm getting a "in_array(): bad argument for second parameter" error for this:

Code: Select all

$date = date("Ymd");
$alreadyvotedsql = "SELECT whovoted FROM faceoffvotes WHERE faceoffid = '$faceoffid' AND date = '$date'";
$alreadyvotedquery = mysql_query($alreadyvotedsql);
$alreadyvotedarray = mysql_fetch_array($alreadyvotedquery);
if(in_array($_COOKIEї'username'], $alreadyvotedarray)){ echo "You have already voted on this faceoff matchup today.  You can vote again tommorow"; require 'footer.php'; die(); }
}
The array when printed to the browser is "Array."
How can I fix this to be a list of names from the query?

Posted: Wed Feb 09, 2005 10:07 pm
by thegreatone2176
you need a variable after you fetch the array

$alreadyvotedusername=$alreadyvotedarray["username"];

which will pick the username out of that row

Posted: Wed Feb 09, 2005 10:14 pm
by djot
-
Should be

Code: Select all

$alreadyvotedarrayї'whovoted']
then

Code: Select all

if(in_array($_COOKIEї'username'], $alreadyvotedarrayї'whovoted']))
{
  echo "You have already voted on this faceoff matchup today.  You can vote again tommorow";
  require 'footer.php';
  die();
}
djot
-

er

Posted: Wed Feb 09, 2005 10:44 pm
by s.dot
err still having troubles

do I need to implode() my variable to get it comma separated or something?

Posted: Wed Feb 09, 2005 10:49 pm
by feyd
how's the data stored in this table? What do you expect $alreadyvotedarray to be?

...

Posted: Wed Feb 09, 2005 11:01 pm
by s.dot
I expect it to be a list of names

such as user1, user2, user3, user4, user5, user6 etc...

Posted: Wed Feb 09, 2005 11:10 pm
by feyd
it will not be as such. You retrieve 1 row from the table for every record that matches when you call mysql_fetch_* .. since it looks like you are searching for a particular user, why not restrict the query to that user?

ah

Posted: Wed Feb 09, 2005 11:12 pm
by s.dot
ah, indeed

I don't know why I didn't do that. Brain fart moment I guess.

Thanks.