|
Posted by Juliette on 09/19/06 02:26
rich wrote:
> Oh here is the getspecprim() function
>
> function getspecprim($dresstypeid) {
> $getQ="SELECT primsecid FROM li_dresstypepsp
> WHERE
> dresstypeid= '$dresstypeid'";
> $getR = pg_query($getQ);
> $getA= pg_fetch_all($getR);
> return($getA);
> }
>
> rich wrote:
>> I keep getting the error:
>> Warning: in_array(): Wrong datatype for second argument on line 679
>> here is the code.
>> I declare and fill the array
>> $specprimA = array();
>> $specprimA= getspecprim($dresstypeid);
>> $primsecA=getprimsec();
>>
>> Then I do a compare using in Array. I even put in the extra step of
>> making sure I have something in the array with the is sizeof statement.
>>
>> $numcl= count($primsecA);
>> for ($i=0; $i<$numcl; $i++){
>> $primsec = $primsecA[$i]['primsec'];
>> if (sizeof($specprimA) >0){
>> if (in_array($primsecA[$i]['primsecid'], $specprimA)) { ?>
>> <input type="checkbox" checked tabindex="2" name="primsecid[]"
>> value="<?php echo $primsecA[$i]['primsecid']; ?>"/><?php echo
>> $primsec;
>> } else { ?>
>> <input type="checkbox" tabindex="2" name="primsecid[]" value="<?php
>> echo $primsecA[$i]['primsecid']; ?>"/><?php echo $primsec;
>> }
>> } else { ?>
>> <input type="checkbox" tabindex="2" name="primsecid[]" value="<?php
>> echo $primsecA[$i]['primsecid']; ?>"/><?php echo $primsec;
>> }
>> }?>
>>
>> This is line 679
>> if (in_array($primsecA[$i]['primsecid'], $specprimA)) { ?>
>>
>> Any ideas why?
>
count / sizeof on a boolean or string will return 1, so try changing the
line above the problem line to:
if( is_array( $specprimA ) && count( $specprimA ) > 0 ) {
Alternatively, IMHO a better solution, would be to do the checking /
typecasting in the function.
replace:
return($getA);
with something along the lines of:
if( !is_array( $getA ) {
return array();
}
else {
return $getA;
}
Navigation:
[Reply to this message]
|