iT邦幫忙

0

如何超連結PHP訂單變數SQL查資料

  • 分享至 

  • xImage

我三個PHP檔 一個是未處理index.php檔 一個是歷史訂單搜尋後的訂單資料顯示的test.php檔 另一個是根據傳超連結變數顯示該哪一筆資料的showorder.php檔

想問index.php未處理訂單檔的顯示字串可以超連結變數編號連接showorder.php 並根據編號SQL顯示該筆資料

這個test.php要怎麼修改成可以根據訂單編號變數連結到showorder.php

資料庫goodsapp
資料表orders幾個欄位
orderid 訂單編號
name 姓名
ordertime 購買時間
totalmoney 總額
chargetime 處理時間

index.php

<?php

session_start();  // 啟用交談期
// 檢查Session變數是否存在, 表示是否已成功登入
if ( $_SESSION["login_session"] != true ) 
   header("Location: login.php");
echo "歡迎管理者者進入訂單管理頁面!<br/>";


	header("Content-Type: text/html; charset=utf-8");
	include("connsql.php");  //連結資料庫檔案
	$seldb = @mysql_select_db("goodsapp");  //連結資料庫
	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++;
	}





?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="user-scalable=yes, maximum-scale=1, minimum-scale=1, width=device-width" />
<title>訂購系統</title>
<link href="jquery-mobile/jquery.mobile-1.0.min.css" rel="stylesheet" type="text/css">
<script src="jquery-mobile/jquery-1.6.4.min.js" type="text/javascript"></script>
<script src="jquery-mobile/jquery.mobile-1.0.min.js" type="text/javascript"></script>
</head>
<body>
<div data-role="page" id="listOrder">
	<div data-role="header" data-position="fixed" data-theme="b">
		<h1>訂單查詢-選擇訂單</h1>
		<div data-role="navbar" data-theme="e">
			<ul>
				<li><a href="index.php" class="ui-btn-active">查詢未處理訂單</a></li>
				<li><a href="historyorder.php">查詢歷史訂單</a></li>
				<li><a href="itemSort.php">銷售排行榜</a></li>
			</ul>
		</div>
	</div>
	<div data-role="content">
		<ul data-role="listview" data-inset="true" id="lstOrder" data-filter="true" data-filter-placeholder="輸入訂單號碼、電話或姓名">
			<?php for($i=0; $i<$numrow; $i++) { ?>
			<li><a href='showorder.php?order=<?php echo $row_result[$i]["orderid"]; ?>' data-ajax='false'>
			<?php echo $row_result[$i]["orderid"]; ?>  
			<?php echo $row_result[$i]["phone"]; ?>  
			<?php echo $row_result[$i]["name"]; ?>
			</a></li>
			<?php } ?>
		</ul>
	</div>
</div>


</body>
</html>

test.php

<?php   
	header("Content-Type: text/html; charset=utf-8");
	include("connsql.php");  //連結資料庫檔案
	$seldb = @mysql_select_db("goodsapp");  //連結資料庫
	if (!$seldb) die("資料庫選擇失敗!");
  
  mysql_query("SET NAMES 'utf8'");
  $ordertime = '';
  $ordertime2 = '';
  $totalmoney = '';
  $orderid = '';
  $orderid2 = '';
  $name = '';
  $chargetime = '';
  $chargetime2 = '';

  if (isset($_POST['ordertime'])) {
    $ordertime = $_POST['ordertime'];
  }
  if (isset($_POST['ordertime2'])) {
    $ordertime2 = $_POST['ordertime2'];
  }
  if (isset($_POST['totalmoney'])) {
    $totalmoney = $_POST['totalmoney'];
  }
   if (isset($_POST['orderid'])) {
    $orderid = $_POST['orderid'];
  }
    if (isset($_POST['orderid2'])) {
    $orderid2 = $_POST['orderid2'];
  }
     if (isset($_POST['name'])) {
    $name = $_POST['name'];
  }
       if (isset($_POST['chargetime'])) {
    $chargetime = $_POST['chargetime'];
  }
       if (isset($_POST['chargetime2'])) {
    $chargetime2 = $_POST['chargetime2'];
  }
  if ($ordertime !== '' AND $ordertime2 !== '' And $totalmoney !== '') {
    $sql = "SELECT * FROM orders WHERE ordertime BETWEEN '$ordertime' AND '$ordertime2' AND totalmoney = '$totalmoney' ORDER BY ordertime DESC";    
  } else if ($ordertime !== '' AND $ordertime2 !== '') {
    $sql = "SELECT * FROM orders WHERE ordertime BETWEEN '$ordertime' AND '$ordertime2' ORDER BY ordertime DESC";  
  } else if ($totalmoney !== '') {
    $sql = "SELECT * FROM orders WHERE totalmoney = '$totalmoney' ORDER BY ordertime DESC";   
  } else if ($orderid !== '' AND $orderid2 !== '') {
    $sql = "SELECT * FROM orders WHERE orderid BETWEEN '$orderid' AND '$orderid2' ORDER BY orderid DESC"; 
	 } else if ($chargetime !== '' AND $chargetime2 !== '') {
    $sql = "SELECT * FROM orders WHERE chargetime BETWEEN '$chargetime' AND '$chargetime2' ORDER BY chargetime DESC";   	
 } else if ($orderid !== '') {
    $sql = "SELECT * FROM orders WHERE orderid = '$orderid' ";
 } else if ($chargetime !== '') {
    $sql = "SELECT * FROM orders WHERE chargetime = '$chargetime' ";
 } else if ($name !== '') {
    $sql = "SELECT * FROM orders WHERE name = '$name' ";   	
	
 }else 
  {
    $sql = "SELECT * FROM orders ORDER BY ordertime DESC";  
  }

  $result = mysql_query($sql) or die('MySQL query error');
  if (mysql_num_rows($result)) {
    echo "<table border = '1'>";
    echo "<tr>";
    echo "<th>訂單編號</th>";
	echo "<th>姓名</th>";
    echo "<th>訂購時間</th>";
    echo "<th>總額</th>";
	echo "<th>處理時間</th>";
    echo "</tr>";
    while($row = mysql_fetch_array($result))
    {
    echo "<tr>";
	  echo "<td>".$row['orderid']."</td>";
	  echo "<td>".$row['name']."</td>";
      echo "<td>".$row['ordertime']."</td>";
      echo "<td>".$row['totalmoney']."</td>";
	  echo "<td>".$row['chargetime']."</td>";
      echo "</tr>";    
    }
    echo "</table>";
  } else {
    echo "查無資料";
  }
?>

showorder.php

<?php
	header("Content-Type: text/html; charset=utf-8");
	include("connsql.php");  //連結資料庫檔案
	$seldb = @mysql_select_db("goodsapp");  //連結資料庫
	if (!$seldb) die("資料庫選擇失敗!");
	
	if (isset($_GET["update"])) {
		$order = $_GET["update"];
		$charged_tm=date('Y-m-d H:i:s',mktime(date('H')+8, date('i'), date('s'), date('m'), date('d'), date('Y')));
		$sql_query = "UPDATE `orders` SET `finish`=1,chargetime='$charged_tm' 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++;
		}
	}
?>
dragonH iT邦超人 5 級 ‧ 2019-05-21 19:17:03 檢舉
看不太懂你的問題

反正如果你想要的是訂單編號是個超連結

點了可以連過去showorder.php之類的

把test.php產生表格那邊

orderId 那行改成

echo "<td><a href = 'showorder.php?order=".$row['orderid']."'>".$row['orderid']."</a></td>";

在你的showorder.php就能以$_GET['order'] 接到值
哇~~~好久沒看到波動拳寫法了。
如果只是作業的話,用上面跟你說的給get參數就好。

但如果是工作上的程式,你最好打掉重練。
這在我這裏這樣寫的話,會被我趕回家吃自已。
我過我想你這是作業居多,所以還是不說明原因好了。
dragonH iT邦超人 5 級 ‧ 2019-05-22 11:12:32 檢舉
哈 大家剛開始寫應該都是這樣啦

而且他甚至看起來還不熟 if else 的用法

直接給他其他組query語句的方法

我覺得有點可怕
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

0
海綿寶寶
iT邦大神 1 級 ‧ 2019-05-22 09:34:21

只要改一列即可

目前 test.php 的寫法是

echo "<td>".$row['orderid']."</td>";

為了一致性,就拿 index.php 相同的寫法來抄

<li><a href='showorder.php?order=<?php echo $row_result[$i]["orderid"]; ?>' data-ajax='false'>

所以 test.php 的結果就變成

echo "<li><a href='showorder.php?order=".$row_result[$i]["orderid"]."' data-ajax='false'>";

我要發表回答

立即登入回答