poleposters Posted September 30, 2008 Share Posted September 30, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/126388-in_array-problem-wrong-data-type-for-second-argument/ Share on other sites More sharing options...
vbnullchar Posted September 30, 2008 Share Posted September 30, 2008 are you sure $specialty is an array? Quote Link to comment https://forums.phpfreaks.com/topic/126388-in_array-problem-wrong-data-type-for-second-argument/#findComment-653589 Share on other sites More sharing options...
poleposters Posted September 30, 2008 Author Share Posted September 30, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/126388-in_array-problem-wrong-data-type-for-second-argument/#findComment-653594 Share on other sites More sharing options...
redarrow Posted September 30, 2008 Share Posted September 30, 2008 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!"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/126388-in_array-problem-wrong-data-type-for-second-argument/#findComment-653614 Share on other sites More sharing options...
sKunKbad Posted September 30, 2008 Share Posted September 30, 2008 line 5 try $specialty[]=$check['specialty']; Quote Link to comment https://forums.phpfreaks.com/topic/126388-in_array-problem-wrong-data-type-for-second-argument/#findComment-653622 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.