关于如何在MySQL中使用LAST()的问题 [英] Problem on how to use LAST() in MySQL

查看:216
本文介绍了关于如何在MySQL中使用LAST()的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用last()函数选择我的数据库表中名为payment的最后一行,然后在where子句中使用该结果来选择不同表中的一些记录...



当我使用它时它真的很有用......



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...

<?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.




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.

推荐答案

pay = mysql_query(\"select * from payment where passengers_id='
pay = mysql_query("select * from payment where passengers_id='


passengers_id' and status = 'Paid' \");



if(!
passengers_id' and status = 'Paid' "); if(!


pay){echo mysql_error(); }else{

while(
pay){echo mysql_error(); }else{ while(


这篇关于关于如何在MySQL中使用LAST()的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆