多條件式查詢語法整合

WBOY
發布: 2016-06-06 20:24:08
原創
1527 人瀏覽過

小弟最近做專題碰上瓶頸,想把兩個範本的IF 整合,卻找不到方法

1.---------------------------------------------------------------------------------------------

<code>header("Content-Type: text/html; charset=utf-8");
include("connsql.php");  //含入連結資料庫檔案
$seldb = @mysql_select_db("orderdrink");  //連結資料庫
if (!$seldb) die("資料庫選擇失敗!");

$sql_query = "SELECT `orderid`,`phone`,`name` FROM `orders` WHERE `finish`=0 ORDER BY `orderid` DESC";
$result = mysql_query($sql_query);
$numrow = mysql_num_rows($result);
$row_result = array();
$i = 0;
while($row_result[$i] = mysql_fetch_array($result, MYSQL_ASSOC)){
    $i++;
}</code>
登入後複製
登入後複製

?>

2.--------------------------------------------------------------------------------------------

<code>header("Content-Type: text/html; charset=utf-8");
include("connsql.php");  //含入連結資料庫檔案
$seldb = @mysql_select_db("orderdrink");  //連結資料庫
if (!$seldb) die("資料庫選擇失敗!");

if (isset($_GET["update"])) {
    $order = $_GET["update"];
    $sql_query = "UPDATE `orders` SET `finish`=1 WHERE `orderid`='" . $order . "'";
    $result = mysql_query($sql_query);
    header("Location: index.php");
}

$row_detail = array();
$order = $_GET["order"];
$sql_query = "SELECT * FROM `orders` WHERE `orderid`='" . $order . "'";
$result = mysql_query($sql_query);
$numorder = 0;
$numorder = mysql_num_rows($result);
if($numorder>0) {
    $row_order = mysql_fetch_array($result, MYSQL_ASSOC);
    $sql_query = "SELECT * FROM `productdetail` WHERE `orderid`='" . $order . "'";
    $result = mysql_query($sql_query);
    $numdetail = mysql_num_rows($result);
    $i = 0;
    while($row_detail[$i] = mysql_fetch_array($result, MYSQL_ASSOC)) {
        $i++;
    }
}</code>
登入後複製
登入後複製

?>

想請問網友該怎麼做?

回复内容:

小弟最近做專題碰上瓶頸,想把兩個範本的IF 整合,卻找不到方法

1.---------------------------------------------------------------------------------------------

<code>header("Content-Type: text/html; charset=utf-8");
include("connsql.php");  //含入連結資料庫檔案
$seldb = @mysql_select_db("orderdrink");  //連結資料庫
if (!$seldb) die("資料庫選擇失敗!");

$sql_query = "SELECT `orderid`,`phone`,`name` FROM `orders` WHERE `finish`=0 ORDER BY `orderid` DESC";
$result = mysql_query($sql_query);
$numrow = mysql_num_rows($result);
$row_result = array();
$i = 0;
while($row_result[$i] = mysql_fetch_array($result, MYSQL_ASSOC)){
    $i++;
}</code>
登入後複製
登入後複製

?>

2.--------------------------------------------------------------------------------------------

<code>header("Content-Type: text/html; charset=utf-8");
include("connsql.php");  //含入連結資料庫檔案
$seldb = @mysql_select_db("orderdrink");  //連結資料庫
if (!$seldb) die("資料庫選擇失敗!");

if (isset($_GET["update"])) {
    $order = $_GET["update"];
    $sql_query = "UPDATE `orders` SET `finish`=1 WHERE `orderid`='" . $order . "'";
    $result = mysql_query($sql_query);
    header("Location: index.php");
}

$row_detail = array();
$order = $_GET["order"];
$sql_query = "SELECT * FROM `orders` WHERE `orderid`='" . $order . "'";
$result = mysql_query($sql_query);
$numorder = 0;
$numorder = mysql_num_rows($result);
if($numorder>0) {
    $row_order = mysql_fetch_array($result, MYSQL_ASSOC);
    $sql_query = "SELECT * FROM `productdetail` WHERE `orderid`='" . $order . "'";
    $result = mysql_query($sql_query);
    $numdetail = mysql_num_rows($result);
    $i = 0;
    while($row_detail[$i] = mysql_fetch_array($result, MYSQL_ASSOC)) {
        $i++;
    }
}</code>
登入後複製
登入後複製

?>

想請問網友該怎麼做?

链式写法,因为面向对象特性,可以返回this
http://segmentfault.com/a/1190000003069921?utm_source=APP&utm_medium=iOS&utm_campaign=socialShare

相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板