Page 1 of 1

query results into fixed array?

Posted: Thu Nov 23, 2006 11:56 am
by biggieuk
Hi all,

I am using the following code to set the results of a query into an array.

Code: Select all

<?php
function QueryIntoArray($query){
        settype($retval,"array");
		
$result= mysql_query($query);
        if(!$result){
print "Query Failed";
        }        
        for($i=0;$i<mysql_numrows($result);$i++){
                for($j=0;$j<mysql_num_fields($result);$j++){
                        $retval[$i][mysql_field_name($result,$j)] = mysql_result
($result,$i,mysql_field_name($result,$j));
                }//end inner loop
        }//end outer loop
return $retval;
}//end function


mysql_connect ($host,$user,$pass) or die ( mysql_error ());
mysql_select_db ($db)or die ( mysql_error ());
settype($myresult,"array");

$query = 'SELECT sessionid FROM session WHERE placesbooked = capacity';
$myresult = QueryIntoArray($query);
for($i=0;$i<count($myresult);$i++){
print $myresult[$i]["sessionid"];
}
?>
I then have this code in each radio button so that 'if placesbooked = capacity' the radio button is disabled and so becomes unusable;

Code: Select all

<input name="session1" type="radio" value="T1" <? if (in_array("T1", $myresult[0])) echo "disabled"; ?> >
(The value 'T1' is changed for each radio button T2,T3,T4 etc..)


The problem is that this only adds a value to the array if 'placesbooked = capacity' and therefore i am receiving an error on the radio buttons that are not fully booked.

How can i create a predefined array with 47 spaces so that if 'placesbooked = capacity' the corresponding sessionid is added to the array.

Or can the php code in the radio button be changed to stop the error:

Warning: in_array(): Wrong datatype for second argument in /u2/WWW/htdocs/booking.php on line 410
>


Thanks fore help with this as i am a bit stuck :(