Hope someone can help me with this weird one. I have some data in a mysql database and a php page draws records from it and displays it in a table. The odd thing that happens is that the displayed tables is showing records that are not supposed to be there. ie they are not in the search criteria when I complete the form.
I am not sure what is going wrong. There should be no reason why this happens, as far as I can see. Maybe I am looking in the wrong place to find the problem.
Please help.
Thanks everyone.
It is impossible to help without seeing any code.
Hi JimL,
Not sure which code to start with but here is part of the page that is giving me grief.
[php]$colname_Suppliers = “-1”;
if (isset($_GET[‘Supplier’])) {
$colname_Suppliers = $_GET[‘Supplier’];
}
mysql_select_db($database_TrophyMaster, $TrophyMaster);
$query_Suppliers = sprintf(“SELECT * FROM tbl_Suppliers WHERE Supplier = %s”, GetSQLValueString($colname_Suppliers, “text”));
$Suppliers = mysql_query($query_Suppliers, $TrophyMaster) or die(mysql_error());
$row_Suppliers = mysql_fetch_assoc($Suppliers);
$totalRows_Suppliers = mysql_num_rows($Suppliers);
$colname_Clients = “-1”;
if (isset($_SESSION[‘MM_Username’])) {
$colname_Clients = $_SESSION[‘MM_Username’];
}
mysql_select_db($database_TrophyMaster, $TrophyMaster);
$query_Clients = sprintf(“SELECT * FROM tbl_Clients WHERE ClientEmail = %s”, GetSQLValueString($colname_Clients, “text”));
$Clients = mysql_query($query_Clients, $TrophyMaster) or die(mysql_error());
$row_Clients = mysql_fetch_assoc($Clients);
$totalRows_Clients = mysql_num_rows($Clients);
$colname1_Orders = “-1”;
if (isset($_GET[‘ClientID’])) {
$colname1_Orders = $_GET[‘ClientID’];
}
$colname2_Orders = “-1”;
if (isset($_GET[‘OrderDate’])) {
$colname2_Orders = $_GET[‘OrderDate’];
}
$colname3_Orders = “-1”;
if (isset($_GET[‘Freight’])) {
$colname3_Orders = $_GET[‘Freight’];
}
$colname4_Orders = “-1”;
if (isset($_GET[‘Supplier’])) {
$colname4_Orders = $_GET[‘Supplier’];
}
mysql_select_db($database_TrophyMaster, $TrophyMaster);
$query_Orders = sprintf(“SELECT *, sum(PartQty) AS PartQty FROM tbl_OrderDetails WHERE tbl_OrderDetails.ClientID = %s AND tbl_OrderDetails.OrderDate= %s AND tbl_OrderDetails.Freight = %s AND tbl_OrderDetails.Supplier =%s GROUP BY PartCode ORDER BY tbl_OrderDetails.PartCode, tbl_OrderDetails.RequiredDate”, GetSQLValueString($colname1_Orders, “int”), GetSQLValueString($colname2_Orders, “int”), GetSQLValueString($colname3_Orders, “text”), GetSQLValueString($colname4_Orders, “text”));
$Orders = mysql_query($query_Orders, $TrophyMaster) or die(mysql_error());
$row_Orders = mysql_fetch_assoc($Orders);
$totalRows_Orders = mysql_num_rows($Orders);
?>[/php]
When I enter a certain date, ie 25/10/13 and 25/09/13, I get the exact same result in the table.
This is the code that renders the table.
[php]
Date | Order No. | Freight | ||
---|---|---|---|---|
<?php echo $_GET['OrderDate']; ?> | <?php echo $row_Orders['OrderNumber']; ?> | <?php echo $_GET['Freight']; ?> |
Part | Description | Qty Ordered | Qty Supplied |
---|---|---|---|
<?php echo $row_Orders['PartCode']; ?> | <?php echo $row_Orders['PartDescription']; ?> | <?php echo $row_Orders['PartQty']; ?> |
Please help if you can.
My page does not grab the records that I expect it to. I am not exactly sure which code to send for you all to review. I have checked the date in the database and it looks okay but when I do a search from the php page the results are not right.
Can someone direct me to where to look?
Thanks.
This it my query statement
$query_Orders = sprintf(“SELECT *, sum(PartQty) as PartQty FROM tbl_OrderDetails WHERE tbl_OrderDetails.ClientID = %s AND tbl_OrderDetails.OrderDate= %s AND tbl_OrderDetails.Freight = %s AND tbl_OrderDetails.Supplier =%s GROUP BY PartCode ORDER BY tbl_OrderDetails.PartCode, tbl_OrderDetails.RequiredDate”, GetSQLValueString($colname1_Orders, “int”),GetSQLValueString($colname2_Orders, “int”),GetSQLValueString($colname3_Orders, “text”),GetSQLValueString($colname4_Orders, “text”));
$Orders = mysql_query($query_Orders, $TrophyMaster) or die(mysql_error());
$row_Orders = mysql_fetch_assoc($Orders);
$totalRows_Orders = mysql_num_rows($Orders);
I think I may have found it. I had the $colname2_Orders value set as “int” instead of “date”. This seems to have fixed the problem.
Hope this helps anyone else.