I have a page that shows the responses from my form (in a webpage). At the moment, all the responses sit on one page, one after the other. I would like the page to show a list of all the dates submitted (date_submitted) and ID number and when that is clicked it takes us to a page with that particular response (i.e. the full response). How do I create a link that will take it to this record?
This is my code for that page:
<?php error_reporting(E_ALL); ?>
<head>
<link rel="stylesheet" type="text/css" href="surveystyle.css" media="all" />
</head>
<body>
<div id="container2">
<div class="logo-header"><img src="images/logo.jpg" alt="" width="205" height="119" /></div>
<h2> Guest Questionnaire Responses </h2>
<?php
try {
$handler = new PDO('mysql:host=localhost;dbname=***', '***', '***');
$handler->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch(PDOException $e) {
echo $e->getMessage();
die();
}
class guestquestionnaireEntry
{
public $id, $date_submitted, $choice, $expectations, $res, $res_information, $res_staff, $further_comments1,
$entry;
public function __construct()
{
$this->entry = "ID
<tr style='text-align: left; font:arial;'><td><h3>Date Submitted: {$this->date_submitted}</h3></td></tr>
<BR>
<table border='1' align='center'>
<tr style='background: #566890; font-size: 8pt; font-weight: bold; color: #fff;'>
<td colspan='3'>Prior to Arrival</td>
</tr>
<tr style='font-size: 8pt;'>
<td width='60%'>What made you choose us for your recent stay? </td>
<td width='40%' colspan='2'>{$this->choice}</td>
</tr>
<tr style='font-size: 8pt;'>
<td>Did our hotel meet your expectations as advertised? If no, please state why: </td>
<td width='40%' colspan='2'>{$this->expectations}</td>
</tr>
<tr style='background: #566890; font-size: 8pt; font-weight: bold; color: #fff;'>
<td colspan='3'>Making your Reservation</td>
</tr>
<BR>
<tr style='font-size: 8pt;'>
<td>Ease of making your reservation: </td>
<td width='40%'>$img</td>
<td width='5%'>{$this->res}</td>
</tr>
<BR>
<tr style='font-size: 8pt;'>
<td>Hotel information offered: </td>
<td width='40%'>$img2</td>
<td width='5%'>{$this->res_information}</td>
</tr>
<BR>
<tr style='font-size: 8pt;'>
<td>Warmth and friendliness of staff: </td>
<td width='40%'>$img3</td>
<td width='5%'>{$this->res_staff}</td>
</tr>
<BR>
<tr style='font-size: 8pt;'>
<td colspan='3'>Further Comments: </BR></BR>{$this->further_comments1}</td>
</tr>
<BR>
</table>";
}
}
// Checks if the submitted is a number. If so, isolates the ID and adds "where" clause
$id = (!empty($_GET['ID']) && is_numeric($_GET['ID']))? " where ID = '".$_GET['ID']."'" : "";
// Add the $id to the end of the string
// A single call would be SELECT * FROM guestquestionnaire where ID = '1'
$query = $handler->query("SELECT * FROM guestquestionnaire{$id}");
$query->setFetchMode(PDO::FETCH_CLASS, 'guestquestionnaireEntry');
while($r = $query->fetch()) {
echo $r->entry, '<br>';
}
?>
</div>
</body>
You need to do a where in your sql:
HTML Button:
<!-- Use whatever here to click on that triggers the ID reload -->
ID
SQL Query:
// Checks if the submitted is a number. If so, isolates the ID and adds "where" clause
$id = (!empty($_GET['ID']) && is_numeric($_GET['ID']))? " where ID = '".$_GET['ID']."'" : "";
// Add the $id to the end of the string
// A single call would be SELECT * FROM guestquestionnaire where ID = '1'
$query = $handler->query("SELECT * FROM guestquestionnaire{$id}");
$query->setFetchMode(PDO::FETCH_CLASS, 'guestquestionnaireEntry');
EDIT:
// Should be something like this
public function __construct()
{
$this->entry = "
ID...etc.
Related
I'm trying to sort the data table via date picker range (server side) but can't get the date sorting part to work properly. Surely there are missing codes and other problems.
What am I missing?
<html lang="en">
<head>
<title>List</title>
<script src="jquery-3.3.1.min.js"></script>
</head>
<body>
<h1 align="center">List</h1>
</br>
</br>
</br>
<center> <p class="search_input">
<form method="post" action="#">
<input type="date" name="dateFrom"> <input type="date" name="dateTo">
<input type="submit" name="range" id="range" class="btn-info" />
</form>
</center>
<table align="center" cellspacing="0" cellpadding="0">
<thead class="fixedthead">
<th width="120px" style="text-align: center; color: navy">Name</th>
<th width="120px" style="text-align: center; color: navy">Description</th>
<th width="120px" style="text-align: center; color: navy">Date</th>
<th width="120px" style="text-align: center; color: navy">Open</th>
</thead>
<?php
//retrieve content via data picker range
$dateFrom = $_POST['dateFrom'];
$dateTo = $_POST['dateTo'];
$conn = mysqli_connect("localhost", "root", "", "order");
// get results from database
$result = mysqli_query($conn, "SELECT * FROM order.item WHERE date BETWEEN '$dateFrom' AND '$dateTo' ", MYSQLI_USE_RESULT)
or die(mysqli_error($conn));
while($row = mysqli_fetch_array( $result )) {
?>
<tbody>
<tr>
<td width="120px" style="text-align: center"><?php echo $row['name']; ?></td>
<td width="120px" style="text-align: center"><?php echo $row['description']; ?></td>
<td width="120px" style="text-align: center"><?php echo $row['date']; ?></td>
<td width="120px"><a href = "download.php?id=<?php echo $row['id']; ?>" style='text-decoration:none;'><button>View</button></a></td>
</tr>
</tbody>
</table><br><br><br>
<?php
}
?>
</body>
</html>
Any help is appreciated. Thanks guys!
Knowing nothing about your database...
$last_five_days = time() - 432000;
$sql = "SELECT * FROM order.item WHERE order.date > ".$last_five_days." ORDER BY order.date ASC";
If this answer doesn't help, then you need to provide us with more information about what you mean by "date picker range."
ORDER BY {column} ASC|DESC orders the rows by the indicated column. It defaults to ASC.
I'm using the WHERE clause to set up your last-five-days requirement. I'm assuming order.date (whatever you've actually named that) is storing a simple UNIX timestamp.
I am pretty much at the beginner's level for PHP and cURL.
The issue is related to a php CronJob Script which fetches data from a phpmyadmin database relating to customer orders with a particular status (say "0", which means SMS not sent/or No Update Sent to Customer) and updating the shipping details.
Before adding the code to send SMS via API from my SMS Service Provider, the script was working fine which was being used to send emails, regarding shipping updates and following that, updating the database like Order Status and other necessary details to the customer as well as in the system.
The issue arises that if, suppose 100-150 results are fetched as
arrays with status='0' the loop only executes once and stops, whereas
before adding the SMS code, it used to run for n number rows
fetched with status='0'.
I've tried almost all the methods listed on StackOverflow, PHP Manuals, W3C as well as from the developer but still I'm unable to make it work successfully for all the results fetched.
Things I wan't -
1. Select data from a table where status='0'. **✓
2. Get details relating to the order using mysqli_fetch_array.✓
3. Send Email as per the format in the code.✓
4. Update Order History and Order Status.✓
5. Send an SMS using API as per the prescribed template. (⍻ Not Working)**
<?php
$con=mysqli_connect("localhost","admin","pass","database");//database connection
$get_email_contents = "SELECT * FROM `oc_shipping` WHERE `status`='0'";
date_default_timezone_set("Asia/Kolkata");
$date = date('Y-m-d');
if($data = mysqli_query($con,$get_email_contents))
{
while ($row=mysqli_fetch_array($data))
{
$order_id = $row['order_id'];
$tracking_no = $row['tracking_awb'];
$get_email = "SELECT * FROM `oc_order` WHERE `order_id`='$order_id'";
if($email_data = mysqli_query($con,$get_email))
{
while ($email_row=mysqli_fetch_array($email_data))
{
$email = str_replace(" ","",$email_row['email']);
$firstname = ucwords($email_row['firstname']);
$lastname = ucwords($email_row['lastname']);
$received_on = $email_row['date_added'];
$date_added = date("d M Y",strtotime($received_on));
$address_1 = $email_row['shipping_address_1'];
$address_2 = $email_row['shipping_address_2'];
$city = $email_row['shipping_city'];
$pincode = $email_row['shipping_postcode'];
$total = str_replace(".0000","",$email_row['total']);
$mobile = $email_row['telephone'];
$delivery_date = date('d-M-Y', strtotime($date. ' + 7 days'));
$track_url = "https://track.delhivery.com/p/".$tracking_no;
$text = "ABC.com
Hi ".$firstname.", Your Order ".$order_id." has been shipped via XYZ AWB #".$tracking_no.", which can be tracked on ".$track_url."
Expected delivery date is ".$delivery_date.". Please keep ready Rs.".$total."/- on the date of delivery.
Thank you for shopping on ABC.com";
echo "SMS Sent : ".$text."<br><br>";
$encode= rawurlencode($text);
//Just for my reference
$url= "login.smshub.com/api/mt/SendSMS?APIKey=****&senderid=ABCABC&channel=2&DCS=0&Route=1&Flashsms=0&Number=$mobile&Text=$encode";
$ch = curl_init("login.smshub.com/api/mt/SendSMS?APIKey=****&senderid=ABCABC&channel=2&DCS=0&Route=1&Flashsms=0&Number=$mobile&Text=$encode");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,"");
curl_setopt($ch, CURLOPT_RETURNTRANSFER,TRUE);
$data = curl_exec($ch);
$json = json_decode($data);
$JobID = $json->{'JobId'};
$Error = $json->{'ErrorMessage'};
echo "Status : <strong>$JobID $Error </strong><br>";
//Email Receiver//
$to = "$email";
//From Header//
$header = "From: ABC.com<shipping#example.com>"."\r\n";
$header .= "MIME-Version: 1.0" . "\r\n";
$header .= "Content-type:text/html; charset=ISO-8859-1" . "\r\n";
// Subject //
$subject = "Your Order #$order_id has been Shipped";
// Message //
$message = "<html>
<head>
<title></title>
<link href='https://fonts.googleapis.com/css?family=Pacifico|Varela+Round' rel='stylesheet' />
</head>
<body>
<table align='center' cellpadding='1' style='background-color:#ffffff; border-color:#f3f3f3; border-radius:10px; border-size:1px; border-style:outset; max-width: 100%; width:100%; font-family: Helvetica,Arial,sans-serif; '>
<tbody>
<tr>
<td colspan='2' style='text-align:center'>
<p style='text-align:center'><a href='example.com' target='_blank'><img alt='abc.com' height='63' src='example.com/image/shipping/Logo.gif' width='250' /></a></p>
</td>
</tr>
<tr>
<td style='border-color:#f3f3f3; text-align:center; white-space:nowrap; width:50%'>
<p>Thank you for shopping on abc</p>
<h3 style='text-align:left;margin-left: 40px;'>Order Details</h3>
<table align='center' border='0' cellpadding='5' cellspacing='5' style='background-color:#f2f2f2; border-radius:5px; color:#333333; width:85%;'>
<tbody>
<tr>
<td>
<p style='text-align:left'>Order Number: <strong>$order_id</strong></p>
<p style='text-align:left'>Date Received: <strong>$date_added</strong></p>
<p style='text-align:left'>Name: <strong>$firstname $lastname</strong></p>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td colspan='2' style='border-color:#f3f3f3; text-align:center'> </td>
</tr>
<tr>
<td colspan='2' style='border-color:#f3f3f3; text-align:center'>
<h3 style='text-align:left;margin-left: 40px;'>Delivery Address</h3>
<table align='center' border='0' cellpadding='5' style='background-color:#f2f2f2; border-radius:5px; color:#333333; padding:7px; width:85%;'>
<tbody>
<tr>
<td>
<p style='text-align:left'><strong>$address_1</strong></p>
<p style='text-align:left'><strong>$address_2</strong></p>
<p style='text-align:left'><strong>$city - $pincode</strong></p>
<p style='text-align:left'><strong>Mobile No. $mobile</strong></p>
</td>
</tr>
</tbody>
</table>
<p> </p>
</td>
</tr>
<tr>
<td colspan='2' style='text-align:center'>
<p style='text-align:center'><img alt='Order Shipped' height='90' src='example.com/image/shipping/Shipping.jpg' width='410' /></p>
<p>Your order has been shipped from our warehouse.</p>
<p>Amount Payable</p>
<h2>Rs.<strong>$total</strong></h2>
</td>
</tr>
<tr>
<td colspan='2' style='text-align:center;'>
<table align='center' border='0' cellpadding='1' cellspacing='1' style='background-color:#000000; border-radius:5px; color:#ffffff; font-size:larger; font-weight:700; padding:10px 15px; text-align:center; text-decoration:none; width:85%;'>
<tbody>
<tr>
<td><a href='https://track.xyz.com/p/$tracking_no' target='_blank' style='padding:15px 25px; text-align:center; text-decoration:none; color:#FFF; text-decoration:none;'>TRACK PACKAGE</a></td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td colspan='2' style='text-align:center'>
<p><br />
</p>
</td>
</tr>
<tr>
<td colspan='2'>
<p style='text-align:center'><em><span style='font-size:12px'>Instructions</span></em></p>
<table align='center' border='0' cellspacing='5' style='background-color:#f2f2f2; border-radius:5px; color:#333333; width:85%;'>
<tbody>
<tr>
<td><span style='font-size:12px'>1.Please do not accept the package, if it is damaged / tampered before delivery.</span></td>
</tr>
<tr>
<td><span style='font-size:12px'>2.Your freebies (if any) shall be inside the package.</span></td>
</tr>
<tr>
<td><span style='font-size:12px'>3.Please mention remarks while signing for delivery, if you doubt that the package might be damaged or is suspicious.</span></td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td colspan='2' style='text-align:center'>
<p> </p>
<p><span style='font-size:12px; color:#a9a9a9;'>Note: We do not demand your bank or credit card details over phone. Please do not divulge these details to fraudsters claiming to be calling on behalf of abc. </span></p>
<p> </p>
</td>
</tr>
<tr>
<td colspan='2' style='text-align:center'>
<p>Contact Us</p>
<p><strong><a href='mailto:help#abc.com?subject=Regarding%20Order%20ID%20$order_id' style='text-decoration:none; color:#000;'>help#example.com</a></strong></p>
<p><span style='font-size:10px; color:#a9a9a9;'>Do not reply to this email, this is an automated email sent to $email.</p>
</td>
</tr>
</tbody>
</table>
</body>
</html> \r\n";
//Send Mail//
$mail_send = mail($to,$subject,$message,$header);
if($mail_send)
{
$con=mysqli_connect("localhost","admin","pass","database");//database connection
$delete = "UPDATE `oc_ship` SET `status`='1' WHERE `order_id`='$order_id'";
if($deleted = mysqli_query($con,$delete))
{
$update_comment = mysqli_real_escape_string($con,"<p>Your order has been shipped via XYZ AWB #<b>$tracking_no</b>.</p> <p><a href='track.xyz.com/p/$tracking_no' target='_blank'>Click here to track your order</a></p>");
$date_time = date('Y-m-d H:i:s');
$order_history = "INSERT INTO `oc_order_hist`(`order_id`,`order_status_id`,`notify`,`comment`,`date_added`) VALUES ('$order_id','3','1','$update_comment','$date_time')";
if($order_history_update = mysqli_query($con,$order_history))
{
$order_status = "UPDATE `oc_order` SET `order_status_id`='3' WHERE `order_id`='$order_id'";
if($order_status_update = mysqli_query($con,$order_status))
{
echo "<br><strong>Shipping Updated successfully for Order ID $order_id</strong><br>";
}
}
}
}
}
}
}
}
?>
Since the script worked as expected until you added the SMS-sending code, that would imply that there's a problem with the new code.
Extract the SMS-sending code into a file on its own and test that, perhaps from the command line. Don't forget to check for cURL-specific errors (network errors, SSL error, etc.) with curl_error() and curl_errno(), like this:
$data = curl_exec($ch);
if (curl_errno($ch) > 0) {
print 'There was a cURL error: ' . $curl_error($ch);
}
Check the PHP and server logs also for error messages.
First of all my PHP skills are kinda limited, Hence my question to you here.
I have built a fairly complex form with multiple inputs(text boxs and drop downs) which are stored in a MYsql DB. When the form is submitted it displays on a new page as completed reports. These completed reports display one under the next every time the form is submitted. My question is, How can i get the reports displayed to show as a list of links to the individual reports rather then a list of complete reports.
I hope i've explained the situation well enough.
Code snippit from viewpage.php
<html>
<head>
<body>
<?php
mysql_connect("localhost","user","passwrd");
mysql_select_db("dtbase");
$order = "SELECT * FROM jobrequest" ;
$result = mysql_query($order);
while ($row=mysql_fetch_array($result)){
?>
<link rel="stylesheet" href="css/style.css" type="text/css" />
</head>
<body>
<div style="padding:15px 0px 0px 100px;">
<table cellpadding="0" cellspacing="0" border="0" style="vertical-align:middle;width: 1139px; background-color:#213568; height:36px;">
<tr>
<td class="topbar">Client Request Form</td>
<td style="width:900px;"></td>
<td class="topbar"><a style="color:#ffffff;" href="logout.php?logout">Logout</a></td>
</tr>
</table>
<div class="main-wrap">
<div class="content">
<table cellpadding="0" cellspacing="0" border="0" style="width: 1137px; background-color:#ffffff; height:5px;">
<tr>
<td></td>
</tr>
</table>
<table cellpadding="0" cellspacing="0" border="0" >
<tr>
<td style="vertical-align:top; width:5px;"></td>
<td style="vertical-align:top;"><?php include("includes/clientchoices.php"); ?></td>
<td style="vertical-align:top; padding:0px 5px 15px 5px;">
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td style="vertical-align:top; width:1002px;"> <h1> Dashboard</h1></td>
</tr>
<tr>
<td style="vertical-align:top; background-color:#f5f5f5;"><h2>Job Request Form</h2></td>
</tr>
<tr>
<td style="vertical-align:top; background-color:#ffffff; height:5px;"> </td>
</tr>
<tr>
<td>
<div class="form">
<table cellspacing="0" cellpadding="0" border="0" style="width:998px">
<tr>
<td style="width:1002px; border:solid 1px #000000; padding:10px 0px 10px 0px;"><center><img src="../../images/spectra_logotop.jpg" alt="Spectra" title="Spectra" width="735" height="120" style="padding:5px;"></center>
</td>
</tr>
<tr>
<td>
<div style="padding:10px 0px 10px 0px;">
<table cellpadding="0" cellspacing="0">
<tr>
<td class="headingsa">Project Leader:</td><td class="answersa"><div class= "typesectiona"><?php echo ($row['project_leader'] ); ?></div></td>
<td class="headingsb">Contact Number:</td><td class="answersb"><div class= "typesectionb"><?php echo ($row['contact_number'] ); ?></div></td>
<td class="headingsc">Company Details:</td><td class="answersc"><div class= "typesectionc"><?php echo ($row['company_details'] ); ?></div></td>
</tr>
</table>
</div>
</td>
</tr>
<tr>
<td>
<table cellpadding="0" cellspacing="0">
<tr>
<td class="headings5">Contact Person On Site:</td><td class="answers5"><div class= "typesection5"><?php echo ($row['contactperson_onsite'] ); ?></div></td>
<td class="headings6">Contact Details:</td><td class="answers6"><div class= "typesection6"><?php echo ($row['contact_no'] ); ?></div></td>
<td class="headings7">Date:</td><td class="answers7"><div class= "typesection7"><?php echo ($row['date'] ); ?></div></td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table cellpadding="0" cellspacing="0">
<tr>
<td class="headings1">Job/Order Number:</td><td class="answers1"><div class= "typesection1"><?php echo ($row['job_order_number'] ); ?></div></td>
<td class="headings2">Document Number:</td><td class="answers2"><div class= "typesection2"><?php echo ($row['doument_number'] ); ?></div></td>
<td class="headings3">QCP:</td><td class="answers3"><div class= "typesection3"><?php echo ($row['qcp'] ); ?></div></td>
<td class="headings4">Page No:</td><td class="answers4"><div class= "typesection4"><?php echo ($row['pageno'] ); ?></div></td>
</tr>
</table>
</td>
</tr>
<table cellspacing="0" cellpadding="0" border="0">
<tr>
<td width="15px"></td>
<td><a class="othersubmitsLink" href="actionpdf.php">Email to Spectra</a></td>
</tr>
</table>
</div>
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
</div>
</div>
<?php
}
?>
</body>
</html>
You will need a separate PHP script for displaying a report based on a supplied ID. This separate script would look something like this:
Using mysqli
<?php
$conn = new mysqli("localhost", "user", "passwrd", "dtbase");
$jrQry = $conn->prepare("SELECT * FROM jobrequest WHERE jobrequest_id = ?");
$jrQry->bind_param('i', $_GET['jobrequest_id']);
$jrQry->execute();
$jobrequestResult = $jrQry->get_result();
$jobrequest = $jobrequestResult->fetch_assoc();
// At this point, $jobrequest will contain the jobrequest record you want to display.
?>
<!-- HTML FOR REPORT GOES HERE, USING $jobrequest VARIABLE TO SHOW THE DATA -->
Note that I have used mysqli in this example, if this is unsuitable you can use the old-style mysql commands, but for many many reasons (security chief among them) I would strongly suggest against this.
Using mysql
<?php
mysql_connect("localhost","user","passwrd");
mysql_select_db("dtbase");
$order = "SELECT * FROM jobrequest WHERE jobrequest_id = " . (int)$_GET['jobrequest_id'];
$result = mysql_query($order);
$jobrequest = mysql_fetch_array($result);
// At this point, $jobrequest will contain the jobrequest record you want to display.
?>
<!-- HTML FOR REPORT GOES HERE, USING $jobrequest VARIABLE TO SHOW THE DATA -->
Save this page as "viewjobrequest.php" and you will be able to load a given job request's report by supplying the jobrequest ID as a parameter in the URL, like so:
http://address_of_site/viewjobrequest.php?jobrequest_id=X
Now you can automatically generate a list of links to these pages by looking up your complete set of jobrequests and iterating over them, but instead on outputting a full report, just output a link:
Using mysqli
<?php
$conn = new mysqli("localhost", "user", "passwrd", "dtbase");
$jrQry = $conn->prepare("SELECT * FROM jobrequest WHERE jobrequest_id = ?");
$jrQry->bind_param('i', $_GET['jobrequest_id']);
$jrQry->execute();
$jobrequestResult = $jrQry->get_result();
?>
<ul>
<?php
while ($jobrequest = $jobrequestResult->fetch_assoc())
{
?>
<li>
<a href="viewjobrequest.php?jobrequest_id=<?php echo $jobrequest['jobrequest_id']; ?>">
View job request #<?php echo $jobrequest['jobrequest_id']; ?>
</a>
</li>
<?php
}
?>
</ul>
Using mysql
<?php
mysql_connect("localhost","user","passwrd");
mysql_select_db("dtbase");
$order = "SELECT * FROM jobrequest WHERE jobrequest_id = " . (int)$_GET['jobrequest_id'];
$result = mysql_query($order);
?>
<ul>
<?php
while ($jobrequest = mysql_fetch_assoc($result))
{
?>
<li>
<a href="viewjobrequest.php?jobrequest_id=<?php echo $jobrequest['jobrequest_id']; ?>">
View job request #<?php echo $jobrequest['jobrequest_id']; ?>
</a>
</li>
<?php
}
?>
</ul>
Note: I have deliberately omitted large portions of your HTML, you can add as much extra HTML as you need, I've just offered the bare bones to get you started.
BY looking at your code, I can say, it's not problem with PHP, it's more like HOW you are showing the result after fetching from database,
you are running loop, started from here
<?php while ($row=mysql_fetch_array($result)){ ?>
and ends here
<?php}?>
So everything inside loop or in easy words inside these brackets {} repeating again and again with new row of result fetched from database, if you take view source of viewpage.php you will see that style css file <link rel="stylesheet" href="css/style.css" type="text/css" /> repeating, Imagine if you are fetching 10 rows of result, you are also loading css file 10 times.
So the answer (most probably the solution) of your question is;
Your mysql query
<?php
mysql_connect("localhost","user","passwrd");
mysql_select_db("dtbase");
$order = "SELECT * FROM jobrequest" ;
$result = mysql_query($order);
$totalrows = mysql_num_rows($result); //Check Total Number of Rows To Check if Data Exist or Not
?>
and then in your HTML, First check if there are any rows exist in database which match your WHERE clause in mysql query.
//Set an if else statement here so incase if no data exist.
<?php if($totalrows > 0) {
//If row(s) exist run your while loop here
<?php while ($row=mysql_fetch_array($result)){ ?>
//Show the result here from database
//Close your loop
<?php } ?>
//Close your if condition
<?php } else { ?>
//Display a message here if there is no data to show
//Close your else bracket
<?php } ?>
With above explaniation I adjusted your HTML to show the result in desired way;
<table cellspacing="0" cellpadding="0" border="0" style="width:998px">
<tr>
<td style="width:1002px; border:solid 1px #000000; padding:10px 0px 10px 0px;"><center><img src="../../images/spectra_logotop.jpg" alt="Spectra" title="Spectra" width="735" height="120" style="padding:5px;"></center></td>
</tr>
<tr>
<td>
<?php if($totalrows > 0) {
<div style="padding:10px 0px 10px 0px;">
<table cellpadding="0" cellspacing="0">
<tr>
<td class="headingsa">Link to Report</td>
</tr>
<?php while ($row=mysql_fetch_array($result)){ ?>
<tr>
//You have to replace `nameoffile.php` with file in which you want to display report and correct this (as i assumed it) if it's wrong `$row['id']`
<td>Open Report</td>
</tr>
<?php } ?>
</table>
</div>
<?php } else { ?>
<div style="padding:10px 0px 10px 0px;">
<table cellpadding="0" cellspacing="0">
<tr>
<td>There is No Result To Show</td>
</tr>
</table>
</div>
<?php } ?>
</td>
</tr>
</table>
Note: MySQL will soon be deprecated, consider start using MYSQLi or PDO
I have a PHP/HTML page that prints a bunch of receipts. I'm trying to make it page break after each when actually printing. I've tried several style and class codes, but the best I've been able to do is get it to break after the first, but it never repeats. IOW I want it to page break after each time it prints the table referred to in the code.
enter code here
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><head>
<style type="text/css">
#media all {
.page-break { display: none; }
}
#media print {
.page-break { display: block; page-break-before: always; }
}
</style>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>North Atlanta Riding Club</title>
<link href="../styles.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
.style45 {
color: #FF0000;
font-weight: bold;
font-style: italic;
}
-->
</style>
</head>
<body>
<?php
do{
//THIS SEES IF THE LOGGED IN MEMBER HAS CONFIRMED CLOTHING
$colname_confirmed = "1";
if (isset($row_roster['key1'])) {
$colname_confirmed = (get_magic_quotes_gpc()) ? $row_roster['key1'] : addslashes($row_roster['key1']);
}
mysql_select_db($database_connection1, $connection1);
$query_confirmed = sprintf("SELECT * FROM clothingorder WHERE who = %s AND confirmed = 'Y' ORDER BY key1 ASC", $colname_confirmed);
$confirmed = mysql_query($query_confirmed, $connection1) or die(mysql_error());
$row_confirmed = mysql_fetch_assoc($confirmed);
$totalRows_confirmed = mysql_num_rows($confirmed);
if($totalRows_confirmed<>0){?>
<table width="990" border="0" align="left" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="990" height="31" valign="top"><!--DWLayoutEmptyCell--> </td>
</tr>
<tr>
<td height="83" valign="top">
<table border="1" align="left" cellpadding="2" cellspacing="0" bordercolor="#000000">
<tr bgcolor="#FFFFFF" class="style5">
<td colspan="9"><p>Member- <strong><?php echo $row_roster['fname']." ".$row_roster['lname']; ?><br>
</strong>Telephone- <strong><?php echo $row_roster['tel']; ?></strong> Email- <strong><?php echo $row_roster['email']; ?></strong><br>
Address- <br>
<strong>
<?php if($row_roster['add1']<>''){echo $row_roster['add1']."<br>";} ?>
</strong>
<strong>
<?php if($row_roster['add2']<>''){echo $row_roster['add2']."<br>";} ?>
</strong>
<strong>
<?php if($row_roster['city']<>''){echo $row_roster['city'].", ";} ?>
</strong>
<strong>
<?php if($row_roster['state']<>''){echo $row_roster['state']." ";} ?>
</strong>
<strong>
<?php if($row_roster['zip']<>''){echo $row_roster['zip'];} ?>
</strong><br>
</p>
</td>
</tr>
<tr bgcolor="#FFFFFF" class="style5">
<td><div align="center"><strong>Qty</strong></div></td>
<td><strong>Item</strong></td>
<td><strong>PO?</strong></td>
<td><div align="center"><strong>Paid?</strong></div></td>
<td><div align="center"><strong>Mens/Womens</strong></div></td>
<td><div align="center"><strong>Style</strong></div></td>
<td><div align="center"><strong>Cut</strong></div></td>
<td><div align="center"><strong>Size</strong></div></td>
<td><div align="center"><strong>Price</strong></div></td>
</tr>
<tr bgcolor="#FFFFFF" class="style5">
<td colspan="8"><div align="right">Narc Membership </div></td>
<td><div align="center">
<?php if($row_roster['paid']=="Y"){echo "Paid";$total=0;}else{echo "$".$row_dues['dues'];$total=$row_dues['dues'];} ?></div></td>
</tr>
<?php
do {
$colname_item = "1";
if (isset($row_confirmed['item'])) {
$colname_item = (get_magic_quotes_gpc()) ? $row_confirmed['item'] : addslashes($row_confirmed['item']);
}
mysql_select_db($database_connection1, $connection1);
$query_item = sprintf("SELECT key1, item, price, free FROM clothing WHERE key1 = %s", $colname_item);
$item = mysql_query($query_item, $connection1) or die(mysql_error());
$row_item = mysql_fetch_assoc($item);
$totalRows_item = mysql_num_rows($item);
?>
<tr class="style5">
<td><div align="center"><?php echo $row_confirmed['qty']; ?></div></td>
<td><?php echo $row_item['item']; ?></td>
<td><div align="center"><span class="style45">
<?php if($row_confirmed['postorder']=='Y'){?>YES<?php }?></span></div></td>
<td><div align="center"><?php echo $row_confirmed['paid']; ?></div></td>
<td><div align="center"><?php echo $row_confirmed['mf']; ?></div></td>
<td><div align="center"><?php echo $row_confirmed['style']; ?></div></td>
<td><div align="center"><?php echo $row_confirmed['cut']; ?></div></td>
<td><div align="center"><?php echo $row_confirmed['size']; ?></div></td>
<td><div align="center">
<?php if($row_confirmed['price'] == 0){echo "Free";
}else{
if($row_confirmed['paid']=="Y"){echo "Paid";}else{echo $row_confirmed['price'];$total = $total + $row_confirmed['price'];}
} ?>
</div></td>
</tr>
<?php
} while ($row_confirmed = mysql_fetch_assoc($confirmed)); ?>
<tr bgcolor="#FFFFFF" class="style5">
<td colspan="8"><div align="right"><em><strong>Total Owed</strong></em></div></td>
<td><div align="center" class="style6"><em><strong><?php echo "$".$total.".00";?></strong></em></div></td>
</tr>
</table>
</td>
</tr>
</table>
<div class="page-break"></div>
<?php
}
}while($row_roster = mysql_fetch_assoc($roster));
?>
</body>
I too am finding the page break in #media print {} to be "beyond flaky"! In fact, so far finding the #media print to be flaky entirely. Floats aren't working well and several styling details just don't seem to be displaying as envisioned. It seems that browser support for "print" is lackluster. I am working on an application that should print name badges and precision is critical regarding placement and sizing. I'm close to giving up on the #media print {} styling though I'd hoped to have it look web-savvy online but to print as I envision. Might have to settle for it looking like the badges. I'm using code which adds that page-break class div every 6 "records" (badges are 6-up in 2 columns of 3, 4" x 3" w).
If like me, you're unable to find the method that uses #media print {} would it work to just display the receipt on-screen as you intend it to print? May also be your workaround until (and if) the browsers catch up to w3c conventions. I'd love to find a good publication explaining what does and doesn't work about the #media print styling otherwise the screen styling should work.
here it showing all records from database but it shows all empty div first then below it shows all records .i want to show each record to be shown in single div in rows.
<div id="winnercontainer">
<h2 style="background-color:#9966FF; width:850px; height:30px; font:bold; font- size:22px; color:#FFFFFF; padding-left:20px;">Winners</h2>
<?php
include('pagination/ps_pagination.php');
$conn = mysql_connect('localhost','root','');
if(!$conn) die("Failed to connect to database!");
$status = mysql_select_db('gunjanbid', $conn);
if(!$status) die("Failed to select database!");
$sql = 'SELECT * FROM winners';
$pager = new PS_Pagination($conn, $sql,10, 10);
//The paginate() function returns a mysql result set for the current page
$rs = $pager->paginate();
?>
<table>
<?php
while($row=mysql_fetch_array($rs)){
?>
<div id="winner">
<tr>
<td ><img src="memberpic/myphoto.jpg" width="150" height="150" alt="001" /></td>
<td > </td>
<td ><table >
<tr>
<td >Auction Item : <?php echo $row['Items']; ?></td>
</tr>
<tr>
<td>Rs. <?php echo $row['Rs']; ?></td>
</tr>
<tr>
<td>Winning Bid Value : Rs. <?php echo $row['WinningBidValue']; ?></td>
</tr>
<tr>
<td>MRP : Rs. <?php echo $row['MRP']; ?></td>
</tr>
<tr>
<td>Auction closed on : <?php echo $row['enddate']; ?></td>
</tr>
<tr>
<td>Winner : <?php echo $row['Winner']; ?></td>
</tr>
<tr>
<td>City: <?php echo $row['City']; ?></td>
</tr>
<tr>
<td >Delivery Status: <?php echo $row['DeliveryStatus']; ?></td>
</tr>
</table></td>
<td > </td>
<td id=save><font color=black>SAVED:</font> Rs.<?php echo $row['MRP']- $row['WinningBidValue']; ?></td>
<td > </td>
<td ><img src=productimage/1/1.1.jpg width="200" height="193" alt="001" /></td>
</tr>
</div>
<?php
}
?>
</table>
<?php
//Display the navigation
//echo $pager->renderFullNav();
echo '<div style="text-align:center">'.$pager->renderFullNav().'</div>';
?>
</div>
abd my stylesheet s are
#winnercontainer
{
width:870px;
height:auto;
background-color:#CCCCCC;
border:solid #9966FF;
border-radius:10px;
margin:auto;
clear:both;
margin:10px;
position:relative;
}
#winner
{
width:840px;
height:250px;
background-color: #999999;
border: solid #9966FF;
border-radius:10px;
margin:auto;
clear:both;
margin-top: 10px;
margin-right: 10px;
margin-bottom: 10px;
margin-left: 15px;
position:relative;
}
i want all my records to be place in div means each div have one record to be display.plz help me ,i am new here.
I'll give you a start with some old code I have that reads a table from a MySQL database and prints it out on a screen. You can modify it as you see fit. It's a php file that resides on the server.
<?php
echo "<head><title>Read list</title></head>";
$host = "xxxxxxxxxxx";
$user = "xxxxxxxxxxx";
$password = "xxxxxxxxxxx";
$dbname = "xxxxxxxxxxx";
$cxn = mysqli_connect($host,$user,$password,$dbname);
if (mysqli_connect_errno()) {echo "No connection" . mysqli_connect_error();}
$query = " select * from list where uniqueid >= 0 ";
$result = mysqli_query($cxn, $query) or die ("could not query database");
echo "<table cellpadding=1px border=1>";
while ($row = mysqli_fetch_array($result))
{
$uniqueid = $row['uniqueid'];
$localid = $row['localid'];
$mdid = $row['mid'];
$type = $row['type'];
echo "<tr><td>".$uniqueid."</td><td>".$localid."</td><td>".$mdd."</td><td>".$type."</td></tr>";
}
echo "</table>";
?>