开发者

Extracting results from a mySQL union query

I'm stuck on an mysql 开发者_运维知识库query. I usually just put the result set into an array and use var = $row['column']; . I am unable to do that this time. The query is as such.

$dbTaskRecords = mysql_query("Select Time, TruckId, TaskNo, PickupLocation, DropOffLocation
From booking 
Where driver='$driver' 
    And Date= CAST('$Date_search' AS DATE) 
Union All
Select Time, TruckId, TaskNo, PickupLocation, DropOffLocation
From returnbooking
WHERE driver='$driver' 
    And Date= CAST('$Date_search' AS DATE) 
Order By TaskNo Asc");

If I try to use: $row = mysql_fetch_array($dbTaskRecords);

I get an error.

How do I go about getting the outputs to variables?

Thanks guys.


mysql_fetch_array() expects parameter 1 to be resource, boolean given

this means that your query has an error

try to add this line before fetching the content

if (!$dbTaskRecords) {
    echo mysql_error();
    die;
}


UNION shouldn't change anything, it just allows you to get results from another source following the same SELECT scheme.. are you sure your error doesn't exist elsewhere?


If you want to extract the results in a tabular format here is the code.

<table>
<?php
 while($info = mysql_fetch_array( $data ))
 {
 ?>             
  <tr>
  <td><?=$info['Time'];?></td>
  <td><?=$info['TruckId'];?></td>
  <td><?=$info['TaskNo'];?></td>
  <td><?=$info['PickupLocation'];?></td>
  <td><?=$info['Dropf'];?></td>
 </tr>
 <?php  
 }
 ?>
 </table>

if you want to assign variable just give like this say variable = $info['TruckId']

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜