简体   繁体   中英

ODBC, PHP while loop to assign data to array

I want to loop though my query and assign each data field to an array.

 $query ="SELECT * FROM Reservations WHERE Room_ID = '145' ";

    $result = odbc_exec($connect,$query);
     while(odbc_fetch_row($result)){
      $reservation = odbc_result($result, 1);
      $reservation2 = odbc_result($result, 2);
      $reservation3 = odbc_result($result, 3);
      $reservation4 = odbc_result($result, 4);

     }

What I am trying to do is

$content = array(); 
while($info = mysql_fetch_array($result))
{
$content[] = $info;
}

I guess I could check to see the total number of rows and then just do a for loop that increments the $result.

I think you're looking for odbc_fetch_array .

while ($info = odbc_fetch_array($result)) {
    $content[] = $info;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM