my table has many columns so it resulted to over-spanning in its width. i want to make it scrollable horizontally so that it would fit in the screen and it will look more neat and organized. I guess css will do with property overflow hidden. but I dont know where to put my html codes. hope someone can help.
<?php
$serverName = "kwe-PC\SQLEXPRESS";
$connectionInfo = array("Database" => "customerdb", "UID" => "dbadmin", "PWD" => "kwe");
$conn = sqlsrv_connect($serverName, $connectionInfo);
if ($conn === false) {
die(print_r(sqlsrv_errors(), true));
}
//declare the SQL statement that will query the database
$query = "SELECT * FROM Customer_Details";
//execute the SQL query and return records
$result = sqlsrv_query($conn, $query)
or die(print_r(sqlsrv_errors(), true));
//Show results in table
$o = '<table border=1 id="myTable">
<thead>
<tr>
<th> </th>
<th>REC NUMBER</th>
<th>CUSTOMER ID</th>
<th>CUSTOMER NAME</th>
<th>SEC-REGISTERED NAME</th>
<th>TIN NUMBER</th>
<th>STORE TYPE</th>
<th>SIZE OF BUSINESS</th>
<th>SELLER ID</th>
<th>DATE OF ESTABLISHMENT</th>
<th>TELEPHONE#/FAX</th>
<th>PAYMENT TERMS</th>
<th>SHIPPING INSTRUCTIONS</th>
<th>NUMBER OF DOORS</th>
<th>NUMBER OF WAREHOUSES</th>
<th>OWNER</th>
<th>PURCHASER/S</th>
<th>ACCOUNTING HEAD</th>
<th>WAREHOUSE HEAD</th>
<th>OTHER PERSONNEL</th>
<th>PAYMENT TERMS 2</th>
<th>COLLECTION SCHEDULE</th>
<th>DISCOUNT</th>
<th>VOLUME</th>
<th>MERCHANDISING</th>
<th>VEHICLE</th>
<th>DISTRIBUTION</th>
<th>CSL</th>
<th>ASSORTMENT</th>
<th>PRICING</th>
<th>MARGIN</th>
<th>PRICE</th>
<th>PROMOTION</th>
<th>PEOPLE</th>
<th>OTHERS</th>
<th>REPLENISHMENT ORDERS</th>
<th>ASSORTMENT/MERCHANDISING</th>
<th>NEW PRODUCTS</th>
<th>PRICING/PROMOTION</th>
<th>PICTURE</th>
</tr>
</thead><tbody>';
while ($record = sqlsrv_fetch_array($result)) {
$o .= '<tr><td><input type=radio name=id value=' . $record ['Rec_No'] . '></td>';
$o .= '<td>' . $record ['Rec_No'] . '</td>';
$o .= '<td>' . $record ['Cust_ID'] . '</td>';
$o .='<td>' . $record ['Cust_Name'] . '</td>';
$o .='<td>' . $record ['SEC_Name'] . '</td>';
$o .='<td>' . $record ['TIN Number'] . '</td>';
$o .='<td>' . $record ['Store_Type'] . '</td>';
$o .='<td>' . $record ['Size of Business'] . '</td>';
$o .='<td>' . $record ['Seller_ID'] . '</td>';
$o .='<td>' . date('F d, Y', strtotime($record ['Date of Establishment'])) . '</td>';
$o .='<td>' . $record ['Telephone/Fax'] . '</td>';
$o .='<td>' . $record ['Payment Terms'] . '</td>';
$o .='<td>' . $record ['Shipping Instructions'] . '</td>';
$o .='<td>' . $record ['Number of Doors'] . '</td>';
$o .='<td>' . $record ['Number of Warehouses'] . '</td>';
$o .='<td>' . $record ['Owner'] . '</td>';
$o .='<td>' . $record ['Purchaser(s)'] . '</td>';
$o .='<td>' . $record ['Accounting Head'] . '</td>';
$o .='<td>' . $record ['Warehouse Head'] . '</td>';
$o .='<td>' . $record ['Other Personnel'] . '</td>';
$o .='<td>' . $record ['Payment Terms 2'] . '</td>';
$o .='<td>' . $record ['Collection Schedule'] . '</td>';
$o .='<td>' . $record ['Discount'] . '</td>';
$o .='<td>' . $record ['Volume'] . '</td>';
$o .='<td>' . $record ['Merchandising'] . '</td>';
$o .='<td>' . $record ['Marketing Vehicle'] . '</td>';
$o .='<td>' . $record ['Distribution'] . '</td>';
$o .='<td>' . $record ['CSL'] . '</td>';
$o .='<td>' . $record ['Assortment'] . '</td>';
$o .='<td>' . $record ['Pricing'] . '</td>';
$o .='<td>' . $record ['Margin'] . '</td>';
$o .='<td>' . $record ['Price'] . '</td>';
$o .='<td>' . $record ['Promotion'] . '</td>';
$o .='<td>' . $record ['People'] . '</td>';
$o .='<td>' . $record ['Others'] . '</td>';
$o .='<td>' . $record ['Replenishment Orders'] . '</td>';
$o .='<td>' . $record ['Assortment/Merchandising'] . '</td>';
$o .='<td>' . $record ['New Products'] . '</td>';
$o .='<td>' . $record ['Pricing/Promotions'] . '</td>';
$o .='<td><img height=127 width=127 src="data:image/png;base64,' . $record['image'] . '"></td>';
$o .='</tr>';
}
$o .= '</tbody></table>';
?>
<form action="delete.php" method="POST">
<?php echo $o; ?>
<br><input type="submit" value="Delete" name="submit">
</form>
<?php
if (isset($_POST['submit'])) {
$serverName = "kwe-PC\SQLEXPRESS";
$connectionInfo = array("Database" => "customerdb", "UID" => "dbadmin", "PWD" => "kwe");
$conn = sqlsrv_connect($serverName, $connectionInfo);
if ($conn === false) {
die(print_r(sqlsrv_errors(), true));
}
if(isset($_POST['id']) && !empty($_POST['id'])){
$sql = "DELETE FROM Customer_Details WHERE Rec_No =" . $_POST['id'];
sqlsrv_query($conn, $sql);
$ids = $_POST['id'];
echo "Row with Record Number: " . $ids . " has been deleted!";
}else{
echo "ID is empty";
}
}
?>
In css
#myTable{overflow-x: scroll}
http://www.w3schools.com/cssref/css3_pr_overflow-x.asp
1) Wrap table with a div which has a class
<div class="wrap">
<table>
...
</table>
</div>
2) Give wrap class overflow-x property with scroll
overflow-x: scroll
3) Make it fixed width
width: 300px;
4) Also take care of vertically visibility
overflow-y: visible;
.wrap {
overflow-x: scroll;
overflow-y: visible;
width: 300px;
}
Here is a simple working example.
Related
I have a render of row of database
echo "<table border='1' cellpadding='10'>";
echo "<tr> <th>ID</th> <th>First Name</th> <th>Last Name</th> <th></th> <th></th></tr>";
// loop through results of database query, displaying them in the table
while($row = mysql_fetch_array( $result )) {
// echo out the contents of each row into a table
echo "<tr>";
echo '<td>' . $row['id'] . '</td>';
echo '<td>' . $row['tex1'] . '</td>';
echo '<td>' . $row['tex2'] . '</td>';
echo '<td>' . $row['tex3'] . '</td>';
echo '<td>' . $row['tex4'] . '</td>';
echo '<td>' . $row['tex5'] . '</td>';
echo '<td>' . $row['tex6'] . '</td>';
echo '<td>' . $row['tex7'] . '</td>';
echo '<td>' . $row['tex8'] . '</td>';
echo '<td>' . $row['tex9'] . '</td>';
echo '<td>' . $row['tex10'] . '</td>';
echo '<td>Edit</td>';
echo '<td>Delete</td>';
echo "</tr>";
}
// close table>
echo "</table>";
And in the tex1 is a date, my problem is for a class for tr, when the tex2 is empty and the date of tex1 is older than 30 days, tr have class red, the date of tex1 is inserted manually,how can I do to change the class on the basis of this?
I'm not sure if I understood what you wanted properly but I'll give it a shot. You want to add a class ("red") to the , whenever the condition is met that either the date is older than 30 days old (tex1) or the First Name is empty (tex2).
echo "<table border='1' cellpadding='10'>";
echo "<table border='1' cellpadding='10'>";
echo "<tr> <th>ID</th> <th>First Name</th> <th>Last Name</th> <th></th> <th></th></tr>";
// loop through results of database query, displaying them in the table
while($row = mysql_fetch_array( $result )) {
// echo out the contents of each row into a table
// I assume since you're just printing it out, the date is a String
// So first convert it to a timestamp
$date = strtotime($row['tex1']);
// Determine the difference, I'm doing it this way to make it easy for you to understand
$days = 60*60*24*30; // 30 days
if (empty($row['tex2']) || time()-$date > $days) {
echo '<tr>';
} else {
echo '<tr class="red">';
}
echo '<td>' . $row['id'] . '</td>';
echo '<td>' . $row['tex1'] . '</td>';
echo '<td>' . $row['tex2'] . '</td>';
echo '<td>' . $row['tex3'] . '</td>';
echo '<td>' . $row['tex4'] . '</td>';
echo '<td>' . $row['tex5'] . '</td>';
echo '<td>' . $row['tex6'] . '</td>';
echo '<td>' . $row['tex7'] . '</td>';
echo '<td>' . $row['tex8'] . '</td>';
echo '<td>' . $row['tex9'] . '</td>';
echo '<td>' . $row['tex10'] . '</td>';
echo '<td>Edit</td>';
echo '<td>Delete</td>';
echo "</tr>";
}
// close table>
echo "</table>";
You should check for the conditions what you have mentioned in your question. And this can be done like this.
if(strtotime($row['tex1']) + 30 * 24 * 60 * 60 < time() && $row['tex2'] =="") {
$class="class='red'";
} else {
$class= "";
}
echo "<tr $class>";// id condition satisfies, class='red' will get echo, else echo will be null.
Try a conditional when writing the element:
echo '<tr'.
( ((strtotime($row['tex1']) < strtotime('30 days ago'))
&& (empty($row['tex2']))) ? ' class="red"' : '').
'>';
I have table called reservations. It displays reservations made by users. I want highlight records in current date using end date.
Php code
$result2 = mysql_query("SELECT * FROM reservations WHERE hotel_id = '1' ORDER BY end");
while ($row = mysql_fetch_array($result2)) {
echo '<tr>';
echo '<td class="contacts">' . $row['fname'] . ' ' . $row['lname'] . '</td>';
echo '<td class="contacts">' . $row['start'] . '</td>';
echo '<td class="contacts">' . $row['end'] . '</td>';
echo '<td class="contacts">' . $row['qty'] . '</td>';
echo '</td>';
echo '<td class="contacts">' . $row['room_type'] . '</td>';
echo '<td class="contacts">' . '<a href=out.php?id=' . $row["res_id"] . '>' . 'Check Out' . '</a>' . '</td>';
echo '</tr>';
}
I'd do that at frontend side, but if you want to compute than in PHP, you will need to compare the date from $row and current date and add a class or a style tag to the .
Like so:
$rowHasCurrentDate = $row['date'] == date('Y-m-d');
echo '<tr' + ($rowHasCurrentDate ? ' class="highlight-row"' : "") + '>';
instead of
echo '<tr>';
You can replace the 'class="highlight-row"' with 'style="background-color:red"' if you want to do it without touching frontend side at all.
The example is kinda spaghetti-code, but you can move this logic somewhere else after you get it working.
I am assuming that your start date is current date. This is css thing, i have given you solution to you.
<html>
<head>
<style>
.currdate
{
background-color:red; //change this color to whatever you wish to change to
}
</style>
</head>
<body>
<?php
$result2 = mysql_query("SELECT * FROM reservations WHERE hotel_id = '1' ORDER BY end");
while ($row = mysql_fetch_array($result2)) {
echo '<tr>';
echo '<td class="contacts">' . $row['fname'] . ' ' . $row['lname'] . '</td>';
echo '<td class="contacts currdate">' . $row['start'] . '</td>';
echo '<td class="contacts">' . $row['end'] . '</td>';
echo '<td class="contacts">' . $row['qty'] . '</td>';
echo '</td>';
echo '<td class="contacts">' . $row['room_type'] . '</td>';
echo '<td class="contacts">' . '<a href=out.php?id=' . $row["res_id"] . '>' . 'Check Out' . '</a>' . '</td>';
echo '</tr>';
}
?>
<body>
</html>
I have a table with 8 columns and then a foreach loop running to display all the content in the table.
I would like to style the table with a scroll bar so the header stays sticky but if I add all the content only shows under the header for the first column (date).
How do I add style for the of the table and at the same time make sure the content is showing in the correct columns?
<table id="email_subscription">
<thead>
<tr>
<th>Date</th>
<th>c1</th>
<th>c2</th>
<th>c3</th>
<th>c4</th>
<th>c5</th>
<th>Total New</th>
<th>All Contacts</th>
</tr>
</thread>
<tbody>
<?php
foreach($values as $v_date){
$date = $v_date->DATE;
$count = $wpdb->get_results($wpdb->prepare(
" SELECT DISTINCT `date`.... ",
echo '<tr class="row_main">';
echo '<td>' . $date . '</td>';
foreach($count as $counts){
$val1 = $counts->c1;
$val2 = $counts->c2;
$val3 = $counts->c3;
$val3a = $counts->c4;
$val3b = $counts->c5;
$val9 = $counts->all_contacts;
echo '<td>' . $val1 . '</td>';
echo '<td>' . $val2 . '</td>';
echo '<td>' . $val3 . '</td>';
echo '<td>' . $val3a . '</td>';
echo '<td>' . $val3b . '</td>';
echo '<td>' . $val7 . '</td>';
echo '<td>' . $val9 . '</td>';
echo '</tr>';
}
}
?>
</tbody>
</table>
It seems display:block; is causing the issue. But how else do I add the scroll?
tbody{
display: block;
overflow-y:auto;
overflow-x: hidden;
height: 100px;
width: 100%;
}
I think, you should move outside the second foreach-loop to complete one row:
foreach($count as $counts){
$val1 = $counts->c1;
$val2 = $counts->c2;
$val3 = $counts->c3;
$val3a = $counts->c4;
$val3b = $counts->c5;
$val9 = $counts->all_contacts;
echo '<td>' . $val1 . '</td>';
echo '<td>' . $val2 . '</td>';
echo '<td>' . $val3 . '</td>';
echo '<td>' . $val3a . '</td>';
echo '<td>' . $val3b . '</td>';
echo '<td>' . $val7 . '</td>';
echo '<td>' . $val9 . '</td>';
}
echo '</tr>';
}
So i've been trying to get one record and edit it by pressing the button that is created in that table, but honestly, i have no idea how to do that. Dx Can anyone help me with this? (Yes, i want the button created for each record. You know, so at the end of every row in the table, every record will have it's own button.)
while($rArt = mysqli_fetch_array($sql)){
echo '<tr><td>' . $rArt['ArtID'] . '</td>';
echo '<td>' . $rArt['FiliaalID'] . '</td>';
echo '<td>' . $rArt['Productnaam'] . '</td>';
echo '<td>' . $rArt['Inkoopprijs'] . '</td>';
echo '<td>' . $rArt['Voorraad'] . '</td>';
echo '<td>' . $rArt['Min_voorraad'] . '</td>';
$voo = $rArt['Voorraad'];
$minvoo = $rArt['Min_voorraad'];
$nodig = $minvoo * 2 - $voo;
$chosen = $rArt['ArtID'];
echo '<td>' . $nodig . '</td>';
echo '<td><input type="submit" name="bestel" value="Bestel"></td></tr>';
if(isset($_GET['bestel'])){
$query = mysqli_query($mysql, "
UPDATE artikel a, voorraad v
SET v.voorraad = v.voorraad + '$nodig'
WHERE a.artid = v.artid
AND v.voorraad = '$chosen'");
}
}
I wouldn't use submit in this case, but just a suggestion:
Why don't you try it this way:
<table>
<tr>
<td>Artikel ID</td>
<td> **<a href="bestelpagina/edit/id/1">** </td>
</tr>
</table>
So you can create an action called Edit in which you can do the changes.
Read the comment in the solution as they are important.
while($rArt = mysqli_fetch_array($sql)){
// echo '<tr><td>' . $rArt['ArtID'] . '</td>';
//The above line i removed and added the line below
echo '<tr><td>' .'<a href=\'admin.php?ArtID='.$rArt['ArtID'].'\'>'.$rArt['ArtID'] .'</td>';
echo '<td>' . $rArt['FiliaalID'] . '</td>';
echo '<td>' . $rArt['Productnaam'] . '</td>';
echo '<td>' . $rArt['Inkoopprijs'] . '</td>';
echo '<td>' . $rArt['Voorraad'] . '</td>';
echo '<td>' . $rArt['Min_voorraad'] . '</td>';
$voo = $rArt['Voorraad'];
$minvoo = $rArt['Min_voorraad'];
$nodig = $minvoo * 2 - $voo;
$chosen = $rArt['ArtID'];
echo '<td>' . $nodig . '</td>';
//echo '<td><input type="submit" name="bestel" value="Bestel"></td></tr>';
//removed this as you dont need input button here.
}///Your while loop should close here not in the ent
if(isset($_GET['bestel'])){
$query = mysqli_query($mysql, "
UPDATE artikel a, voorraad v
SET v.voorraad = v.voorraad + '$nodig'
WHERE a.artid = v.artid
AND v.voorraad = '$chosen'");
}
//} I remove this tag as your while loop should close before isset function
In PHP MYSQL_FETCH_ASSOC is omitting Last Row. This never happened. But this time it put me into soup at the last moment.
Even I've put up mysql_num_rows the result is 14 records -- but on list it shows only 13 records and the 14th record is omitted.
Any kind of help is Appreciated.
$uno = $_GET["uno"];
$xtc1 = 'select * from rform where uno="' . $uno . '" order by rno DESC';
$xtc = mysql_query($xtc1) or die('User Reservation Retrival Error : ' . mysql_error());
$trno = mysql_fetch_assoc($xtc);
$trow = mysql_num_rows($xtc);
echo '<p>List of Onlilne Reservations made by <strong style="font-weight:bold; color:red;">' . ucwords($trno["cname"]) . ' (' . $trow . ')</strong></p>';
echo '<table cellpadding="5" cellspacing="0" border="1">';
echo '<tr>';
echo '<td colspan="5" style=" font-size:14px; text-align:center; font-weight:bold; color:red;">' . ucwords($trno["cname"]) . '</td>';
echo '</tr>';
echo '<tr>';
echo '<th>R.NO</th>';
echo '<th>From</th>';
echo '<th>To</th>';
echo '<th>Date & Time of<Br>Travel</th>';
echo '<th>Reserved On</th>';
echo '</tr>';
while($mtn = mysql_fetch_assoc($xtc)){
$dt = $mtn["csdate"] . ' ' . $mtn["ctime"];
echo '<tr>';
echo '<td>' . $mtn["rno"] . '</td>';
echo '<td>' . $dt . '</td>';
echo '<td>' . $mtn["caddr"] . '</td>';
echo '<td>' . $mtn["cdest"] . '</td>';
echo '<td>' . date('d-M-Y',strtotime($mtn["tstamp"])) . '</td>';
echo '</tr>';
}
echo '</table>';
You have an extra $trno = mysql_fetch_assoc($xtc) that you sem to be discarding. This is your missing row. Just remove that line.
deleting the first $trno = mysql_fetch_assoc($xtc); will solve this problem.
In case you need to read the first line of $xtc before the loop. You can change while loop to do-while, without deleted the first $mtn = mysql_fetch_assoc($xtc);
do{
//whatever
}while($mtn = mysql_fetch_assoc($xtc));