我有一个由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