English 中文(简体)
搜查的形式 利用PHP和SQL
原标题:Formatting a Search Result using PHP and mySQL

此时此刻,我把管理者一边拖到现场,允许现场管理人进入飞行编号,数据库将删除所有飞行人员的姓名。 然而,在我取得结果时,正视着这样的一点:

<编码> The following people are on this Airlines. 以下人员乘坐这架飞机:Joe Blaggs。 The following people are on thisjet Gareth Roberts 以下人员乘坐这架飞机:Joe Blaggs。 The following people are on thisjet Gareth Roberts 以下人员乘坐这架飞机:Joe Blaggs。 The following people are on thisjet Gareth Roberts 以下人员乘坐这架飞机:Joe Blaggs。 The following people are on thisjet Gareth Roberts The following people are on thisjet Joe Blaggs

你们有这样的想法:显然由于政治部的原因而构成姓名:

我怎么能这样说:

2021号航班上的乘客是:

  • Name one
  • Name two
  • Name three

在此,我欢迎任何建议!

    <? 
     include("logon/include/session.php");
                $loggedinuser = $session->username;
    $passengerNo = $_POST[ enteredPassNo ];
       $theflightno = $_POST[ enteredflightNo ];
            $query1 = mysql_query("SELECT p.surname, p.forename,   p.passNo FROM PASSENGER p WHERE p.passNo =  $passengerNo ");
while($row = mysql_fetch_array($query1))
{
    echo "Welcome to the site"  . " " . $row[ forename ] ." ";
        }
        echo mysql_error();
$query2 = mysql_query("SELECT    p.surname, p.forename, p.passNo, p.flightNo FROM PASSENGER p, FLIGHT_INFO f WHERE     p.flightNo =  $theflightno ");
while($row = mysql_fetch_array($query2))
{
    echo "以下人员正在这一飞行中。" . "</ br> ";
    echo $row[ forename ] ." " . $row[ surname ];
    echo "</ br>";
        echo mysql_error();
        }
    echo mysql_error();
       ?> 

It s query2 that is more the focus, query1 is being used for a few tests really! And just to clarify, the values stored in $passengerNo and $theflightNo are being correctly assigned after being posted from the form.

许多感谢,

送文函

www.un.org/spanish/ecosoc EDIT:关于格式的大型建议,但它仍在印刷之中:

以下人员正在这一飞行中。

  • Gareth Roberts
  • Joe Bloggs
  • Gareth Roberts
  • Joe Bloggs
  • Gareth Roberts
  • Joe Bloggs

而不是印刷,

以下人员正在这一飞行中。:-

  • Gareth Roberts
  • Joe Bloggs

仅一次:

最佳回答

将以下部分改为:

$query2 = mysql_query("SELECT CONCAT(p.surname, p.forename) as name, p.passNo, 
         p.flightNo FROM PASSENGER p WHERE p.flightNo =  $theflightno  
         GROUP BY name");
echo "Passengers on flight number {$theflightno} are:" . "<br /> <ul>";
while($row = mysql_fetch_array($query2)) {
  echo "<li>" . $row[ name ] . "</li>";
  echo "</ br>";
}
echo "</ul>";

EDIT

我所做的基本编辑是:

  • Added a CONCAT function, so that names will be returned as a single string(for repeated values of surnames/fornames).
  • Changing the query, to include a GROUP BY clause. So that repeated names(forname+surname) will appear only once.
问题回答
echo "The following people are on flight " . $row[ flightNo ] . "</ br> ";    
echo "<ul>";
while($row = mysql_fetch_array($query2))

{

echo "<li>" . $row[ forename ] ." " . $row[ surname ] . "</li>";

    }
 echo "</ul>";

您也正在起草案文。 So

echo "Passenger s on flight number 2021 are:";
echo  </ br> ;
echo  <ul> ;
while($row = mysql_fetch_array($query2))
{
  echo  <li> ;
  echo $row[ forename ] ." " . $row[ surname ];
  echo  </li> ;
}
echo  </ul> ;




相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签