我有一個由php腳本用來顯示數據的mysql數據庫......我遇到的問題是,它看起來是隨機發生的,它錯過了結果,我看不到一個模式以確定爲什麼它可能會這樣做...從mysql數據庫中缺少數據
當我檢查數據庫時,所有的數據似乎很好。
這裏是我最初的搜索頁面
<?php
include 'connect.php';
//set variable
$option = '';
// Get the county names from database - no duplicates - Order A-Z
$query = "SELECT DISTINCT tradingCounty FROM offers ORDER BY tradingCounty ASC";
// execute the query, $result will hold all of the Counties in an array
$result = mysqli_query($con,$query);
while($row = mysqli_fetch_array($result)) {
$option .="<option>" . $row['tradingCounty'] . "</option>";
}
echo "<html xmlns='http://www.w3.org/1999/xhtml'>";
echo "<title>HSB - Latest Offers</title>";
echo "<style type='text/css'>;
body {
background-color: #FFF;
}
#wrapper {
background-color: #FFF;
height: auto;
width: 1000px;
margin-right: auto;
margin-left: auto;
font-family: 'Trebuchet MS', Arial, Helvetica, sans-serif;
}
</style>
</head>
<body>
<div id='wrapper'>
<p><img src='images/header.jpg' width='400' height='100' alt='header' /></p>
<HR/>
Select an area from the menu below to view any offers in that area.
<form id='filter' name='filter' method='post' action='resultssimple.php'>
<p><label>County</label></p>
<select name='result' id='result'>' . $option . '</select>
<input name='' type='submit' />
</form>
</div>
</body>
</html>";
?>
,這裏是我的結果頁
<?
include 'connect.php';
//Get the details from previous page
$SelectedCounty = $_POST["result"];
// Select offers linked to selected county from form
$result = mysqli_query($con,"SELECT * FROM offers WHERE tradingCounty ='" . $SelectedCounty . "'ORDER BY categoryIdName ASC;");
// PREVIOUS ATTEMPTS - ALL WRONG - GGGGRRRRRRRRRRRR !!!!!!!!
//------------------------------------------------------------
//$result = mysqli_query($con,"SELECT * FROM offers WHERE tradingCounty LIKE" . $SelectedCounty);
//$result = mysql_query("SELECT * FROM pdetails WHERE uid='" . $inputname . "';");
//"SELECT * FROM `offers` WHERE `tradingCounty` LIKE
//$result = mysqli_query($con,"SELECT * FROM offers;");
//$result = mysql_query("SELECT * FROM pdetails WHERE uid='" . $inputname . "';");
//$result = mysqli_query("SELECT * FROM offers WHERE tradingCounty=" . $SelectedCounty);
//check to see if results is set - error if not.
if(!$result)
{
die("<p>Error in listing tables: ". mysql_error()."</p>");
}
//Show all records for selected county
echo ("<p><h2>Showing Latest Offers In : " . $SelectedCounty . "</h2></p>");
echo ("<p><a href='offers.php' target='_self'>back to search menu</a></p>");
/*
echo ("<table border='1'>");
echo ("<tr>");
echo ("<td>ID</td><td>Category</td><td>Business Name</td><td>Business Address</td><td>Address2</td><td>Address3</td><td>Town</td><td>County</td><td>Post Code</td><td>Telephone</td><td>URL</td><td>Email</td><td>Discount/Special Offer</td><td>valid from</td>");
*/
while($row = mysqli_fetch_row($result))
{
echo ("<div style=' background-color: #EFF5FF; color: #06C; padding: 5px; float: left; border: 1px dotted #06C; margin: 10px; width: 300px; height: 300px; text-align: center; >");
// echo ("" . $row[0] . "");
// echo ("</br>");
echo ("<strong>" . $row[1] . "</strong>");
echo ("<hr/>");
// echo ("</br>");
echo ("" . $row[2] . "");
echo ("</br>");
echo ("" . $row[3] . "");
echo ("</br>");
// echo ("" . $row[4] . "");
// echo ("</br>");
// echo ("" . $row[5] . "");
// echo ("</br>");
echo ("" . $row[6] . "");
echo ("</br>");
echo ("" . $row[7] . "");
echo ("</br>");
echo ("" . $row[8] . "");
echo ("</br>");
echo ("" . $row[9] . "");
echo ("</br>");
// echo ("" . $row[10] . "");
// echo ("</br>");
echo ("" . $row[11] . "");
echo ("</br>");
echo ("<hr/>");
echo ("<strong>" . $row[12] . "</strong>");
echo ("</br>");
echo ("</div>");
/* echo("<tr>");
echo("<td>" . $row[0] . "</td>" . "<td>" . $row[1] . "</td>" . "<td>" . $row[2] . "</td>" . "<td>" . $row[3] . "</td>" . "<td>" . $row[4] . "</td>" . "<td>" . $row[5] . "</td>" . "<td>" . $row[6] . "</td>" . "<td>" . $row[7] . "</td>" . "<td>" . $row[8] . "</td>" . "<td>" . $row[9] . "</td>" . "<td>" . $row[10] . "</td>" . "<td>" . $row[11] . "</td>" . "<td>" . $row[12] . "</td>" . "<td>" . $row[13] . "</td>");
echo("</tr>");
*/
}
// echo("</table>");
?>
什麼我越來越可以看出here
是一個更清楚一點......一些結果是缺少企業類型,企業名稱和一些地址 – sturobinson81 2014-09-02 15:01:06
只是挑剔這裏的,但在所有的'SELECT'語句,我建議你明確地命名你想要的列選擇而不是使用'SELECT * ...'。 – kevin628 2014-09-02 15:07:32
:)注意到凱文...我想從業餘愛好者/我的觀點選擇*更快:)而我只是不得不註釋掉我不想顯示的行... – sturobinson81 2014-09-02 15:14:49