当我尝试转到第2页时我没有结果的空白页
因为第一个条件if ($_SERVER['REQUEST_METHOD'] == 'POST')
在此条件下,必须选择名称&datefrom&dateto并提交以显示结果,以便当我们转到第2页及更高版本时,此条件$_SERVER['REQUEST_METHOD'] == 'POST'
不是TRUE吗?
解决这个问题的想法我仍然在考虑,但是我没有找到,我的头会爆炸:D
我需要3天的时间来解决它:( 而且我会尽量使用Stacoverflow中出现的所有方式,但没有人解决
这是我的代码和我的数据库帮助
已编辑
showbydrivers.php
<?php //session_start(); ?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="description" content="$1">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="">
<title>Under work</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.12.2/css/bootstrap-select.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.12.2/js/bootstrap-select.min.js"></script>
</head>
<body>
<!----- `drivers` ----->
<?php
require 'config.php';
$query = "SELECT * FROM `driversuser`";
$result1 = mysqli_query($con, $query);
//
//
?>
<div class="container">
<div class="addingcar">
<form dir="rtl" method="post">
<div class="">
<b>عرض وردية سائق</b>
</div>
<br/>
<label>
<b>اختر السائق</b>
<select name="insdname" id="framework" class="align-right selectpicker" data-live-search="true" required>
<option style="text-align: right" value="">اختر السائق ...</option>
<?php while($row1 = mysqli_fetch_array($result1)):; ?>
<option style="text-align: right" value="<?php echo $row1[10]; ?>"><?php echo $row1[1]; ?></option>
<?php endwhile; ?>
</select>
</label>
<br />
<label>
<b>من</b>
<input type="date" name="datefrom" required>
</label>
<br />
<label>
<b>الي</b>
<input type="date" name="dateto" required>
</label>
<br /><br />
<input type="hidden" name="hidden_framework" id="hidden_framework" />
<input type="submit" name="submit" class="btn btn-info" value="عــــرض" />
</form>
<?php
$divcon = '<div class="result-info" style="text-align: right; font-size: 17px; background-color: #ff661a; padding: 5px; margin-top: 5px;">';
$num_rec_per_page = 3;
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
echo $divcon;
$selected_val = $_POST['insdname'];
$date_val = $_POST['datefrom'];
$dateto_val = $_POST['dateto'];
$totalprice = 0;
$totalprice_paid = 0;
////////////////////
if(isset($_GET['pg']))
{
$pg = $_GET['pg'];
}
else
{
$pg = 1;
};
$startfrom = ( $pg-1 ) * $num_rec_per_page;
////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
$driverName = mysqli_query($con, "SELECT * FROM `reports` r1 INNER JOIN `driversuser` d1 ON r1.DriverCode = d1.Driver_ID WHERE r1.DriverCode = '$selected_val'");
while ($datareport2 = mysqli_fetch_array($driverName)) {
echo "<div style='margin-top: 0px';>";
echo "<div style='font-size: 18px; color: blue; display: inline';>اسم السائق: </div>";
echo "<div style='display: inline';>".$datareport2['DriverName']."</div>";
echo "<div style='display: inline; margin-right: 10%; color: white; border: dotted 2px yellow; padding: 2px;'>";
echo "<div class='datefrom' style='display: inline; color: white;'>"."فاتوره من ";
echo "<div style='display: inline; color: black; margin-right: 10px;'>".$date_val."</div>"."</div>";
echo "<div class='dateto' style='display: inline; margin-right: 10px; color: white;'>"." الي ";
echo "<div style='display: inline; color: black; margin-right: 10px;'>".$dateto_val."</div>"."</div>";
echo "</div>"."</div>";
break 1;
}
//////////////////////////////////////////////////////////////////////////////////////////////
/////////***********///////////
$carinfo = mysqli_query($con, "SELECT * FROM `reports` r1 INNER JOIN `cars` c1 ON r1.CarCode = c1.Car_ID INNER JOIN `driversuser` d1 ON r1.DriverCode = d1.Driver_ID WHERE r1.Datefrom BETWEEN '$date_val' AND '$dateto_val' AND DriverCode = '$selected_val' ORDER BY r1.Datefrom DESC LIMIT $startfrom , $num_rec_per_page");
while ($carReport1 = mysqli_fetch_array($carinfo)) {
echo '<div class="reportsrow" style="background-color: #006600; color: white; margin: 7px; padding-right: 8px;">'.date("Y-m-d h:i A", strtotime($carReport1['Datefrom']))." ".date("Y-m-d h:i A", strtotime($carReport1['DateTo']))." ".$carReport1['Price']." ".$carReport1['PriceTaken']." ".$carReport1['CarName']." ".$carReport1['CarModel']." ".$carReport1['CarNumber']." ".$carReport1['CarColor']." ".'</div>';
//echo $carReport1['Price'] - $carReport1['PriceTaken']; //Edit here later
$totalprice += $carReport1['Price']-$carReport1['PriceTaken']-$carReport1['PricePaid']; //تم اضافة المصروفات ضمن القيم المطروحة
//echo '<br/>';//****** Edit here later *******
////// تمت عملية حساب اذا كان لديه رصيد ام لا ///////
$totalprice_paid += $carReport1['PricePaid']+$carReport1['PriceTaken']-$carReport1['Price'];
}
if ($_SERVER['REQUEST_METHOD'] == 'POST' && $totalprice > 0){
/// تمت اضافة قيمة PricePaid ضمن العملية الحسابية
echo "مدين بــ ".$totalprice." ج.م";
echo '<br/>';
}
//
if ($_SERVER['REQUEST_METHOD'] == 'POST' && $totalprice_paid > 0){
/// تمت اضافة قيمة PricePaid ضمن العملية الحسابية
echo "رصيده ".$totalprice_paid." ج.م";
}
////////////////
////////////////
$qry = mysqli_query($con, "SELECT * FROM `reports` r1 INNER JOIN `cars` c1 ON r1.CarCode = c1.Car_ID INNER JOIN `driversuser` d1 ON r1.DriverCode = d1.Driver_ID WHERE Datefrom BETWEEN '$date_val' AND '$dateto_val' AND DriverCode = '$selected_val' ORDER BY r1.Datefrom");
$total_page = ceil (($qry->num_rows/$num_rec_per_page));
echo "<ul class='pagination'>";
for($i=1;$i<=$total_page;$i++)
{
echo "<li><a href='{$_SERVER['PHP_SELF']}?pg=".$i."'>".$i."</a>"."</li>";
}
echo "</ul>";
///////////////
///////////////
echo '</div>';
mysqli_close($con);
}
?>
</div>
</div>
</body>
</html>
和我的数据库:testing.sql
-- phpMyAdmin SQL Dump
-- version 4.8.5
-- https://www.phpmyadmin.net/
--
-- Host: 127.0.0.1
-- Generation Time: Feb 27, 2019 at 09:33 PM
-- Server version: 10.1.36-MariaDB
-- PHP Version: 7.2.10
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET AUTOCOMMIT = 0;
START TRANSACTION;
SET time_zone = "+00:00";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;
--
-- Database: `testing`
--
-- --------------------------------------------------------
--
-- Table structure for table `cars`
--
CREATE TABLE `cars` (
`ID` int(11) NOT NULL,
`CarName` varchar(20) NOT NULL,
`CarModel` varchar(20) NOT NULL,
`CarNumber` varchar(20) NOT NULL,
`CarColor` varchar(20) NOT NULL,
`Car_ID` varchar(255) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--
-- Dumping data for table `cars`
--
INSERT INTO `cars` (`ID`, `CarName`, `CarModel`, `CarNumber`, `CarColor`, `Car_ID`) VALUES
(1, 'تويوتا', 'ياريس', 'ف ق 127', 'ابيض', 'C52134764I'),
(2, 'تويوتا', 'كورولا', 'ط غ 165', 'اسود', 'C27692315I'),
(3, 'جيلي', 'ام جراند', 'ص ل 396', 'ازرق', 'C98050930C'),
(4, 'بي واي دي', 'اف 3', 'س ص 648', 'ابيض', 'C42897410K'),
(5, 'شيفروليه', 'لانوس', 'و د 492', 'فيراني', 'C23439035T'),
(6, 'شيفروليه', 'افيو', 'م ل 345', 'احمر', 'C89045285S');
-- --------------------------------------------------------
--
-- Table structure for table `driversuser`
--
CREATE TABLE `driversuser` (
`ID` int(11) NOT NULL,
`DriverName` varchar(30) NOT NULL,
`Office` varchar(30) NOT NULL,
`Company` varchar(50) NOT NULL,
`UberMail` varchar(50) NOT NULL,
`UberPassword` varchar(50) NOT NULL,
`UberPhone` varchar(25) NOT NULL,
`CareemMail` varchar(50) NOT NULL,
`CareemPassword` varchar(50) NOT NULL,
`CareemPhone` varchar(25) NOT NULL,
`Driver_ID` varchar(255) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--
-- Dumping data for table `driversuser`
--
INSERT INTO `driversuser` (`ID`, `DriverName`, `Office`, `Company`, `UberMail`, `UberPassword`, `UberPhone`, `CareemMail`, `CareemPassword`, `CareemPhone`, `Driver_ID`) VALUES
(1, 'احمد محمد السيد', 'فيوتشر كار', 'Uber', 'example@exm.com', '0155gddd999', '01112345678', '', '', '', 'D15427214J'),
(2, 'محمد علي عوضين', 'فيوتشر كار', 'Careem', '', '', '', 'MohaCM@hotmail.com', 'CM963258', '01235469878', 'D90655118M');
-- --------------------------------------------------------
--
-- Table structure for table `reports`
--
CREATE TABLE `reports` (
`ID` int(11) NOT NULL,
`DriverCode` varchar(255) NOT NULL,
`CarCode` varchar(255) NOT NULL,
`Price` int(11) NOT NULL,
`PriceTaken` int(11) NOT NULL,
`PricePaid` int(11) NOT NULL,
`Datefrom` datetime NOT NULL,
`DateTo` datetime NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--
-- Dumping data for table `reports`
--
INSERT INTO `reports` (`ID`, `DriverCode`, `CarCode`, `Price`, `PriceTaken`, `PricePaid`, `Datefrom`, `DateTo`) VALUES
(1, 'D15427214J', 'C89045285S', 250, 150, 0, '2019-02-23 06:00:00', '2019-02-24 06:00:00'),
(2, 'D15427214J', 'C98050930C', 250, 250, 0, '2019-02-24 06:00:00', '2019-02-25 06:00:00'),
(3, 'D15427214J', 'C23439035T', 250, 100, 0, '2019-02-25 18:00:00', '2019-02-26 18:00:00'),
(4, 'D15427214J', 'C98050930C', 150, 150, 0, '2019-02-26 06:00:00', '2019-02-26 16:00:00'),
(5, 'D15427214J', 'C52134764I', 150, 100, 50, '2019-02-24 06:00:00', '2019-02-24 16:00:00'),
(6, 'D90655118M', 'C42897410K', 150, 50, 100, '2019-02-24 06:00:00', '2019-02-25 06:00:00'),
(7, 'D90655118M', 'C98050930C', 150, 100, 50, '2019-02-01 06:00:00', '2019-02-01 16:00:00');
--
-- Indexes for dumped tables
--
--
-- Indexes for table `cars`
--
ALTER TABLE `cars`
ADD PRIMARY KEY (`ID`);
--
-- Indexes for table `driversuser`
--
ALTER TABLE `driversuser`
ADD PRIMARY KEY (`ID`);
--
-- Indexes for table `reports`
--
ALTER TABLE `reports`
ADD PRIMARY KEY (`ID`);
--
-- AUTO_INCREMENT for dumped tables
--
--
-- AUTO_INCREMENT for table `cars`
--
ALTER TABLE `cars`
MODIFY `ID` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=7;
--
-- AUTO_INCREMENT for table `driversuser`
--
ALTER TABLE `driversuser`
MODIFY `ID` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3;
--
-- AUTO_INCREMENT for table `reports`
--
ALTER TABLE `reports`
MODIFY `ID` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=8;
COMMIT;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
答案 0 :(得分:0)
我找到了一种方法来修复我将方法从POST更改为GET并将$ _POST更改为$ _REQUEST并在代码打击方面进行了一些更改
<?php
$divcon = '<div class="result-info" style="text-align: right; font-size: 17px; background-color: #ff661a; padding: 5px; margin-top: 5px;">';
$num_rec_per_page = 3;
//if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if (isset($_REQUEST['DN']) && isset($_REQUEST['DF']) && isset($_REQUEST['DT'])){
$selected_val = $_REQUEST['DN'];
$date_val = $_REQUEST['DF'];
$dateto_val = $_REQUEST['DT'];
$totalprice = 0;
$totalprice_paid = 0;
////////////////////
if(isset($_GET['pg']))
{
$pg = $_GET['pg'];
}
else
{
$pg = 1;
};
$startfrom = ( $pg-1 ) * $num_rec_per_page;
////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
$driverName = mysqli_query($con, "SELECT * FROM `reports` r1 INNER JOIN `driversuser` d1 ON r1.DriverCode = d1.Driver_ID WHERE r1.DriverCode = '$selected_val'");
while ($datareport2 = mysqli_fetch_array($driverName)) {
echo $divcon;
echo "<div style='margin-top: 0px';>";
echo "<div style='font-size: 18px; color: blue; display: inline';>اسم السائق: </div>";
echo "<div style='display: inline';>".$datareport2['DriverName']."</div>";
echo "<div style='display: inline; margin-right: 10%; color: white; border: dotted 2px yellow; padding: 2px;'>";
echo "<div class='datefrom' style='display: inline; color: white;'>"."فاتوره من ";
echo "<div style='display: inline; color: black; margin-right: 10px;'>".$date_val."</div>"."</div>";
echo "<div class='dateto' style='display: inline; margin-right: 10px; color: white;'>"." الي ";
echo "<div style='display: inline; color: black; margin-right: 10px;'>".$dateto_val."</div>"."</div>";
echo "</div>"."</div>";
break 1;
}
//////////////////////////////////////////////////////////////////////////////////////////////
/////////***********/////////// LIMIT $startfrom , $num_rec_per_page
$carinfo = mysqli_query($con, "SELECT * FROM `reports` r1 INNER JOIN `cars` c1 ON r1.CarCode = c1.Car_ID INNER JOIN `driversuser` d1 ON r1.DriverCode = d1.Driver_ID WHERE r1.Datefrom BETWEEN '$date_val' AND '$dateto_val' AND DriverCode = '$selected_val' ORDER BY r1.Datefrom DESC LIMIT $startfrom , $num_rec_per_page");
while ($carReport1 = mysqli_fetch_array($carinfo)) {
echo '<div class="reportsrow" style="background-color: #006600; color: white; margin: 7px; padding-right: 8px;">'.date("Y-m-d h:i A", strtotime($carReport1['Datefrom']))." ".date("Y-m-d h:i A", strtotime($carReport1['DateTo']))." ".$carReport1['Price']." ".$carReport1['PriceTaken']." ".$carReport1['CarName']." ".$carReport1['CarModel']." ".$carReport1['CarNumber']." ".$carReport1['CarColor']." ".'</div>';
//echo $carReport1['Price'] - $carReport1['PriceTaken']; //Edit here later
$totalprice += $carReport1['Price']-$carReport1['PriceTaken']-$carReport1['PricePaid']; //تم اضافة المصروفات ضمن القيم المطروحة
//echo '<br/>';//****** Edit here later *******
////// تمت عملية حساب اذا كان لديه رصيد ام لا ///////
$totalprice_paid += $carReport1['PricePaid']+$carReport1['PriceTaken']-$carReport1['Price'];
}
if ($totalprice > 0){
/// تمت اضافة قيمة PricePaid ضمن العملية الحسابية
echo "مدين بــ ".$totalprice." ج.م";
echo '<br/>';
}
//
if ($totalprice_paid > 0){
/// تمت اضافة قيمة PricePaid ضمن العملية الحسابية
echo "رصيده ".$totalprice_paid." ج.م";
echo '<br/>';
}
////////////////
////////////////
$qry = mysqli_query($con, "SELECT * FROM `reports` r1 INNER JOIN `cars` c1 ON r1.CarCode = c1.Car_ID INNER JOIN `driversuser` d1 ON r1.DriverCode = d1.Driver_ID WHERE Datefrom BETWEEN '$date_val' AND '$dateto_val' AND DriverCode = '$selected_val' ORDER BY r1.Datefrom DESC");
$total_page = ceil (($qry->num_rows/$num_rec_per_page));
echo "<ul class='pagination'>";
for($i=1;$i<=$total_page;$i++)
{
//echo "<li><a href='{$_SERVER['PHP_SELF']}?pg=".$i."'>".$i."</a>"."</li>";
echo "<li><a href=\"".$_SERVER['PHP_SELF']."?pg=$i&DN=$selected_val&DF=$date_val&DT=$dateto_val\">$i</a></li>";
}
echo "</ul>";
///////////////
///////////////
echo '</div>';
mysqli_close($con);
}
?>
我在该网站上仅创建了1个帖子,帮助我实现了这一想法,但我对整个结果不满意,我希望有一种方法可以通过$ _POST做到这一点
感谢所有帮助我的人<3