I have a MySQL Database on my website that lists engine parts and am currently working on PHP code to dynamically make a table from Query results.
My code for creating the tables for example are as follows:
<?php
mysql_connect("localhost", "username", "password") or die(mysql_error());
mysql_select_db("djvkcom_ysp") or die(mysql_error());
// Get specific items using query from the "ysp" table and stores them in result variable
$result = mysql_query("SELECT * FROM ysp
WHERE Heading='Anodes' AND `Description` LIKE '%2QM15%'") or die(mysql_error());
// Sort the results into rows
$row= mysql_fetch_array( $result );
// Display the contents of the entry
echo "<table border='1' style='background-color: #ffffff; text-align:center;'>";
echo "<tr> <th>Image</th> <th>Item</th> <th>Engine Models</th> <th>Part No.</th> <th>Price</th> </tr>";
// keeps getting the next row until there are no more to get
while($row= mysql_fetch_array( $result )) {
// Print out the contents of each row into a table
echo "<tr><td>";
echo "<img src=\"".$row['Image']."\">";
echo "</td><td>";
echo $row['SubHeading'];
echo "</td><td>";
echo $row['Description'];
echo "</td><td>";
echo $row['PartNo'];
echo "</td><td>";
echo $row['Price'];
echo "</td></tr>";
}
echo "</table>";
?>
The above code looks for parts with the heading 'Anodes' that contain the engine model '2QM15' in the description and then displays the results in a tabular format. When running the same query in phpMyAdmin's Search or Query tabs on the database this returns 2 results from my database. However when the above code is used on my website it only returns 1 result.
I know the code is not at fault as it is only having this problem on that specific query. I have other pages with the same format of code but a different query showing multiple results. This makes me think it has something to do with the way the that particular description field is written. But I am confused as to why the Query works fine in phpMyAdmin but not when it is put on the webpage with the above code.



Reply With Quote



Bookmarks