Click here to Skip to main content
16,022,542 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i wanted to use last() function to select the last row in the my database table called "payment" and then use that result in where clause to select some records in different table...

it really words when i use this...

XML
<?php

                    $pay = mysql_query("select * from payment  where passengers_id='$passengers_id' and status = 'Paid' ");

                    if(!$pay){echo mysql_error(); }else{
                            while($p = mysql_fetch_array($pay)){

                                $booking_id=$p['booking_id'];

                                $book = mysql_query("SELECT * FROM booking where booking_id = '$booking_id'");
                                    if(!$book){echo mysql_error(); }else{
                                        while($b = mysql_fetch_array($book)){
                                            $booking_id = $b['booking_id'];
                                            $flight_id = $b['flight_id'];
                                            $flight_type = $b['flight_type'];
                                            $flight_price = $b['flight_price'];
                                            $booking_date = $b['booking_date'];
                                            $cabin = $b['cabin'];

                                            if($flight_type == "Domestic"){
                                                $flight = mysql_query("SELECT * FROM domes_flight where flight_id = '$flight_id'");
                                                if(!$flight){echo mysql_error(); }else{
                                                    while($f = mysql_fetch_array($flight)){
                                                        $flight_name=$f['flight_name'];
                                                        $flight_from = $f['flight_from'];
                                                        $flight_to=$f['flight_to'];
                                                        $flight_time=$f['flight_time'];

                                                    }

                                                }
                                            }
                                            if($flight_type == "International"){
                                                $flight = mysql_query("SELECT * FROM inter_flight where flight_id = '$flight_id'");
                                                if(!$flight){echo mysql_error(); }else{
                                                    while($f = mysql_fetch_array($flight)){
                                                        $flight_name=$f['flight_name'];


                                                    }

                                                }
                                            }
                        echo '


                            <tr style="margin-top:10px;border:1px solid; border-color:#1D77E9;">
                                <td style="padding:10px;"> '.$flight_name.' </td>
                                <td style="padding:10px;"> '.$flight_price.'    </td>
                                <td style="padding:10px;"> '.$flight_type.' </td>
                                <td style="padding:10px;"> '.$cabin.'   </td>
                                <td style="padding:10px;"> '.$flight_from.' </td>
                                <td style="padding:10px;"> '.$flight_to.'   </td>
                                <td style="padding:10px;"> '.$flight_time.' </td>
                                <td style="padding:10px;"> <img src="images/cancel.png"></a>    </td>
                            </tr>
                            <tr><td></td></tr>

                            ';
                                        }
                                    }


                            }

                    }







                ?>



but if i change it to SELECT LAST(booking_id) as booking_id FROM payment, it gives me this error

"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(booking_id) as booking_id from payment where passengers_id='20' and status = '' at line 1 "


if there is any why to up with this please help...Thanks.
Posted

SQL Last() function is only valid for MS Access. Check this out: SQL LAST() Function[^] to find out the workaround for MySQL.
 
Share this answer
 
i got it...

while using LAST() there shouldn't be WHERE Clause

thanks.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900