Jump to content

Recommended Posts

Hi,

 

I'm using the in_array function to check if a value exists in an array.

 

Abridged code is below.

 

Basically I'm retrieving an array of records from the data base and checking if the string "massage" is in it. That way I can check a checkbox.

 

I'm still unsure about arrays, so I'm not even sure if I've vreated it properly in order to use the in_array function.

 

$bid=$_SESSION['business_id'];
$query="SELECT * FROM specialties WHERE business_id=$bid";
$result=mysql_query($query);
while($check=mysql_fetch_array($result)){
$specialty=$check['specialty'];


if (in_array("massage", $specialty)) {
    echo "checked=\"checked\"";

}

 

I get the following error

 

in_array() [function.in-array]: Wrong datatype for second argument

 

Can anyone help? Or suggest another way to see if checkbox values exist in a database so that they can be checked.

 

Thanks

I'm not sure. I'm quite new at using arrays. I think the problem might lie with the array rather than the in_array function. But I've been reading tutorials and I can't seem to get my head around it.

 

Is there a better(correct) way to create an array from the records in the database?

 

I think it not in the array sorry.........

 

 

OFF topic....

 

This is for those dont understand in_array....................

 

 

 

<?php


$find="luke";


$a=array("john","luke","paul");


if(in_array("$find",$a)){


if(preg_match('/^[a-z]/',$find)){


echo "$find is in the array";

}else{

echo " didnt find $find in this array";

}

}else{

	echo " sorry $find is not a  ((a to z))  letter!";
}

?>

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.