I can't seem to work out how I can style the td's in the following code.
I want the Match Details to be aligned to the right. Normally I would just insert straight in, but this doesn't seem to work.
I also want to bolded the away team row.
Any idea?
Cheers
<h3>SEPTEMBER 2017</h3>
<table><?php $sql = "SELECT * FROM `results` WHERE `year`='2017' AND `Division`='AA1' AND `month`='September'";
$result = $conn ->query($sql);
if ($result-> num_rows > 0) {
while($row = $result -> fetch_assoc()) {
echo "<tr><td>" . $row["day"] . ", " . $row["date"] . " " . $row["month"] . "</td> <td>" . $row["awayteam"] . "</td> <td>" . $row["homescore"] . " - " . $row["awayscore"] . "</td> <td>" . $row["venue"] . "</td> <td>ESFA League</td><td>Match details</td></tr><br>";
}
"</table>";
} else {
echo "No games listed for this month";
}
?></table>
to styling your display data you need to apply css code as declared in <style> tag.
<style>
.table-boarderd{
border: 1px solid black;
text-align: left;
}
.pull-right{
text-align: right;
}
.bold{
font-weight: bold;
}
</style>
<h3>SEPTEMBER 2017</h3>
<table class="table-boarderd">
<?php
$sql = "SELECT * FROM `results` WHERE `year`='2017' AND `Division`='AA1' AND `month`='September'";
$result = $conn ->query($sql);
?>
<?php
if ($result-> num_rows > 0) {
while($row = $result -> fetch_assoc()){ ?>
<tr>
<td><?=$row["day"]?></td>
<td><?=$row["date"]?></td>
<td><?=$row["month"]?></td>
<td class="pull-right bold"><?=$row["awayteam"]?></td>
<td><?=$row["homescore"]?>-<strong><?=$row["awayscore"]?></strong></td>
<td><?=$row["venue"]?></td>
<td>ESFA League</td>
<td>Match details</td>
</tr><br/>
<?php } ?>
</table>
<?php }
else {
echo "No games listed for this month";
}
?>
As I have used custom css with table awayteam cell you can use at anywhere
Write the css for the code in head tag
table, th, td {
border: 1px solid black;
text-align: right;
}
Then you're trying it the false way, because the straight way in is possible. Also you've closed your table twice. I removed it once. Try this:
<h3>SEPTEMBER 2017</h3>
<table><?php $sql = "SELECT * FROM `results` WHERE `year`='2017' AND `Division`='AA1' AND `month`='September'";
$result = $conn ->query($sql);
if ($result-> num_rows > 0) {
while($row = $result -> fetch_assoc()){
echo "<tr><td>" . $row["day"] . ", " . $row["date"] . " " . $row["month"] . "</td> <td><b>" . $row["awayteam"] . "</b></td> <td>" . $row["homescore"] . " - " . $row["awayscore"] . "</td> <td>" . $row["venue"] . "</td> <td>ESFA League</td><td style="text-align: right;">Match details</td></tr><br>";
}
}
else {
echo "No games listed for this month";
}
?></table>
Related
Here's what I'm trying to do:
I'm working on an inventory management system for my work, and the idea is that when we need to order something it's status is set to 'order' in the mySQL database which contains all of our inventory items. We have an 'Order Queue' page that displays all of the things that need ordered. The twist is that we need two different tables for each supplier: one for Purchase Orders and one for Request for Quotes (e.g. buying raw material isn't always a constant price, so a PO and RFQ need a different format). Then for each supplier table there is a submit button that says "Push supplier name PO/RFQ".
Pressing this button takes you to a second page which creates the PO and sends the email to the supplier. I know this isn't the issue here because regardless of what is in this script it will run three times when the button is pressed.
Here's some code:
$suppTable = mysqli_query($conn,"SELECT * FROM `suppliers` WHERE (`user` = '" . $user_login . "')");
This creates the array storing all the supplier info, and is all correct.
<div class="trackheader" style="border-radius:5px 5px 0px 0px; border: 2px solid #CC3333;">
<h3 style="color:white !important; margin-left: 10px; vertical-align: middle; display: inline-block;">Display:</h3>
</div>
<div class="trackcont3" style="border-radius:0px 0px 5px 5px; border: 2px solid #CC3333; margin-bottom:20px;">
<form action="" method="POST" id="rec">
<?php
while($row1 = mysqli_fetch_assoc($suppTable)){
echo "<input type='checkbox' id='" . $row1['name'] . "' name='" . $row1['name'] . "' value='" . $row1['name'] . "' onchange='this.form.submit()'";
if(isset($_POST['' . $row1['name'] . ''])){
echo "checked='checked'";
}
echo ">";
echo "<label for='" . $row1['name'] . "'>" . $row1['name'] . "</label>";
}
?>
</form>
</div>
Please ignore the inline CSS - this will get added to the stylesheet once this actually works...
This is a pretty straightforward snippet: it creates display toggles for each supplier in the database so that they don't all show up at once.
Now for the fun stuff:
<?php
$loopTable = mysqli_query($conn,"SELECT * FROM `suppliers` WHERE (`user` = '" . $user_login . "')"); //this creates another array with each supplier tied to the user account
while($row2 = mysqli_fetch_assoc($loopTable)){ //this while loop creates two tables for each supplier: one with items that need to be ordered in a PO and another table for RFQ
if(isset($_POST['' . $row2['name'] . ''])){ //controls display from the above form
$display['' . $row2['name'] . ''] = "block";
} else {
$display['' . $row2['name'] . ''] = "none";
}
echo "<div style='display:" . $display['' . $row2['name'] . ''] . " ;'>";
echo "<div class='trackheader' style='border-radius:5px 5px 0px 0px; border: 2px solid #CC3333;'>
<h3 style='color:white !important; margin-left: 10px; vertical-align: middle; display: inline-block;'>" . $row2['name'] . " PO</h3>
</div>";
echo "<div class='trackcont2'><table style='width:100%; !important'><tbody style='width:100%; !important'>
<tr style='width:100% !important;'>
<th style='width:16.6%;'><h3 style='color:grey !important;'>ALEX ID</th>
<th style='width:16.6%;'><h3 style='color:grey !important;'>Description</th>
<th style='width:16.6%;'><h3 style='color:grey !important;'>Supplier P/N</th>
<th style='width:16.6%;'><h3 style='color:grey !important;'>Order QTY</th>
<th style='width:16.6%;'><h3 style='color:grey !important;'>Price</th>
<th style='width:16.6%;'><h3 style='color:grey !important;'>Total</th>
</tr>";
$i = 0;
$listTablePO = mysqli_query($conn,"SELECT * FROM `inventory` WHERE (`user` = '" . $user_login . "') AND (`supplier` = '" . $row2['name'] . "') AND (`status` = 'order') AND (`method` = 'PO')"); //this creates an array with all database items from the appropriate supplier which need ordered (and go in the PO table)
$total = 0; //tallies a running total of the price
while($row3 = mysqli_fetch_assoc($listTablePO)){ //this while loop creates the table of all parts that need ordered and their necessary info
if($i % 2 == 0){
echo "<tr class='odd' style='text-align: center;'>";
} else {
echo "<tr class='even' style='text-align: center;'>";
}
echo "<td>" . $row3['part_name'] . "</td>";
echo "<td>" . $row3['description'] . "</td>";
if($row3['order_link'] == null){
echo "<td>" . $row3['supplier_part_no'] . "</td>";
} else {
echo "<td><a href='" . $row3['order_link'] . "' target='_blank'>" . $row3['supplier_part_no'] . "</a></td>";
}
if($row['order_override'] == 0){
echo "<td>" . $row3['order_qty'] . "</td>";
$qty = $row3['order_qty'];
} else {
echo "<td>" . $row3['order_override'] . "</td>";
$qty = $row3['order_override'];
}
echo "<td>$" . sprintf('%.2lf', $row3['price']) . "</td>";
$total = ($total + ($qty * $row3['price']));
echo "<td>$" . sprintf('%.2lf', $total) . "</td>";
echo "</tr>";
$i++;
}
echo "</tbody></table></div>
<form action='/po-mailing/' method='POST' name='" . $row2['name'] ."PO'>
<input type='hidden' value='" . $row2['name'] . "' name='PO' id='PO'></input>
<button type='submit' class='addbutton' style='margin-top: -20px !important; margin-bottom: 20px;'>Push " . $row2['name'] . " PO</button>
</form>
</div>"; //the above snippet handles creating the appropriate form and submit button. All this needs to do is route to the appropriate page (/po-mailing/) and pass the correct supplier name.
//From there I can get all the necessary info from the SQL database and don't need to pass any other info through the form.
//I suspect this is where my issue lies, but all I need is an individual Push PO button for each supplier that directs to /po-mailing/ and passes the supplier info to the page. The problem here is it is doing it three times...
The next code is basically the same as above but for the RFQ table. Skip this part
// the same code is essentially repeated for RFQ for each supplier with minor format changes (it is also irrelevant as I have only been testing with the PO side)
echo "<div style='display:" . $display['' . $row2['name'] . ''] . " ;'>";
echo "<div class='trackheader' style='border-radius:5px 5px 0px 0px; border: 2px solid #CC3333;'>
<h3 style='color:white !important; margin-left: 10px; vertical-align: middle; display: inline-block;'>" . $row2['name'] . " RFQ</h3>
</div>";
echo "<div class='trackcont2'><table style='width:100% !important;'><tbody style='width:100%; !important'>
<tr style='width:100% !important;'>
<th style='width:16.6%;'><h3 style='color:grey !important;'>ALEX ID</th>
<th style='width:16.6%;'><h3 style='color:grey !important;'>Description</th>
<th style='width:16.6%;'><h3 style='color:grey !important;'>Supplier P/N</th>
<th style='width:16.6%;'><h3 style='color:grey !important;'>Order QTY</th>
<th style='width:16.6%;'><h3 style='color:grey !important;'>Last Price</th>
<th style='width:16.6%;'><h3 style='color:grey !important;'>Estimate</th>
</tr>";
$i = 0;
$listTableRFQ = mysqli_query($conn,"SELECT * FROM `inventory` WHERE (`user` = '" . $user_login . "') AND (`supplier` = '" . $row2['name'] . "') AND (`status` = 'order') AND (`method` = 'RFQ')");
while($row5 = mysqli_fetch_assoc($listTableRFQ)){
if($i % 2 == 0){
echo "<tr class='odd' style='text-align: center;'>";
} else {
echo "<tr class='even' style='text-align: center;'>";
}
echo "<td>" . $row5['part_name'] . "</td>";
echo "<td>" . $row5['description'] . "</td>";
if($row5['order_link'] == null){
echo "<td>" . $row5['supplier_part_no'] . "</td>";
} else {
echo "<td><a href='" . $row5['order_link'] . "' target='_blank'>" . $row5['supplier_part_no'] . "</a></td>";
}
if($row['order_override'] == 0){
echo "<td>" . $row5['order_qty'] . "</td>";
$qty = $row5['order_qty'];
} else {
echo "<td>" . $row5['order_override'] . "</td>";
$qty = $row5['order_override'];
}
echo "<td>$" . sprintf('%.2lf', $row5['price']) . "</td>";
$total = ($total + ($qty * $row5['last_price']));
echo "<td>$" . sprintf('%.2lf', $total) . "</td>";
echo "</tr>";
$i++;
}
echo "</tbody></table></div>
<form action='/rfq-mailing/' method='POST' id='" . $row2['name'] ."RFQ'>
<input type='hidden' value='" . $row2['name'] . "' name='" . $row2['name'] . "' id='" . $row2['name'] . "'></input>
<button type='submit' class='addbutton' style='margin-top: -20px !important; margin-bottom: 20px;'>Push " . $row2['name'] . " RFQ</button>
</form>
</div>";
}
?>
Hopefully someone can spot where I'm screwing up.. FWIW I'm also using Wordpress as a backend for the system (just an easy way to handle accounts, create pages, etc)
I found the solution:
My wordpress theme appears to load the head of each page multiple times, so the issue wasn't with the code itself. On each load it was submitting the info.
Encasing necessary info in if(isset($_POST['submitbuttonexample'])){} fixed the issue.
I'm in a class, and I've been asked to retrieve information from an SQL table and display it as an invoice. I've got the basics down, however I've now been asked to format the PHP page to look something like this.
I'm a little confused as to how to do this or even where to begin for that matter.
PHP:
<?php
require("connect.php");
$inNo = $_POST["inNo"];
$sql = "SELECT invoice.invoice_no, invoice.date, invoice.cust_id, invoice.emp_id, invoice_line.prod_id, invoice_line.qty, product.cost_price, (product.cost_price * invoice_line.qty) FROM invoice INNER JOIN invoice_line ON invoice.invoice_no = invoice_line.invoice_no INNER JOIN product ON invoice_line.prod_id = product.id WHERE cust_id = '" . $inNo . "'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
//open table
echo '<table class="table table-striped" id="outTable">';
echo "<tr><th>Invoice no.</th><th>Date</th><th>Customer ID</th><th>Employee ID</th><th>Product ID</th><th>Qty</th><th>Price</th><th>Total cost</th></tr>";
// output data of each row
while($row = $result->fetch_assoc()) {
echo "
<tr>
<td>" . $row["invoice_no"]. "</td>
<td>" . $row["date"]. "</td><td>" . $row["cust_id"]. "</td>
<td>" . $row["emp_id"]. "</td><td>" . $row["prod_id"]. "</td>
<td>" . $row["qty"]. "</td><td>" . $row["cost_price"]. "</td>
<td>" . $row["(product.cost_price * invoice_line.qty)"]. "</td>
</tr>";
}
} else {
echo "0 results";
}
$conn->close();
?>
Try this:
<?php
require("connect.php");
$inNo = $_POST["inNo"];
$sql = "SELECT invoice.invoice_no, invoice.date, invoice.cust_id, invoice.emp_id, invoice_line.prod_id, invoice_line.qty, product.cost_price, (product.cost_price * invoice_line.qty) FROM invoice INNER JOIN invoice_line ON invoice.invoice_no = invoice_line.invoice_no INNER JOIN product ON invoice_line.prod_id = product.id WHERE cust_id = '" . $inNo . "'";
$result = $conn->query($sql);
echo"<div style='width:50em'>";
if ($result->num_rows > 0) {
$count =0;
while($row = $result->fetch_assoc()) {
if ($count==0){
echo '<h2 style="text-align: center">Invoice no. " . $row["invoice_no"]. "</h2>';
echo '<table width=100%>';
echo "<tr style='text-align: left'><th>Date</th><th>Customer ID</th><th>Employee ID</th></tr>";
echo '<td>" . $row["date"]. "</td><td>" . $row["cust_id"]. "</td>
<td>" . $row["emp_id"]. "</td></table>';
echo '<table class="table table-striped" id="outTable" width=100% style="text-align: left">';
echo '<th>Product ID</th><th>Qty</th><th>Price</th></tr>';
}
echo "
<tr>
<td>" . $row["prod_id"]. "</td>
<td>" . $row["qty"]. "</td><td>" . $row["cost_price"]. "</td>
</tr>";
if ($count==$result->num_rows-1){
echo '<div style="text-align: right">Total cost: " . $row["(product.cost_price * invoice_line.qty)"]. "</div>';
}
$count++;
}
echo "</table></div>";
} else {
echo "0 results";
}
$conn->close();
?>
I'm following along with the example from w3schools to extract some rows from a mysql db and return the results in a table format, but I'm only getting blank rows (although the correct number of them, oddly enough).
Here is what I have in my php script:
<!DOCTYPE html>
<html>
<head>
<style>
table
{
width: 100%;
border-collapse: collapse;
}
table, td, th
{
border: 1px solid black;
padding: 5px;
}
th
{
text-align: left;
}
</style>
</head>
<body>
<?php
$q = $_GET['q'];
$con = mysqli_connect('localhost', 'root', '123', 'drugsatfda');
if (!$con) {die('Could not connect: ' . mysqli_error($con));}
mysqli_select_db($con, "drugsatfda");
$sql="SELECT * FROM products WHERE DrugName LIKE '"."%".$q."%"."'";
$result = mysqli_query($con,$sql);
$count = 0;
echo "<table>
<tr>
<th>Application Number</th>
<th>Product Number</th>
<th>Form</th>
<th>Strength</th>
<th>Reference Drug</th>
<th>Drug Name</th>
<th>Active Ingredient</th>
</tr>";
while($row = mysqli_fetch_array($result, MYSQLI_ASSOC) && $count < 10) {
echo "<tr>";
echo "<td>" . $row['ApplNo'] . "</td>";
echo "<td>" . $row['ProductNo'] . "</td>";
echo "<td>" . $row['Form'] . "</td>";
echo "<td>" . $row['Strength'] . "</td>";
echo "<td>" . $row['ReferenceDrug'] . "</td>";
echo "<td>" . $row['DrugName'] . "</td>";
echo "<td>" . $row['ActiveIngredient'] . "</td>";
echo "</tr>";
$count++;
}
echo "</table>";
mysqli_close($con);
?>
</body>
</html>
Can someone please help me see where I'm going wrong?
while($row = mysqli_fetch_array($result, MYSQLI_ASSOC) && $count < 10) {
When doing this, you get two conditions, so $row = mysqli_fetch_array($result, MYSQLI_ASSOC) just becomes an expression returning a boolean true, so while $count is less than 10, you get while (true && true).
The solution is to break; when the loop reaches 10 instead.
while($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
if ($count >= 10) // If we reach 10 iterations, break the loop
break;
echo "<tr>";
echo "<td>" . $row['ApplNo'] . "</td>";
/* and so on */
echo "</tr>";
$count++;
}
You can verify this by doing
while($row = mysqli_fetch_array($result, MYSQLI_ASSOC) && $count < 10) {
var_dump($row);
}
Which will output bool(true); for each iteration, until there are no more rows to fetch (when mysqli_fetch_array() returns null), or when $count is 10 or greater - whichever comes first.
The easier approach
An alternative, is simply just to fetch 10 rows. You can add a LIMIT clause to your SQL, like
$sql="SELECT * FROM products WHERE DrugName LIKE '%".$q."%' LIMIT 10";
This will fetch only 10 rows, meaning that you can just loop through it normally, without having to count
while($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
echo "<tr>";
echo "<td>" . $row['ApplNo'] . "</td>";
/* and so on */
echo "</tr>";
}
It should also be noted that your code is currently wide open to SQL injections, and you should use prepared statements to guard yourself against this.
References
http://php.net/manual/en/mysqli.prepare.php
How can I prevent SQL injection in PHP?
Please try again...
<!DOCTYPE html>
<html>
<head>
<style>
table
{
width: 100%;
border-collapse: collapse;
}
table, td, th
{
border: 1px solid black;
padding: 5px;
}
th
{
text-align: left;
}
</style>
</head>
<body>
<?php
$q = $_GET['q'];
$con = mysqli_connect('localhost', 'root', '123', 'drugsatfda');
if (!$con) {die('Could not connect: ' . mysqli_error($con));}
mysqli_select_db($con, "drugsatfda");
$sql="SELECT * FROM products WHERE DrugName LIKE '"."%".$q."%"."'";
$result = mysqli_query($con,$sql);
$count = 0;
echo "<table>
<tr>
<th>Application Number</th>
<th>Product Number</th>
<th>Form</th>
<th>Strength</th>
<th>Reference Drug</th>
<th>Drug Name</th>
<th>Active Ingredient</th>
</tr>";
while($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
if($count >=10)
break;
echo "<tr>";
echo "<td>" . $row['ApplNo'] . "</td>";
echo "<td>" . $row['ProductNo'] . "</td>";
echo "<td>" . $row['Form'] . "</td>";
echo "<td>" . $row['Strength'] . "</td>";
echo "<td>" . $row['ReferenceDrug'] . "</td>";
echo "<td>" . $row['DrugName'] . "</td>";
echo "<td>" . $row['ActiveIngredient'] . "</td>";
echo "</tr>";
$count++;
}
echo "</table>";
mysqli_close($con);
?>
</body>
</html>
Basically I have to create a jukebox type chart via mysql and php using xampp.
I've done the basics of setting up the table my referring to mysql database etc. I just don't get how to code the path to the image folder I have created. My Image folder is in htdocs under my folder I created called Jukebox. This is my coding:
<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
border: 1px solid black;
}
</style>
</head>
<body>
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "jukebox";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT * FROM Music";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
echo "<table>
<tr>
<th>Artist</th>
<th>Title</th>
<th>Album</th>
<th>Albumcover</th>
<th>Play</th>
</tr>";
// output data of each row
while($row = $result->fetch_assoc()) {
echo
"<tr>
<td>" . $row["Artist"]. "</td>
<td>" . $row["Title"]. "</td>
<td>" . $row["Album"]. "</td>
<td>" . $row["Albumcover"]
. "</td>
<td>" . $row["Play"] . "</td>
</tr>";
}
echo "</table>";
} else {
echo "0 results";
} ?>
</body>
</html>
This is what my php coding looks like
This is my image folder which i wish to create a path to so that all the album art can come up in the albumcover column
How do I create this path with php and mysql
<style>
.preview
{
width:400px;
border:solid 1px #dedede;
padding:10px;
color:#cc0000;
}
</style>
<?php
// output data of each row
while($row = $result->fetch_assoc()) {
echo
"<tr>
<td>" . $row["Artist"]. "</td>
<td>" . $row["Title"]. "</td>
<td>" . $row["Album"]. "</td>
<td><img class='preview' src='jukebox/img/" . $row["Albumcover"] ."' alt=".$row["Albumcover"]."></td>
<td>" . $row["Play"] . "</td>
</tr>";
}
No need to do anything special. You are working from a base directory of /jukebox/, your images reside in /jukebox/img/. Let's make it work:
<img src=\"/jukebox/img/".$row['Albumcover']."\"/>
Within your loop. Now the album cover will appear as an image in that row.
I have a mysql database that is used by a php script to display data... the problem i have is, at what appears to be random occurrences it misses results and I can't see a pattern to establish why it might be doing it...
all the data appears to be fine when i check the database.
here is my initial search page
<?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>";
?>
and here is my results page
<?
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>");
?>
what I'm getting can be seen here
Are they missing or maybe they are obscured by unescaped html characters. Check the View Source option of your browser to see if they are actually there. I would especially watch for characters in the data like the Less Than character that the browser may be mistaking for an HTML open character.
You may need to escape your output so the browser does not try to render it:
echo ("" . htmlspecialchars($row[2]) . "");
Also, I would suggest you never take input directly from a user and put it into a SQL query without escaping it first. You are opening yourself up for SQL Injection attacks.
See the following:
http://php.net/manual/en/mysqli.real-escape-string.php
Don't know if it'll help but in this line:
$result = mysqli_query($con,"SELECT * FROM offers WHERE tradingCounty ='" . $SelectedCounty . "'ORDER BY categoryIdName ASC;");
it looks like you have an extra semi-colon (;) right before the last double quote. I don't think that should be there.
You could also store everything returned in an array and echo everything as you iterate through it to see what it returns. Then, if something's missing, go to your database and look at that row.
$tempArray = array();
while($row = mysqli_fetch_row($result)) {
$tempArray = $row;
}
foreach($tempArray as $value) {
echo $value . '<br>';
}