Display table vertically - php

I want to display table vertically. Now, It's displaying horizontally. Each
and every field is displaying. How can I display table vertically?
And one more thing I want to add one more function to the button. Current
date added into database when button
submit is clicked. For now this code is making my status 0 and not updating
date in database.
<html>
<head>
<meta name="description" content="website description" />
<meta name="keywords" content="website keywords, website keywords" />
<meta http-equiv="content-type" content="text/html; charset=windows-
1252" />
<link rel="stylesheet" type="text/css" href="style/style.css" />
<style>
<table>
{
border-style:solid;
border-width:2px;
border-color:pink;
}
</style>
</head>
<?php
include 'inc/head.php';
include 'connection.php';
$id = $_GET['id'];
$sql = "SELECT * FROM user WHERE id='$id'";
$query = mysqli_query($conn, $sql);
echo "<table border='6'>
<tr>
<th>Application Type</th> <br>
<th>First name</th><br>
<th>Sur name</th><br>
<th>title</th>
<th>Date of Birth</th>
<th>Gender</th>
<th>Nationality</th>
<th>Country of Birth</th>
<th>Applicant's Location</th>
<th>alias</th>
<th>Criminal </th>
<th>Country of passport</th>
<th>Passport number</th>
<th>Passport issue date </th>
<th>Passport expiry date</th>
<th>Address </th>
<th>City</th>
<th>State</th>
<th>Postal Code</th>
<th>Country</th>
<th>Email Address</th>
<th>Home Number</th>
<th>Business Number</th>
<th>mobile</th>
</tr>";
while($row = mysqli_fetch_assoc($query)) {
echo "<tr>";
echo " <td>" . $row['applicationtype'] . "</td>";
echo " <td>" . $row['firstname'] . "</td>";
echo " <td>" . $row['lastname'] . "</td>";
echo " <td>" . $row['title1'] . "</td>";
echo " <td>" . $row['dob'] . "</td>";
echo " <td>" . $row['gender'] . "</td>";
echo " <td>" . $row['nationality'] . "</td>";
echo " <td>" . $row['countryofbirth'] . "</td>";
echo " <td>" . $row['applicantlocation'] . "</td>";
echo " <td>" . $row['alias'] . "</td>";
echo " <td>" . $row['criminal'] . "</td>";
echo " <td>" . $row['countryofpassport'] . "</td>";
echo " <td>" . $row['passportnumber'] . "</td>";
echo " <td>" . $row['pid'] . "</td>";
echo " <td>" . $row['ped'] . "</td>";
echo " <td>" . $row['address'] . "</td>";
echo " <td>" . $row['city'] . "</td>";
echo " <td>" . $row['state'] . "</td>";
echo " <td>" . $row['postalcode'] . "</td>";
echo " <td>" . $row['country'] . "</td>";
echo " <td>" . $row['email'] . "</td>";
echo " <td>" . $row['homephone'] . "</td>";
echo " <td>" . $row['businessphone'] . "</td>";
echo " <td>" . $row['mobile'] . "</td>";
echo "</tr>";
}
echo "</table><br><br>";
if(isset($_POST['submit'])) {
echo $radio = $_POST['radio'];
$date_clicked = date('Y-m-d H:i:s');
$sql = "UPDATE user SET visastatus='$radio' AND currentdate='$date_clicked' WHERE id='$id'";
$query = mysqli_query($conn, $sql);
if($query) {
echo "<h4 style='color:green'>Action Performed Successfully....</h4>";
} else {
echo "<h4 style='color:red'>Failed.</h4>";
}
}
?>
<form method="POST" action="" enctype="multipart/form-data">
<div class="col-xs-12 col-sm-6 col-md-6 col-lg-6" style="margin-top:
8px;">
<label class="checkbox-inline tourist-rad">
<input type="radio" name="radio" id="success"
value="Successfull">Successfull
</label>
<label class="checkbox-inline tourist-rad">
<input type="radio" name="radio" id="decline" value="Declined">Declined
</label>
</div>
<div class="form-group">
<button type="submit" name="submit" value="submit" class="btn btn-
primary" style="float: right;">Update Menu Item</button>
</div>
</body>
</html>

How can I display the table vertically?
Put each heading in a new <tr>. Remember, <tr> stands for table row, while <td> is for each of the elements in that row. This will require some modification of your php code so that you can essentially print a new row, and each td within it.
Edit: To display it vertically as you like, you'd need to modify your existing while loop.
//Print the row
echo "<tr>";
//Print the row heading
<th>Application Type</th>
while($row = mysqli_fetch_assoc($query)) {
//Print each matching data type inside
echo " <td>" . $row['applicationtype'] . "</td>";
}
//Close the row
echo "</tr>";
You'll need to do this functionality for each of the headings you have. You could also use arrays along with nested loops to print all the data cleanly and easily without excess code.

If by "vertically" you mean you want to have 2 columns and 24 rows instead of 24 columns and 2 rows, this will do it for you:
echo "<table border='6'>";
while($row = mysqli_fetch_assoc($query)) {
echo "<tr><th>Application Type</th><td>{$row['applicationtype']}</td></tr>";
echo "<tr><th>First Name</th><td>{$row['firstname']}</td></tr>";
echo "<tr><th>Surname</th><td>{$row['lastname']}</td></tr>";
echo "<tr><th>Title</th><td>{$row['title1']}</td></tr>";
echo "<tr><th>Date of Birth</th><td>{$row['dob']}</td></tr>";
echo "<tr><th>Gender</th><td>{$row['gender']}</td></tr>";
echo "<tr><th>Nationality</th><td>{$row['nationality']}</td></tr>";
echo "<tr><th>Country of Birth</th><td>{$row['countryofbirth']}</td></tr>";
echo "<tr><th>Applicant's Location</th><td>{$row['applicantlocation']}</td></tr>";
echo "<tr><th>Alias</th><td>{$row['alias']}</td></tr>";
echo "<tr><th>Criminal</th><td>{$row['criminal']}</td></tr>";
echo "<tr><th>Country of Passport</th><td>{$row['countryofpassport']}</td></tr>";
echo "<tr><th>Passport Number</th><td>{$row['passportnumber']}</td></tr>";
echo "<tr><th>Passport Issue Date</th><td>{$row['pid']}</td></tr>";
echo "<tr><th>Passport Expiry Date</th><td>{$row['ped']}</td></tr>";
echo "<tr><th>Address</th><td>{$row['address']}</td></tr>";
echo "<tr><th>City</th><td>{$row['city']}</td></tr>";
echo "<tr><th>State</th><td>{$row['state']}</td></tr>";
echo "<tr><th>Postal Code</th><td>{$row['postalcode']}</td></tr>";
echo "<tr><th>Country</th><td>{$row['country']}</td></tr>";
echo "<tr><th>Email Address</th><td>{$row['email']}</td></tr>";
echo "<tr><th>Home Number</th><td>{$row['homephone']}</td></tr>";
echo "<tr><th>Business Number</th><td>{$row['businessphone']}</td></tr>";
echo "<tr><th>Mobile</th><td>{$row['mobile']}</td></tr>";
}
echo "</table>";
Additionally, if you are going to be handling such sensitive personal data, you MUST improve your query security starting with mysqli prepared statements using placeholders.

Related

Update the php after deleting in database

This is The main Page where the user_list.php gets $txt to query "where Like".
<?php
include_once('dbConfig.php');
$result = mysqli_query($conn,"SELECT * FROM compid");
<title>Computer Record</title>
</head>
<body><thead>
<tr>
<th id='time'> </th>
<th>Computer ID</th>
<th id='time'>ComputerName</th>
<th id='title'>Status</th>
<th id='cost'>IP</th>
<th id='size'>OS</th>
<th id='author'>RAM</th>
<th id='author'>CPU</th>
<th id='author'>Machine Model</th>
<th id='author'>Serial Number</th>
<th id='author' >Remarks</th>
<th id='author'>Application</th>
<th id='author'>User</th>
<th id='author'>Delete</th>
<th id='author'>Edit</th>
</tr></thead>
";
while($row = mysqli_fetch_array($result))
{
echo"<tbody>";
echo "<td><input type='checkbox' name='Days[]' value=". $row['cid'] ."> </td>";
echo "<td>" . $row['cid'] . "</td>";
echo "<td>" . $row['cname'] . "</td>";
echo "<td>" . $row['stat'] . "</td>";
echo "<td>" . $row['ip'] . "</td>";
echo "<td>" . $row['os'] . "</td>";
echo "<td>" . $row['ram'] . "</td>";
echo "<td>" . $row['cpu'] . "</td>";
echo "<td>" . $row['mmodel'] . "</td>";
echo "<td>" . $row['snumber'] . "</td>";
echo " <td>" . $row['remarks'] . "</td>";
echo "<td ><a href='App_List.php?cname=" . $row['cname'] . "'><img src='http://10.9.57.129:8888/SGSComputer5.3/FINAL/images/view.png' style='border-style: none'></a></td>";
echo "<td><a href='User_List.php?cname=" . $row['cname'] . "'><img src='http://10.9.57.129:8888/SGSComputer5.3/FINAL/images/user_group.png' style='border-style: none'></a></td>";
echo "<td><a href='del_Main.php?ID=" . $row['ID'] . "' onclick='return checkDelete()'><img src='http://10.9.57.129:8888/SGSComputer5.3/FINAL/images/erase.png' style='border-style: none'></a></td>";
echo "<td><a href='Edit_Main.php?ID=" . $row['ID'] . "'><img src='http://10.9.57.129:8888/SGSComputer5.3/FINAL/images/edit.png' style='border-style: none'></a></td>";
}
echo "</table>";?>
?>
This is User_List.php
if(isset($_GET['cname'])) {
$txt= $_GET['cname'];
$result = mysqli_query($con,"SELECT * FROM user Where cname like '$txt'");
echo"<body bgcolor='#696969'>
<input type='submit' value='Export' method='post'>
</head>";
echo "<table border='1'>
<tr>
<th>Users</th>
<th> </th>
</tr>";
while($row = mysqli_fetch_array($result))
{
$one = $row['cname'];
echo "<tr>";
echo "<td>" . $row['user'] . "</td>";
echo "<td><a href='User_List.php?ID=" . $row['ID'] . "' onclick='return checkDelete()'><img src='http://10.9.57.129:8888/SGSComputer5.3/FINAL/images/erase.png' style='border-style: none'></a></td>"; echo "</tr>";
echo "</tr>";
}
echo "</table>";
This is my delete button in table how can i update the page this is the delete.php:
if(isset($_GET['ID'])) {
$result = mysqli_query($conn,"DELETE FROM `SGSCOMP`.`user` WHERE `user`.`ID` = ".$_GET["ID"]);
}
How to get back to the User List
You can do a header redirect directly after the update-query in your delete.php.
header("location:User_List.php")
This will redirect the user back to User_List.php.
header() is used to send a raw HTTP header. See the ยป HTTP/1.1 specification for more information on HTTP headers.
To go back to User_List.php, you can simply use header(). This will redirect users after running mysqli_query.
You should check if the row was deleted successfully by using mysqli_affected_rows(). This will return the number of rows affected, ie if 1 row was deleted, it will return 1.
if(isset($_GET['ID'])) {
$result = mysqli_query($conn,"DELETE FROM `SGSCOMP`.`user` WHERE `user`.`ID` = ".$_GET["ID"]);
if (mysqli_affected_rows($conn) > 0) {
header("Location:User_List.php");
exit;
} else {
// row was not deleted successfully
}
}
More information on header() at http://www.w3schools.com/php/func_http_header.asp.
For User_Main.php, it should be:
You cannot put <?php tags inside of <?php tags.
<?php
include_once('dbConfig.php');
$result = mysqli_query($conn,"SELECT * FROM compid");
?>
<title>Computer Record</title>
</head>
<body><thead>
<tr>
<th id='time'> </th>
<th>Computer ID</th>
<th id='time'>ComputerName</th>
<th id='title'>Status</th>
<th id='cost'>IP</th>
<th id='size'>OS</th>
<th id='author'>RAM</th>
<th id='author'>CPU</th>
<th id='author'>Machine Model</th>
<th id='author'>Serial Number</th>
<th id='author' >Remarks</th>
<th id='author'>Application</th>
<th id='author'>User</th>
<th id='author'>Delete</th>
<th id='author'>Edit</th>
</tr></thead>
<?php
while($row = mysqli_fetch_array($result))
{
echo"<tbody>";
echo "<td><input type='checkbox' name='Days[]' value=". $row['cid'] ."> </td>";
echo "<td>" . $row['cid'] . "</td>";
echo "<td>" . $row['cname'] . "</td>";
echo "<td>" . $row['stat'] . "</td>";
echo "<td>" . $row['ip'] . "</td>";
echo "<td>" . $row['os'] . "</td>";
echo "<td>" . $row['ram'] . "</td>";
echo "<td>" . $row['cpu'] . "</td>";
echo "<td>" . $row['mmodel'] . "</td>";
echo "<td>" . $row['snumber'] . "</td>";
echo " <td>" . $row['remarks'] . "</td>";
echo "<td ><a href='App_List.php?cname=" . $row['cname'] . "'><img src='http://10.9.57.129:8888/SGSComputer5.3/FINAL/images/view.png' style='border-style: none'></a></td>";
echo "<td><a href='User_List.php?cname=" . $row['cname'] . "'><img src='http://10.9.57.129:8888/SGSComputer5.3/FINAL/images/user_group.png' style='border-style: none'></a></td>";
echo "<td><a href='del_Main.php?ID=" . $row['ID'] . "' onclick='return checkDelete()'><img src='http://10.9.57.129:8888/SGSComputer5.3/FINAL/images/erase.png' style='border-style: none'></a></td>";
echo "<td><a href='Edit_Main.php?ID=" . $row['ID'] . "'><img src='http://10.9.57.129:8888/SGSComputer5.3/FINAL/images/edit.png' style='border-style: none'></a></td>";
}
echo "</table>";
?>
For User_List.php
You didn't close if(isset($_GET['cname'])) {, with another curly bracket.
For delete.php, it should be:
There's no need to concat the string as it's reductant.
if(isset($_GET['ID'])) {
$result = mysqli_query($conn, "DELETE FROM `SGSCOMPuser` WHERE `userID` = '$_GET["ID"]');
}

PHP connection to a database (no output!)

I wrote a code to connect a html page to the database, but it does not search for all employees in the table. I'm not sure why the code seems to be correct. It does not give any error or warning.
Can anyone explain to me what is wrong?
<div>
<form id='searchform' action='index.php' method='get'>
<a href='index.php'>All employees</a> ---
Search by a last name:
<input id='search' name='search' type='text' size='20' value='<?php echo #$_GET['search']; ?>' />
<input id='submit' type='submit' value='Go!' />
</form>
</div>
<?php
// check if search view of list view
if (isset($_GET['search'])) {
$sql = "SELECT * FROM Employee WHERE LastName like '%" . #$_GET['search'] . "%'";
} else {
$sql = "SELECT * FROM Employee";
}
// execute sql statement
$stmt = oci_parse($conn, $sql);
oci_execute($stmt);
?>
<table style='border: 1px solid #DDDDDD'>
<thead>
<tr>
<th>Personal Number</th>
<th>Insurance Number</th>
<th>First Name</th>
<th>Last Name</th>
<th>Birth Date</th>
<th>Gender</th>
<th>Hire Date</th>
<th>Salary</th>
<th>Office ID</th>
</tr>
</thead>
<tbody>
<?php
// fetch rows of the executed sql query
while ($row = oci_fetch_assoc($stmt)) {
echo "<tr>";
echo "<td>" . $row['PersonalNumber'] . "</td>";
echo "<td>" . $row['InsuranceNumber'] . "</td>";
echo "<td>" . $row['FirstName'] . " " . $row['LastName'] . "</td>";
echo "<td>born on " . $row['BirthDate'] . "</td>";
echo "<td>" . $row['Gender'] . "</td>";
echo "<td>hired on " . $row['HireDate'] . "</td>";
echo "<td>" . $row['Salary'] . "</td>";
echo "<td>" . $row['OfficeID'] . "</td>";
echo "</tr>";
}
?>
</tbody>
</table>
<div>There are found <?php echo oci_num_rows($stmt); ?> employees!</div>
<?php oci_free_statement($stmt); ?>
</body>

Multiple delete through checkout

I am stuck in one of my application module. I have to set multiple delete options in my application.
I have used the below code. The designing is perfectly fine. All what I want to add multiple delete options in it.
Below is the code which I have tried out:
<html>
<head>
<title>Strad Hosting Limited -Web Hosting</title>
<script language="javascript">
function validate()
{
var chks = document.getElementsByName('checkbox[]');
var hasChecked = false;
for (var i = 0; i < chks.length; i++)
{
if (chks[i].checked)
{
hasChecked = true;
break;
}
}
if (hasChecked == false)
{
alert("Please select at least one.");
return false;
}
return true;
}
</script>
</head>
<body >
<?php
$con=mysqli_connect("localhost","stradsol","D#v,b5TnQ!D!","stradsol_sales");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM Persons");
echo "<form name='form1' method='post' action='' onSubmit='return validate();'>";
echo "<table border='1' style='
background-color: white;'>
<tr>
<th></th>
<th>id</th>
<th style='padding-left: 11px;'>Lead Generated Date </th>
<th>name</th>
<th>email</th>
<th>contacts</th>
<th>requirement</th>
<th style='display:none;'>Company name</th>
<th style='display:none;'>Address</th>
<th>Next Follow-Up date</th>
<th>Final_Details</th>
<th style='display:none;'>Status</th>
<th style='padding-left: 12px; display:none;'>Lead Closed Date</th>
<th>EDIT</th>
<th>Follow-up History</th>
<th>Add Follow-up</th>
<th>Delete Record</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td><input name='checkbox[]' type='checkbox' id='checkbox[]' value='".$rows['id']."'></td>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['date'] . "</td>";
echo "<td><a href='config_info.php?id=" . $row['id'] . "'>".$row['name']."</a></td>";
echo "<td>" . $row['email'] . "</td>";
echo "<td>" . $row['contacts'] . "</td>";
echo "<td>" . $row['requirement'] . "</td>";
echo "<td style='display:none;'>" . $row['company_name'] . "</td>";
echo "<td style='display:none;'>" . $row['address'] . "</td>";
echo "<td>" . $row['startdate'] . "</td>";
echo "<td>" . $row['final_details'] . "</td>";
echo "<td style='display:none;'>" . $row['status'] . "</td>";
echo "<td style='display:none;'>" . $row['lead_close'] . "</td>";
echo "<td><a href='edit_eg1.php?id=" . $row['id'] . "'>Edit</a></td>";
echo "<td><a href='Follow_history.php?id=" . $row['id'] . "'>Follow_history</a></td>";
echo "<td><a href='add_follow.php?id=" . $row['id'] . "'>Followup</a></td>";
echo "<td><a href='delete.php?id=" . $row['id'] . "'>Delete</a></td>";
echo "</tr>";
}
echo "<tr><td><input name='delete' type='submit' id='delete' value='Delete'></td></tr>";
$count=mysqli_num_rows($result);
if(isset($_POST['delete'])){
for($i=0;$i<count($_POST['checkbox']);$i++){
$del_id=$_POST['checkbox'][$i];
$sql = "DELETE FROM Persons WHERE id='$del_id'";
echo $sql;
$result2 = mysqli_query($con,$sql);
}
// if successful redirect to delete_multiple.php
if($result2)
{
echo "<meta http-equiv=\"refresh\" content=\"0;URL=edit_table_del.php\">";
}
}
mysqli_close($con);
echo "</table>";
echo "</form>";
?>
<br><br>
[ Back To Home ]
</body>
</html>
I am stuck, the query is not working I think. I don't know what I am missing.
Try replacing
$sql = "DELETE FROM Persons WHERE id='$del_id'";
With
$sql = "DELETE FROM Persons WHERE id=$del_id";
I'm assuming the ID is a number so the single quotes aren't needed.

PHP, MYSQL, HTML table with tablesorter

Trying to add tablesorter added to a page I am creating. I know very little of jquery, so I'm guessing that's where my fault is. I've added the required code in the <head> area of my page, and made the necessary changes to my table. My table still renders as it would with just HTML. Ideas?
<html>
<head>
<title>Inventory</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<script type="text/javascript" src="http://tablesorter.com/__jquery.tablesorter.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){ $("table").tablesorter(); });
</script>
</head>
<body>
<?php
$con=mysqli_connect("localhost","user","pass","db_name");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$query = "SELECT
products.name,
products.sku,
inventory.quantityfry,
inventory.quantityjuv,
inventory.quantityadult,
inventory.notes,
inventory.location,
inventory.owner
FROM
products
INNER JOIN
inventory
ON
products.sku=inventory.sku";
$result = mysqli_query($con,$query) or die(mysqli_error($con));
echo "<table border='1' id='table' class='tablesorter'>
<thead>
<tr>
<th>Species</th>
<th>SKU</th>
<th>Fry Count</th>
<th>Juvie Count</th>
<th>Adult Count</th>
<th>Notes</th>
<th>Location</th>
<th>Owner</th>
</tr>
</thead>";
while ($row = mysqli_fetch_assoc($result)) {
echo "<tbody>";
echo "<tr>";
echo "<td>" . $row['name'] . "</td>";
echo "<td>" . $row['sku'] . "</td>";
echo "<td>" . $row['quantityfry'] . "</td>";
echo "<td>" . $row['quantityjuv'] . "</td>";
echo "<td>" . $row['quantityadult'] . "</td>";
echo "<td>" . $row['notes'] . "</td>";
echo "<td>" . $row['location'] . "</td>";
echo "<td>" . $row['owner'] . "</td>";
echo "</tr>";
echo "</tbody>";
}
mysqli_free_result($result);
echo "</table>";
mysqli_close($con);
?>
</body>
</html>
Thanks!
Three things:
Don't link directly to tablesorter at tablesorter.com - make a copy to your own server, or use a copy at a CDN (this is of my fork of tablesorter at cdnjs.com).
Include a <!DOCTYPE html> at the top of your HTML otherwise IE will change into quirks mode and pretty much make your site look bad.
As #MikeB mentioned, the above code wraps every row in a tbody, correct the code as follows (this is just a snippet):
echo "<table border='1' id='table' class='tablesorter'>
<thead>
<tr>
<th>Species</th>
<th>SKU</th>
<th>Fry Count</th>
<th>Juvie Count</th>
<th>Adult Count</th>
<th>Notes</th>
<th>Location</th>
<th>Owner</th>
</tr>
</thead><tbody>";
while ($row = mysqli_fetch_assoc($result)) {
echo "<tr>";
echo "<td>" . $row['name'] . "</td>";
echo "<td>" . $row['sku'] . "</td>";
echo "<td>" . $row['quantityfry'] . "</td>";
echo "<td>" . $row['quantityjuv'] . "</td>";
echo "<td>" . $row['quantityadult'] . "</td>";
echo "<td>" . $row['notes'] . "</td>";
echo "<td>" . $row['location'] . "</td>";
echo "<td>" . $row['owner'] . "</td>";
echo "</tr>";
}
mysqli_free_result($result);
echo "</tbody></table>";

Hiding a table if a search result does not exist

Exactly what the title says. I want the table containing all of the search queries to be hidden, but I've tried a lot of things and none of them work. For example, if($myData!=null) {proceed with showing the table}, but that didn't work. isset() also didn't work. Any ideas?
<style>
ul
{
list-style-type: none;
}
</style>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Search Chemicals</title>
</head>
<p>
<body>
<h3>Chemical Information</h3>
<p>You may search by Catalog number, CASRN, or the chemical name.</p>
<form method="post" action="search.php?go" id="searchform">
<input type="text" name="name">
<input type="submit" name="submit" value="Search">
</form>
<?php
error_reporting(0);
if (isset($_POST['submit'])) {
if (isset($_GET['go'])) {
if (preg_match("/^[a-zA-Z0-9]+/", $_POST['name'])) {
$name = $_POST['name'];
$conn = mysql_connect("localhost", "Blimeo", "password");
$db = mysql_connect("localhost", "-", "-") or die('I cannot connect to the database because: ' . mysql_error());
//-select the database to use
$mydb = mysql_select_db("chemicals");
//-query the database table
$sql = "SELECT * FROM products WHERE Catalog LIKE '%" . $name . "%' OR CASRN LIKE '%" . $name . "%' OR Chemical_Name LIKE '%" . $name . "%'";
$myData = mysql_query($sql, $conn);
echo "<table border=1>
<tr>
<th>Catalog</th>
<th>Image</th>
<th>CASRN</th>
<th>Chemical Name</th>
<th>Quantity 1</th>
<th>Price 1</th>
<th>Quantity 2</th>
<th>Price 2</th>
<th>Quantity 3</th>
<th>Price 3</th>
<th>Quantity 4</th>
<th>Price 4</th>
</tr>";
while ($record = mysql_fetch_array($myData)) {
echo "<tr>";
echo "<td>" . $record['Catalog'] . "</td>";
echo "<td><img src=\"./img/" . $record['Image'] . "\" alt=\"Chemical\"/></td>";
echo "<td>" . $record['CASRN'] . "</td>";
echo "<td>" . $record['Chemical_Name'] . "</td>";
echo "<td>" . $record['Quantity1'] . "</td>";
echo "<td>" . $record['Price1'] . "</td>";
echo "<td>" . $record['Quantity2'] . "</td>";
echo "<td>" . $record['Price2'] . "</td>";
echo "<td>" . $record['Quantity3'] . "</td>";
echo "<td>" . $record['Price3'] . "</td>";
echo "<td>" . $record['Quantity4'] . "</td>";
echo "<td>" . $record['Price4'] . "</td>";
echo "</tr>";
echo "</form>";
echo "<ul>\n";
echo "<li>" . "" . $Catalog . " " . $CASRN . " " . $Chemical_Name . "</li>\n";
echo "</ul>";
}
}
} else {
echo "<p>Product not found! Please rephrase your search criteria.</p>";
}
}
?>
</body>
</html>
</p>
You should add mysql_num_rows();
$myData = mysql_query($sql, $conn);
$exists = mysql_num_rows($myData);
if($exists) {
echo "<table border=1>";
//..................
echo "</table>";
} else {
echo "<p>Product not found! Please rephrase your search criteria.</p>";
}
Well, it seems you are echoing out your table regardless of the results of the search query. You should probably check the number of rows returned in teh result set and only echo out the table if the count is > 0.
Use <div visibility="hidden"> to hide the table and use Javascript to change the visibility based on the search queries or some other condition.

Categories