How to get data from form and make and array - php

I am just making a railway reservation project to my college therefor I have to get passenger details and make a 2d array and send it to another page to show the summary but I just don't know how to do that.
my code is
<?php
include('connection.php');
session_start();
$train_number = $_GET['train_number'];
$train_name = $_GET['train_name'];
$coachid = $_GET['coachid'];
$date = $_SESSION['date'];
$day = $_SESSION['day'];
$coachtype = $_SESSION['coachtype'];
$useremail = $_SESSION['useremail'];
if($_SERVER['REQUEST_METHOD']='POST')
{
if(!empty($_POST['proceed']))
{
$i = 1;
while($i<7)
{
"What to write here";
}
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Buy Tickets </title>
<link rel="stylesheet" href="css.css">
</head>
<body>
<div class="wrapper">
<div class="header">
<img src="banner.jpg" height="100%" width="100%"/>
</div>
<div class="navbar">
<ul>
<li>Dashboard </li>
<li>Buy Ticket </li>
<li>Cancel ticket</li>
<li>Edit Profile</li>
<li id="last">Logout</li>
</ul>
</div>
<div>
<?php
echo "<h4 align='center'><u>Booking for </u></h4>";
echo "<table align='center'>
<thead>
<tr style='border: 1px solid #dddddd;text-align: left; padding: 8px;'>
<th style='border: 1px solid #dddddd;text-align: left; padding: 8px;'> Train Number </th>
<th style='border: 1px solid #dddddd;text-align: left; padding: 8px;'> Train name </th>
<th style='border: 1px solid #dddddd;text-align: left; padding: 8px;'> Date </th>
<th style='border: 1px solid #dddddd;text-align: left; padding: 8px;'> Coach type </th>
</tr>
</thead>";
echo "<tr>";
echo "<td style='border: 1px solid #dddddd;text-align: left; padding: 8px;'>".$train_number."</td>";
echo "<td style='border: 1px solid #dddddd;text-align: left; padding: 8px;'>".$train_name."</td>";
echo "<td style='border: 1px solid #dddddd;text-align: left; padding: 8px;'>".$date."</td>";
echo "<td style='border: 1px solid #dddddd;text-align: left; padding: 8px;'>".$coachtype."</td>";
echo "</tr>";
echo "</table>";
echo "<h4 align='center'><u>Passenger details </u></h4>";
echo "<table align='center'>
<thead>
<tr style='border: 1px solid #dddddd;text-align: left; padding: 8px;'>
<th style='border: 1px solid #dddddd;text-align: left; padding: 8px;'> No </th>
<th style='border: 1px solid #dddddd;text-align: left; padding: 8px;'> Passenger Name </th>
<th style='border: 1px solid #dddddd;text-align: left; padding: 8px;'> Age </th>
<th style='border: 1px solid #dddddd;text-align: left; padding: 8px;'> Gender type </th>
</tr>
</thead>";
$iforlist = 1;
while($iforlist<7)
{
echo "<form method='post'>";
echo "<tr>";
echo "<td style='border: 1px solid #dddddd;text-align: left; padding: 8px;'>".$iforlist."</td>";
echo "<td style='border: 1px solid #dddddd;text-align: left; padding: 8px;'><input type='text' name='passenger_name.".$iforlist."' value='' placeholder='Enter name '></td>";
echo "<td style='border: 1px solid #dddddd;text-align: left; padding: 8px;'><input type='number' name='passenger_age.".$iforlist."' value='' max='100' min='1' placeholder='Enter passenger age '></td>";
echo "<td style='border: 1px solid #dddddd;text-align: left; padding: 8px;'><select name='passenger_gender.".$iforlist."'>
<option value='Male'>Male</option>
<option value='Female'>Female</option>
</select></td></td>";
echo "</tr>";
$iforlist++;
}
echo "</table>";
echo "<div align='center' style='margin-top:10px;'><input type='submit' align='center' name='proceed' value='Proceed' style='width:100px;height:40px;' placeholder='Enter name '></div>";
echo "</form>";
?>
</div>
</div>
</body>
</html>
So, tell me how can i make fetch data if only 2 or 3 field are filled and make a 2d array of it.
if you want any other information i'll give you..

Here is an example of how to use 2D Arrays in PHP
$cars = array
(
array("Volvo",22,18),
array("BMW",15,13),
array("Saab",5,2),
array("Land Rover",17,15)
);
Now to access the data, you must specify the row and column:
<?php
echo $cars[0][0].": In stock: ".$cars[0][1].", sold: ".$cars[0][2].".<br>";
echo $cars[1][0].": In stock: ".$cars[1][1].", sold: ".$cars[1][2].".<br>";
echo $cars[2][0].": In stock: ".$cars[2][1].", sold: ".$cars[2][2].".<br>";
echo $cars[3][0].": In stock: ".$cars[3][1].", sold: ".$cars[3][2].".<br>";
?>
In this case:
array("Volvo",22,18)
That is a single row (0) and it has three columns (Volvo at row=0 column=0, 22 at row=0 colum=1, etc)
I took the example from here: https://www.w3schools.com/php/php_arrays_multi.asp
Let me know if this helps.

Related

dompdf stops unexpectedly after data collection with mysq

I have a file that converts my MySQL data to PDF using dompdf it works fine but sometimes it just throws 500 error and nothing shows up and after a few moments works and sometimes I am supposed to put a clean back up for it to work. All the is collected successfully with mysql and php but at last some errors in converting the PDF dont know is it dompdf bug or problem with my code. Please check the code below and help me make a better world... I greatly appreciate your help :)
<?php
$idswitch = $_GET['id']; // id for viewing
// Below is optional, remove if you have already connected to your database.
$mysqli = mysqli_connect('...', '..', '..', '...');
$sql=mysqli_query($mysqli,"SELECT * FROM si_invoices WHERE id='$idswitch'")or die(mysql_error());
$row=mysqli_fetch_assoc($sql);
$sample .= "<div style='font-family: Arial, Helvetica, sans-serif; background:#000000; width: 100%; color: #ffffff; padding: 4px; text-align: center; font-size: 120%;' >PROFOMA INVOICE: ID:100".$row['id']."</div>";
$sample .= "<div style='width:100%; height: 120px; background: #ffffff;'>";
$sample .= "<img src='logo-si.png' style='width: 250px; padding: 15px'>";
$sample .= "<div style='font-family: Arial, Helvetica, sans-serif; background:#000000; width: 100%; color: #ffffff; padding: 4px; text-align: center; font-size: 75%' >Interior Exterior General Signs LED Architectural & Modular Sign Systems Traffic & Safety Signs MV No. Plates</div><br>";
$sample .= "<div style='font-family: Arial, Helvetica, sans-serif; position:absolute; top: 35px; left: 300px; width: 400px; border-left: 2px solid #000000; padding-left: 10px; background: #ffffff; font-size: 85%'>
UBUNGO BUSINESS PARK-P.O.BOX 1965 - <br>DAR ES SALAAM-TANZANIA- +255 22 2866500 / 2860440 -<br>068444 422
E-MAIL: headsales#signindustries.co.tz - info#signindustries.co.tz - www.signindustries.co.tz
</div>";
$sample .= "</div>";
$sample .= "<div style='width:100%; margin-top: 15px;'>
<div style='float:left; width: 400px; height:margin-right: 10px;'>
<table style='width: 100%; height: 175px; border: 1px solid #000000; padding: 3px; font-size: 90%; font-family: Arial, Helvetica, sans-serif;'>
<tr>
<th align='left'></th>
<th align='left'></th>
</tr>
<tr>
<td width='30%'>Main Client:</td>
<td width='65%' align='left' style='border: 1px solid #000000;'>".$row['main_client']."</td>
</tr>
<tr>
<td width='30%'>Postal Address:</td>
<td width='65%' align='left' style='border: 1px solid #000000;'>".$row['postal_address']."</td>
</tr>
<tr>
<td width='30%'>Contact Person:</td>
<td width='65%' align='left' style='border: 1px solid #000000;'>".$row['contact_person']."</td>
</tr>
<tr>
<td width='30%'>Telephone / Cell:</td>
<td width='65%' align='left' style='border: 1px solid #000000;' >".$row['cell_offc']."</td>
</tr>
<tr>
<td width='30%'>Office Location:</td>
<td width='65%' align='left' style='border: 1px solid #000000;' >".$row['office_loc']."</td>
</tr>
<tr>
<td width='30%'>Email Address:</td>
<td width='65%' align='left' style='border: 1px solid #000000;' >".$row['email_addr']."</td>
</tr>
<tr>
<td width='30%'>Job Title:</td>
<td width='65%' align='left' style='border: 1px solid #000000;' >".$row['job_title']."</td>
</tr>
</table>
</div>
<div style='float:right; width: 40%; border: '>
<table style='width: 100%; height: 175px; border: 1px solid #000000; padding: 3px; font-size: 90%; font-family: Arial, Helvetica, sans-serif;'>
<tr>
<th align='left'></th>
<th align='left'></th>
</tr>
<tr>
<td colspan='2' align='center' style='background: #000000; color: #ffffff;'>Customer Tax Information:</td>
</tr>
<tr>
<td>TIN#:</td>
<td align='left' style='border: 1px solid #000000;' >".$row['clnt_tin']."</td>
</tr>
<tr>
<td>VRN#</td>
<td align='left' style='border: 1px solid #000000;' >".$row['clnt_vrn']."</td>
</tr>
<tr>
<td>VAT Exempted:</td>
<td align='left' style='border: 1px solid #000000;'>".$row['vat_expt']."</td>
</tr>
<tr>
<td>Exemption Cert</td>
<td align='left' style='border: 1px solid #000000;' >".$row['expt_cert']."</td>
</tr>
<tr>
<td colspan='2' align='center' style='background: #000000; color: #ffffff;'>Our Tax Information:</td>
</tr>
<tr>
<td>TIN#:</td>
<td align='left' style='border: 1px solid #000000;'>".$row['our_tin']."</td>
</tr>
<tr>
<td>VRN#:</td>
<td align='left' style='border: 1px solid #000000;' >".$row['our_vrn']."</td>
</tr>
</table>
</div>
<div style='clear:both;'>
</div>
<div>
</div>
</div>";
$sample .= "<table style='width: 100%; font-family: Arial, Helvetica, sans-serif; ' >
<tr>
<th align='center' style='border: 1px solid #000000;' >Requested Date:</th>
<th align='center' style='border: 1px solid #000000;'>Requested By:</th>
<th align='center' style='border: 1px solid #000000;'>Sales Person:</th>
</tr >
<tr>
<td align='center' style='border: 1px solid #000000;'>".$row['date_created']."</td>
<td align='center' style='border: 1px solid #000000;'>".$row['prepared_by']."</td>
<td align='center' style='border: 1px solid #000000;'>".$row['sales_person']."</td>
</tr>
</table>";
$idfk = $row['inv_code']; // id for viewing
$subtotl = $row['sub_totl']; // id for viewing
$vattotl = $row['vat_percent']; // id for viewing
$grandtotl = $row['grand_total']; // id for viewing
$dis_perc_sub = $row['dis_perc_sub']; // id for viewing
$lpouser = $row['lpo_user']; // id for viewing
$lpostatus = $row['lpo_status']; // id for viewing
$servername = "...";
$username = "...";
$password = "...";
$dbname = "....";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$sql = "SELECT * FROM itemsinv WHERE invidfk='$idfk' ORDER BY ln_no ASC";
$result = mysqli_query($conn, $sql);
$count = 0;
$sample .= "<table cellspacing='1' cellpadding='1' style='width:100%; border: 1px solid black; font-family: Arial, Helvetica, sans-serif; margin-top: 20px 0 0 0;
th, td { padding: 5px;}' >
<tr>
<th align='center' style='background: #000000; color: #ffffff; '>No</th>
<th align='center' style='background: #000000; color: #ffffff; '>Product Details</th>
<th align='center' style='background: #000000; color: #ffffff; '>Price</th>
<th align='center' style='background: #000000; color: #ffffff; '>Qty</th>
<th align='center' style='background: #000000; color: #ffffff; '>Total</th>
</tr>";
if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
$count++;
$sample .= "<tr>
<td style='border: 1px solid black;'>" .$count. "</td>
<td style='border: 1px solid black;'><b>" . $row['productname']. "</b><br>" . $row['particulars']. "</td>
<td style='border: 1px solid black;'>". $row['price']. "</td>
<td style='border: 1px solid black;'>". $row['qty']. "</td>
<td style='border: 1px solid black;'>". $row['item_total']. "</td>
</tr>";
}
} else {
echo "0 results";
}
$sample .= "<tr><td align='right' colspan='4'><b>Sub Total:</b></td><td align='left' style='border: 1px solid #000000;'>".$subtotl."</td></tr>";
$sample .= "<tr><td align='right' colspan='4'><b>VAT Total:</b></td><td align='left' style='border: 1px solid #000000;'>".$vattotl."</td></tr>";
$sample .= "<tr><td align='right' colspan='4'><b>Discount %:</b></td><td align='left' style='border: 1px solid #000000;'>".$dis_perc_sub."</td></tr>";
$sample .= "<tr ><td align='right' colspan='4'><b>Grand Total:</b></td><td align='left' style='border: 1px solid #000000;'>".$grandtotl."</td></tr>";
$sample .= "</table>";
$sample .= "<br><b style='font-family: Arial, Helvetica, sans-serif; font-size: 70%;'>Please read our terms and conditions by visiting our website. http://signindustries.co.tz</b>";
mysqli_close($conn);
// create pdf of invoice
$invoiceFileName = 'Invoice-'. $row["contact_name"]. '.pdf';
require_once 'dompdf/src/Autoloader.php';
Dompdf\Autoloader::register();
use Dompdf\Dompdf;
$dompdf = new Dompdf();
$dompdf->loadHtml(html_entity_decode($sample));
$dompdf->setPaper('A4', 'portrait');
$dompdf->render();
$dompdf->stream($invoiceFileName, array("Attachment" => false));
?>
Error log below
Stack trace:
#0 /home/crmsignindustrie/public_html/crm/admins/dompdf/lib/Cpdf.php(4870): Imagick->writeimage('/tmp/cpdf_img_e...')
#1 /home/crmsignindustrie/public_html/crm/admins/dompdf/lib/Cpdf.php(4984): Cpdf->addImagePngAlpha('/home/crmsignin...', 45.265748031496, 737.92949241794, 187.5, 35.112359550562, 6)
#2 /home/crmsignindustrie/public_html/crm/admins/dompdf/src/Adapter/CPDF.php(864): Cpdf->addPngFromFile('/home/crmsignin...', 45.265748031496, 737.92949241794, 187.5, 35.112359550562)
#3 /home/crmsignindustrie/public_html/crm/admins/dompdf/src/Renderer/Image.php(110): Dompdf\Adapter\CPDF->image('/home/crmsignin...', 45.265748031496, 68.848148031496, 187.5, 35.112359550562, 'normal')
#4 /home/crmsignindustrie/public_html/crm/admins/dompdf/src/Renderer.php(293): Dompdf\Renderer\Image->render(Object(Dompdf\FrameDecorator\I in /home/crmsignindustrie/public_html/crm/admins/dompdf/lib/Cpdf.php on line 4870
[06-Jul-2020 13:58:06 UTC] PHP Warning: Version warning: Imagick was compiled against Image Magick version 1650 but version 1654 is loaded. Imagick will run but may behave surprisingly in Unknown on line 0
[06-Jul-2020 13:58:06 UTC] PHP Fatal error: Uncaught ImagickException: WriteBlob Failed `/tmp/cpdf_img_QpfKj7.png' # error/png.c/MagickPNGErrorHandler/1755 in /home/crmsignindustrie/public_html/crm/admins/dompdf/lib/Cpdf.php:4870
Stack trace:
#0 /home/crmsignindustrie/public_html/crm/admins/dompdf/lib/Cpdf.php(4870): Imagick->writeimage('/tmp/cpdf_img_Q...')
#1 /home/crmsignindustrie/public_html/crm/admins/dompdf/lib/Cpdf.php(4984): Cpdf->addImagePngAlpha('/home/crmsignin...', 45.265748031496, 737.92949241794, 187.5, 35.112359550562, 6)
#2 /home/crmsignindustrie/public_html/crm/admins/dompdf/src/Adapter/CPDF.php(864): Cpdf->addPngFromFile('/home/crmsignin...', 45.265748031496, 737.92949241794, 187.5, 35.112359550562)
#3 /home/crmsignindustrie/public_html/crm/admins/dompdf/src/Renderer/Image.php(110): Dompdf\Adapter\CPDF->image('/home/crmsignin...', 45.265748031496, 68.848148031496, 187.5, 35.112359550562, 'normal')
#4 /home/crmsignindustrie/public_html/crm/admins/dompdf/src/Renderer.php(293): Dompdf\Renderer\Image->render(Object(Dompdf\FrameDecorator\I in /home/crmsignindustrie/public_html/crm/admins/dompdf/lib/Cpdf.php on line 4870
[06-Jul-2020 13:59:05 UTC] PHP Warning: Version warning: Imagick was compiled against Image Magick version 1650 but version 1654 is loaded. Imagick will run but may behave surprisingly in Unknown on line 0
[06-Jul-2020 13:59:05 UTC] PHP Fatal error: Uncaught ImagickException: WriteBlob Failed `/tmp/cpdf_img_0wDRir.png' # error/png.c/MagickPNGErrorHandler/1755 in /home/crmsignindustrie/public_html/crm/admins/dompdf/lib/Cpdf.php:4870
Stack trace:
#0 /home/crmsignindustrie/public_html/crm/admins/dompdf/lib/Cpdf.php(4870): Imagick->writeimage('/tmp/cpdf_img_0...')
#1 /home/crmsignindustrie/public_html/crm/admins/dompdf/lib/Cpdf.php(4984): Cpdf->addImagePngAlpha('/home/crmsignin...', 45.265748031496, 737.92949241794, 187.5, 35.112359550562, 6)
#2 /home/host/public_html/crm/admins/dompdf/src/Adapter/CPDF.php(864): Cpdf->addPngFromFile('/home/crmsignin...', 45.265748031496, 737.92949241794, 187.5, 35.112359550562)
#3 /home/host/public_html/crm/admins/dompdf/src/Renderer/Image.php(110): Dompdf\Adapter\CPDF->image('/home/crmsignin...', 45.265748031496, 68.848148031496, 187.5, 35.112359550562, 'normal')
#4 /home/host/public_html/crm/admins/dompdf/src/Renderer.php(293): Dompdf\Renderer\Image->render(Object(Dompdf\FrameDecorator\I in /home/host/public_html/crm/admins/dompdf/lib/Cpdf.php on line 4870

Table and buttons in html and php with bootstrap

In this code that have to print a table and 3 buttons, the 3 buttons appear above the table but i want them under the table. What can I fix?
And how can i print them inline? I tried with a div with style display inline but doesn't work.
echo "<div class='container'>";
echo "<br>";
echo "<table class='table table-hover' style='border: 1px solid black; margin-left:auto; margin-right:auto;'><caption><h2>Esperienze di Lavoro</h2>
</caption> <thead> <tr>";
echo "<th style='border: 1px solid black;'> Username </th><th style='border: 1px solid black;'> Password </th><th style='border: 1px solid black;'> Nome </th> <th style='border: 1px solid black;'> Cognome </th> <th style='border: 1px solid black;'> Data di Nascita </th> <th style='border: 1px solid black;'> Email </th> <th style='border: 1px solid black;'> Foto </th>";
echo "</tr> </thead> <tbody> <tr>";
echo "<td style='border: 1px solid black;'>".$_COOKIE["username"]."</td>";
echo "<td style='border: 1px solid black;'>".$_COOKIE["password"]."</td>";
echo "<td style='border: 1px solid black;'>".$_COOKIE["name"]."</td>";
echo "<td style='border: 1px solid black;'>".$_COOKIE["surname"]."</td>";
echo "<td style='border: 1px solid black;'>".$_COOKIE["birth"]."</td>";
echo "<td style='border: 1px solid black;'>".$_COOKIE["mail"]."</td>";
echo "<td style='border: 1px solid black;'><img src=".$_COOKIE["foto"]." style='width:128px;height:128px;'></td>";
echo "</tr></tbody</table>";
echo "
<div class='form-group'>
<div class='col-sm-offset-2 col-sm-10'><button type='button' name='mod_nome' class='btn btn-primary' onclick='Funzione1()';>Modifica Informazioni</button></div>
</div>";
echo "<div class='form-group'>
<div class='col-sm-offset-2 col-sm-10'><button type='button' name='studio' class='btn btn-primary' onclick='Funzione2()';>Aggiungi Esperienze </button></div>
</div>";
echo "
<div class='form-group'>
<div class='col-sm-offset-2 col-sm-10'> <button type='button' name='comp' onclick='Funzione7()' class='btn btn-primary';>Compagnie in cui i nostri iscritti lavorano</button></div>
</div>";
I'm using bootstrap.
Your button code is fine, you just need to close <tbody></tbody>
echo "</tr></tbody></table>";
To align the buttons,
<style>
#btnSearch,
#btnClear{
display: inline-block;
vertical-align: top;
}
</style>
<div class="row">
<div class="col-sm-12 text-center">
<button id="btnSearch" class="btn btn-primary btn-md center-block" Style="width: 100px;">button-1</button>
<button id="btnClear" class="btn btn-danger btn-md center-block" Style="width: 100px;">button-2</button>
<button id="btnClear" class="btn btn-danger btn-md center-block" Style="width: 100px;">button-3</button>
</div>
</div>

How to increase width of a field in html page which has CSS and jQuery

I am new to programming, I have managed to create a page which fetches the data from MySQL.
I have used a jQuery plugin to freeze the first column and first row of my table.
The problem I am facing is, when I try to increase the width of a specific column it is not working.
Please help me to understand how do I increase width for specific column. This is my PHP and CSS for your reference.
Thanks.
PHP
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<title>Region Wise</title>
<link href="css/test.css" rel="stylesheet" media="screen" />
<header class="header">
<div class="titulosHeader">
<h2>Region Wise</h2>
</header>
</head>
<main class="main">
<div class="ContenedorTabla">
<?php
$sql = 'SELECT * from rgn_report';
$result = mysqli_query($con,$sql);
echo "<table id='pruebatabla' class='fht-table hoverTable'>
<thead>
<tr>
<th class='celda_encabezado_general' rowspan='3' style='height:100px;'>REGION</th>
<tr>
<th class='celda_encabezado_general' colspan='4'>KA</th>
<th class='space'></th>
<th class='celda_encabezado_general' colspan='4'>MI</th>
<th class='space'></th>
<th class='celda_encabezado_general' colspan='4'>OT</th>
<th class='space'></th>
<th class='celda_encabezado_general' colspan='4'>FA</th>
<th class='space'></th>
<th class='celda_encabezado_general' colspan='4'>HA</th>
</tr>
<tr>
<th class='celda_encabezado_general'>SOH</th>
<th class='celda_encabezado_general'>CY</th>
<th class='celda_encabezado_general'>CT</th>
<th class='celda_encabezado_general'>WC</th>
<th class='space'></th>
<th class='celda_encabezado_general'>SOH</th>
<th class='celda_encabezado_general'>CY</th>
<th class='celda_encabezado_general'>CT</th>
<th class='celda_encabezado_general'>WC</th>
<th class='space'></th>
<th class='celda_encabezado_general'>SOH</th>
<th class='celda_encabezado_general'>CY</th>
<th class='celda_encabezado_general'>CT</th>
<th class='celda_encabezado_general'>WC</th>
<th class='space'></th>
<th class='celda_encabezado_general'>SOH</th>
<th class='celda_encabezado_general'>CY</th>
<th class='celda_encabezado_general'>CT</th>
<th class='celda_encabezado_general'>WC</th>
<th class='space'></th>
<th class='celda_encabezado_general'>SOH</th>
<th class='celda_encabezado_general'>CY</th>
<th class='celda_encabezado_general'>CT</th>
<th class='celda_encabezado_general'>WC</th>
</tr>
</thead>";
echo "<tbody>";
while ($row = mysqli_fetch_array($result))
{
$rowhighlight = array("RGN1","RGN2","Grand Total");
if (in_array($row['rgn'],$rowhighlight)){
echo "<tr>";
echo "<td class='highlight_cell'>" . $row['rgn']."</td>";
echo "<td class='highlight_cell'>" . number_format($row['KA_SOH'])."</td>";
echo "<td class='highlight_cell'>" . number_format($row['KA_CY'])."</td>";
echo "<td class='highlight_cell'>" . number_format($row['KA_CT'])."</td>";
echo "<td class='highlight_cell'>" . $row['KA_CVR']."</td>";
echo "<td class='space'></td>";
echo "<td class='highlight_cell'>" . number_format($row['MI_SOH'])."</td>";
echo "<td class='highlight_cell'>" . number_format($row['MI_CY'])."</td>";
echo "<td class='highlight_cell'>" . number_format($row['MI_CT'])."</td>";
echo "<td class='highlight_cell'>" . $row['MI_CVR']."</td>";
echo "<td class='space'></td>";
echo "<td class='highlight_cell'>" . number_format($row['OT_SOH'])."</td>";
echo "<td class='highlight_cell'>" . number_format($row['OT_CY'])."</td>";
echo "<td class='highlight_cell'>" . number_format($row['OT_CT'])."</td>";
echo "<td class='highlight_cell'>" . $row['OT_CVR']."</td>";
echo "<td class='space'></td>";
echo "<td class='highlight_cell'>" . number_format($row['FA_SOH'])."</td>";
echo "<td class='highlight_cell'>" . number_format($row['FA_CY'])."</td>";
echo "<td class='highlight_cell'>" . number_format($row['FA_CT'])."</td>";
echo "<td class='highlight_cell'>" . $row['FA_CVR']."</td>";
echo "<td class='space'></td>";
echo "<td class='highlight_cell'>" . number_format($row['HA_SOH'])."</td>";
echo "<td class='highlight_cell'>" . number_format($row['HA_CY'])."</td>";
echo "<td class='highlight_cell'>" . number_format($row['HA_CT'])."</td>";
echo "<td class='highlight_cell'>" . $row['HA_CVR']."</td>";
echo "</tr>";}
else
{
echo "<tr>";
echo "<td class='excel_cell'>" . $row['rgn']."</td>";
echo "<td class='excel_cell'>" . number_format($row['KA_SOH'])."</td>";
echo "<td class='excel_cell'>" . number_format($row['KA_CY'])."</td>";
echo "<td class='excel_cell'>" . number_format($row['KA_CT'])."</td>";
echo "<td class='excel_cell'>" . $row['KA_CVR']."</td>";
echo "<td class='space'></td>";
echo "<td class='excel_cell'>" . number_format($row['MI_SOH'])."</td>";
echo "<td class='excel_cell'>" . number_format($row['MI_CY'])."</td>";
echo "<td class='excel_cell'>" . number_format($row['MI_CT'])."</td>";
echo "<td class='excel_cell'>" . $row['MI_CVR']."</td>";
echo "<td class='space'></td>";
echo "<td class='excel_cell'>" . number_format($row['OT_SOH'])."</td>";
echo "<td class='excel_cell'>" . number_format($row['OT_CY'])."</td>";
echo "<td class='excel_cell'>" . number_format($row['OT_CT'])."</td>";
echo "<td class='excel_cell'>" . $row['OT_CVR']."</td>";
echo "<td class='space'></td>";
echo "<td class='excel_cell'>" . number_format($row['FA_SOH'])."</td>";
echo "<td class='excel_cell'>" . number_format($row['FA_CY'])."</td>";
echo "<td class='excel_cell'>" . number_format($row['FA_CT'])."</td>";
echo "<td class='excel_cell'>" . $row['FA_CVR']."</td>";
echo "<td class='space'></td>";
echo "<td class='excel_cell'>" . number_format($row['HA_SOH'])."</td>";
echo "<td class='excel_cell'>" . number_format($row['HA_CY'])."</td>";
echo "<td class='excel_cell'>" . number_format($row['HA_CT'])."</td>";
echo "<td class='excel_cell'>" . $row['HA_CVR']."</td>";
echo "</tr>";
}
}
echo "</tbody>";
echo "</table>";
mysqli_close($con);
?>
</div>
</main>
<script src="js/jquery-1.11.0.min.js"></script>
<script src="js/jquery.CongelarFilaColumna.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#pruebatabla").CongelarFilaColumna({Columnas:1});
});
</script>
</body>
</html>
CSS
*{
margin: 0;
padding: 0;
border:0;
}
.header, .main {
display: inline-block;
height: auto;
width: 100%;
}
.titulosHeader {
height: auto;
}
.ContenedorTabla {
height: 540px;
border: 1px solid green;
overflow: auto;
position: relative;
max-width:auto;
}
.fht-table,
.fht-table thead,
.fht-table tfoot,
.fht-table tbody,
.fht-table tr,
.fht-table th,
.fht-table td
{
margin: 0;
}
.fht-table{
height: auto;
width: auto;
border-collapse: collapse;
border-spacing: 0;
border: 0 none;
table-layout:fixed;
}
.fht-table th,.fht-table td {
overflow: hidden;
table-layout:fixed;
}
.fht-table-wrapper,
.fht-table-wrapper .fht-thead,
.fht-table-wrapper .fht-tfoot,
.fht-table-wrapper .fht-fixed-column .fht-tbody,
.fht-table-wrapper .fht-fixed-body .fht-tbody,
.fht-table-wrapper .fht-tbody {
overflow: hidden;
position: relative;
}
.fht-table-wrapper .fht-fixed-body .fht-tbody,
.fht-table-wrapper .fht-tbody {
overflow: auto;
}
.fht-table-wrapper .fht-table .fht-cell {
overflow: hidden;
height: 1px;
}
.fht-table-wrapper .fht-fixed-column,
.fht-table-wrapper .fht-fixed-body {
top: 0;
left: 0;
position: absolute;
}
.fht-table-wrapper .fht-fixed-column {
z-index: 1;
}
.fht-fixed-body .fht-thead table {
margin-right: 20px;
border: 0 none;
}
.celda_encabezado_general {
background-color: #4BACC6;
border: 1px solid black;
color: #ffffff;
text-align: center;
font-size: 12px;
font-family: Calibri, sans-serif;
white-space: nowrap;
}
._Separador{
background-color: #fff;
height: 12px;
border-left: 1px solid #ccc;
border-right: 1px solid #ccc;
width: 7px;
}
._Separador div{
width: 4px;
}
.celda_normal {
background-color: #fff;
border: 1px solid #ccc;
padding: 2px 4px;
}
.excel_cell{
border: 1px solid black;
color: #222;
text-align: center;
font-size: 11px;
font-weight: normal;
padding: 5px;
empty-cells: show;
font-family: Calibri, sans-serif;
white-space: nowrap;
}
._cell_header{
background-color: #EEE;
}
._cell_Default{
background-color: #FFF;
text-align: left;
}
.excel_cell div{
width: 30px;
height: 20px;
}
.highlight_cell{
border: 2px solid black;
color: #222;
text-align: center;
font-size: 11px;
font-weight: bold;
padding: 5px;
empty-cells: show;
font-family: Calibri, sans-serif;
white-space: nowrap;
}
.hoverTable tr:hover {
background-color: grey;
}
.space{
border: none;
empty-cells: show;
background-color:grey;
width:10px;
}

Unable to upload .avi files using php form

have tried uploading .avi video formats but the page just refreshes and the file is not uploaded all other types type images and everything is getting uploaded im posting my code here look for file uploding sections with cwf and ve
<?php
$n=5;
$exp_no="";
$shot_no="";
$file_name1="";
$file_name2="";
$remarks="";
$cwf="";
$vedio="";
$conn=mysqli_connect("localhost","root","","project");
if(!$conn){
die("connection failed");
echo "<br/>";
}
$query="select stage from experimentdetails where NO='{$exp_no}'";
$res=mysqli_query($conn,$query);
if(mysqli_num_rows($res)>0){
$r=mysqli_fetch_row($res);
$n=$r[0];
}
session_start();
$exp_no=$_SESSION["expno_add"];
$s=mysqli_query($conn,"select ShotNo from shotdetails where ExpNo='{$exp_no}'");
$res=mysqli_fetch_row($s);
$shot_no=$res[0];
if(isset($_POST["submit"]))
{
$remarks=$_POST["remarks"];
$cap=array(8);
$off=array(8);
$cv=array(8);
$cptp=array(8);
$pul=array(8);
$del=array(8);
$vel=array(8);
for($i=0;$i<8;$i++)
{
if($i<$n)
{
$j=$i+1;
$cap[$i]=$_POST["cv{$j}"];
$off[$i]=$_POST["off{$j}"];
$cv[$i]=$_POST["cc{$j}"];
$cptp[$i]=$_POST["cpt{$j}"];
$pul[$i]=$_POST["pw{$j}"];
$del[$i]=$_POST["del{$j}"];
$vel[$i]= $_POST["vel{$j}"];
}
else{
$cap[$i]=0;
$off[$i]=0;
$cv[$i]=0;
$cptp[$i]=0;
$pul[$i]=0;
$del[$i]=0;
$vel[$i]=0;
}
}
if($_FILES['cwf']['name']!="")
{
$fname=$_FILES["cwf"];
$uploaddir = 'cwf/';
if (is_uploaded_file($fname['tmp_name']))
{
$filname = basename($fname['name']);
$uploadfile = $uploaddir . basename($fname['name']);
if (move_uploaded_file ($fname['tmp_name'], $uploadfile))
$r = "File " . $filname . " was successfully uploaded and stored.<br>";
else
$r = "Could not move ".$fname['tmp_name']." to ".$uploadfile."<br>";
}
else
$r = "File ".$fname['name']." failed to upload.";
$file_name1='cwf/'.$file_name1;
}
if($_FILES['ve']['name']!="")
{
$fname=$_FILES["ve"];
$uploaddir = 'upload/';
if (is_uploaded_file($fname['tmp_name']))
{
$filname = basename($fname['name']);
$uploadfile = $uploaddir . basename($fname['name']);
if (move_uploaded_file ($fname['tmp_name'], $uploadfile))
$r = "File " . $filname . " was successfully uploaded and stored.<br>";
else
$r = "Could not move ".$fname['tmp_name']." to ".$uploadfile."<br>";
}
else
$r = "File ".$fname['name']." failed to upload.";
$file_name2='upload/'.$file_name2;
}
$query="insert into shotdetails values($shot_no,$cap[0],$cap[1],$cap[2],$cap[3],$cap[4],$cap[5],$cap[6],$cap[7],$off[0],$off[1],$off[2],$off[3],$off[4],$off[5],$off[6],$off[7],$cptp[0],$cptp[1],$cptp[2],$cptp[3],$cptp[4],$cptp[5],$cptp[6],$cptp[7],$pul[0],$pul[1],$pul[2],$pul[3],$pul[4],$pul[5],$pul[6],$pul[7],$del[0],$del[1],$del[2],$del[3],$del[4],$del[5],$del[6],$del[7],$vel[0],$vel[1],$vel[2],$vel[3],$vel[4],$vel[5],$vel[6],$vel[7],$file_name1,$file_name2,$remarks,$exp_no,$cv[0],$cv[1],$cv[2],$cv[3],$cv[4],$cv[5],$cv[6],$cv[7])";
mysqli_query($conn,$query);
}
mysqli_close($conn);
?>
<html>
<head>
<title>ADD Shot</title>
<style>
select {
padding:3px;
margin: 0;
-webkit-border-radius:4px;
-moz-border-radius:4px;
border-radius:4px;
-webkit-box-shadow: 0 3px 0 #ccc, 0 -1px #fff inset;
-moz-box-shadow: 0 3px 0 #ccc, 0 -1px #fff inset;
box-shadow: 0 3px 0 #ccc, 0 -1px #fff inset;
background: #f8f8f8;
color:#888;
border:none;
outline:none;
display: inline-block;
-webkit-appearance:none;
-moz-appearance:none;
appearance:none;
cursor:pointer;
}
/* Targetting Webkit browsers only. FF will show the dropdown arrow with so much padding. */
#media screen and (-webkit-min-device-pixel-ratio:0) {
select {padding-right:18px}
}
label {position:relative}
label:after {
content:'<>';
font:11px "Consolas", monospace;
color:#aaa;
-webkit-transform:rotate(90deg);
-moz-transform:rotate(90deg);
-ms-transform:rotate(90deg);
transform:rotate(90deg);
right:8px; top:2px;
padding:0 0 2px;
border-bottom:1px solid #ddd;
position:absolute;
pointer-events:none;
}
label:before {
content:'';
right:6px; top:0px;
width:20px; height:20px;
background:#f8f8f8;
position:absolute;
pointer-events:none;
display:block;
}
.c ul li {
margin-top: 11px;
margin-right: 6px;
padding: 0px;
display: inline-block;
font-family: open-sans, Araial, Helvetica, sans-serif;
font-size:14px;
}
.c li a {
margin-left: 10px;
color:black;
padding-right: 20px;
text-decoration: none;
}
.c{
margin-left: 20px;
border-right: 1px solid rgba(1,1,1,0.20);
border-left: 1px solid rgba(1,1,1,0.20);
border-radius:5px;
width:98%;
margin-top: 10px;
}
#nav {
height: 40px;
border-radius:3px;
background-color: #f2f2f2;
border-bottom: 1px solid #ccc;
border-top: 1px solid #ccc;
}
</style>
</head>
<body>
<div class="c">
<ul id="nav">
<li style="border-right:1px solid rgba(1,1,1,0.65);">
Add Experiment
</li>
<li style="border-right:1px solid rgba(1,1,1,0.65);">
Modify Experiment
</li>
<li style="border-right:1px solid rgba(1,1,1,0.65);">
Delete Experiment
</li>
<li style="border-right:1px solid rgba(1,1,1,0.65);">
Create New Shot
</li>
<li style="border-right:1px solid rgba(1,1,1,0.65);">
Delete Shot
</li>
<li style="border-right:1px solid rgba(1,1,1,0.65);">
Add Component
</li>
<li style="border-right:1px solid rgba(1,1,1,0.65);">
Modify Component
</li>
<li style="border-right:1px solid rgba(1,1,1,0.65);">
Delete Component
</li>
</ul>
</div>
<center style="margin-top:5%">
<form action="add_shot1.php" method="POST" name="add" enctype="multipart/form-data">
<table cellspacing="4" cellpadding="4" class="cap">
<tr>
<th>Stage No.</th>
<th>Charging Voltage(kV)</th>
<th>Offset(mm)</th>
<th>Coil Current(kA)</th>
<th>Current Pulse Time period(ms)</th>
<th>Pulse Width(ms)</th>
<th>Delay(ms)</th>
<th>Velocity</th>
</tr>
<?php
for ($x = 1; $x <= $n; $x++) {
echo "<tr>";
echo "<td align='center'>" . $x . "</td>";
echo "<td align='center' ><input type='number' class='text' name='cv{$x}' value='' style=' height:30px;'/></td>";
echo "<td align='center'><input type='number' class='text' name='off{$x}' value=''style=' height:30px;'/></td>";
echo "<td align='center' ><input type='number' class='text' name='cc{$x}' value=''style=' height:30px;'/></td>";
echo "<td align='center' ><input type='number' class='text' name='cpt{$x}' value=''style=' height:30px;'/></td>";
echo "<td align='center' ><input type='number' class='text' name='pw{$x}' value=''style=' height:30px;'/></td>";
echo "<td align='center' ><input type='number' class='text' name='del{$x}' value=''style=' height:30px;'/></td>";
echo "<td align='center' ><input type='number' class='text' name='vel{$x}' value=''style=' height:30px;'/></td>";
echo"</tr>";
}
?>
<tr>
<td colspan='4'> Current wave form file: &nbsp <input type='file' name='cwf' value='' class='text'/> </td>
</tr>
<tr >
<td colspan='4' >Video File: <input type='file' name='ve' value='' class='text'/></td>
<td></td>
<td></td>
</tr>
<tr>
<td>Remarks</td>
<td><textarea rows="10" cols="40" name="remarks" value=""></textarea></td>
</tr>
<tr>
<td colspan=4 align='center'><input type="submit" name="submit" value="submit" /></td>
</tr>
</table>
</form>
</center>
</body>
</html>

PHP alternating colors

$dbc = mysql_connect('localhost','root','') or die (mysql_error());
mysql_select_db('payroll') or die (mysql_error());
$sql = "SELECT * FROM employee ORDER BY employee_id DESC";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result)) {
echo "
<tr>
<td style=\"padding-left: 20px; border-bottom: 1px solid #999; border-right: 1px solid #999;\">".$row['first_name']." ".$row['last_name']."</td>
<td style=\"text-align: center; border-bottom: 1px solid #999; border-right: 1px solid #999; padding-top: 2px ; padding-bottom: 3px ;\"><input type=\"button\" name=\"edit\" value=\"Edit\" class=\"selbtn\"> <input type=\"button\" name=\"delete\" value=\"Delete\" class=\"selbtn\"></td>
</tr>
";
}
I wanted to add an alternating color in the loop. what code should I add?
$rowCount = 0;
$colorOne = '#ffffff';
$colorTwo = '#f3f3f3';
while($row = mysql_fetch_array($result)){
$rowColor = ($rowCount % 2) ? $colorOne : $colorTwo;
echo "<element bgcolor='$rowColor'></element>";
$rowCount++;
}
Edited after #Jayrox comment.
Use CSS classes instead of inline styles. They're easier to manipulate. Then style the .myclass_row_0 and .myclass_row_1 in your CSS for the alternate row color as well as .col1 and .col2 for the column styles.
$c=1; // or 0 (added after deceze's comment)
while($row = mysql_fetch_array($result)) {
$c=1-$c; // magic!
echo "
<tr class=\"myclass_row_$c\">
<td class=\"col1\">".$row['first_name']." ".$row['last_name']."</td>
<td class=\"col2\"><input type=\"button\" name=\"edit\" value=\"Edit\" class=\"selbtn\"> <input type=\"button\" name=\"delete\" value=\"Delete\" class=\"selbtn\"></td>
</tr>
";
}
Or using inline styles:
$colors = array('#ffffff','#f3f3f3');
$c=1;
while($row = mysql_fetch_array($result)) {
$c=1-$c;
echo "
<tr style=\"background-color:{$colors[$c]};\">
<!-- tds here -->
</tr>
";
}
Or using preset classes:
$styles = array('odd','even');
$c=1;
while($row = mysql_fetch_array($result)) {
$c=1-$c;
echo "
<tr class=\"{$styles[$c]}\">
<!-- ... -->
</tr>
";
}
There are already a lot of solutions, but this one use only two lines of css.
You can set specific css on even and odd rows:
tr:nth-child(even) {background: #CCC}
tr:nth-child(odd) {background: #FFF}
Usually, I will declare an index(int) value and increment for each time through the loop. Then do a check to see if index mod 2 = 1. If so, then output a tr with the style that you want to apply to show an alternating row.
$color = 0;
while($row = mysql_fetch_array($result)) {
if($color % 2 == 1){
echo "<tr>";
}else{
echo "<tr class=\"altRow\">";
}
echo "
<td style=\"padding-left: 20px; border-bottom: 1px solid #999; border-right: 1px solid #999;\">".$row['first_name']." ".$row['last_name']."</td>
<td style=\"text-align: center; border-bottom: 1px solid #999; border-right: 1px solid #999; padding-top: 2px ; padding-bottom: 3px ;\"><input type=\"button\" name=\"edit\" value=\"Edit\" class=\"selbtn\"> <input type=\"button\" name=\"delete\" value=\"Delete\" class=\"selbtn\"></td>
</tr>
";
$color++;
}
As it's bumped already, here is my 5 cents.
7 answers and not a single one using templates.
We can write a thousand articles of the templates necessity, but such an examples will always win.
So, based on the OP's code and stagas' answer:
business logic part:
$c = 1;
$DATA = array();
$sql = "SELECT * FROM employee ORDER BY employee_id DESC";
$result = mysql_query($sql) or trigger_error(mysql_error().$sql);
while($row = mysql_fetch_array($result)) {
$row['c'] = $c=1-$c;
$DATA[] = $row;
}
and template part:
<tr class="myclass_row_<?=$row['$c']?>">
<td class="col1"><?=$row['first_name']?> <?=$row['last_name']?></td>
<td class="col2">
<input type="button" name="edit" value="Edit" class="selbtn"> <input type="button" name="delete" value="Delete" class="selbtn">
</td>
</tr>
$color = 1;
while($row = mysql_fetch_array($result)) {
if($color == 1){
echo "
<tr>
<td style=\"padding-left: 20px; border-bottom: 1px solid #999; border-right: 1px solid #999;\">".$row['first_name']." ".$row['last_name']."</td>
<td style=\"text-align: center; border-bottom: 1px solid #999; border-right: 1px solid #999; padding-top: 2px ; padding-bottom: 3px ;\"><input type=\"button\" name=\"edit\" value=\"Edit\" class=\"selbtn\"> <input type=\"button\" name=\"delete\" value=\"Delete\" class=\"selbtn\"></td>
</tr>
";
$color = 2;
}
else
{
echo "
<tr>
<td style=\"padding-left: 20px; border-bottom: 1px solid #555; border-right: 1px solid #555;\">".$row['first_name']." ".$row['last_name']."</td>
<td style=\"text-align: center; border-bottom: 1px solid #555; border-right: 1px solid #555; padding-top: 2px ; padding-bottom: 3px ;\"><input type=\"button\" name=\"edit\" value=\"Edit\" class=\"selbtn\"> <input type=\"button\" name=\"delete\" value=\"Delete\" class=\"selbtn\"></td>
</tr>
";
}
$color = 1;
}
// here it is in less code
<?php
$dbc = mysql_connect('localhost','root','') or die (mysql_error());
mysql_select_db('payroll') or die (mysql_error());
$sql = "SELECT * FROM employee ORDER BY employee_id DESC";
$result = mysql_query($sql);
$colors = array('FFF', '000000'); // valid hex colors
$numOfColors = sizeOf($colors); $i = 0
while($row = mysql_fetch_array($result)) {
$i++;if($i>$numOfColors){$i=0;}
?>
<tr>
<td style="padding-left: 20px; border-bottom: 1px solid #<?=$colors[$i]?>; border-right: 1px solid #<?=$colors[$i]?>;"> <?=$row['first_name']?> <?=$row['last_name']?> </td>
<td style="text-align: center; border-bottom: 1px solid #<?=$colors[$i]?>; border-right: 1px solid #<?=$colors[$i]?>; padding-top: 2px ; padding-bottom: 3px ;"><input type="button" name="edit" value="Edit" class="selbtn"> <input type="button" name="delete" value="Delete" class="selbtn"></td>
</tr>
<?php
}
?>
Just keep track whether it is an alternating row with a Boolean. Initialize it to false before your loop, not it for each iteration, then you can set the row style based on its value. Something like:
...
$isAlternatingRow = false;
while($row = mysql_fetch_array($result)) {
echo "
<tr class=\"" . $isAlternatingRow ? "defaultRow" : "alternatingRow" . "\">
<td style=\"padding-left: 20px; border-bottom: 1px solid #999; border-right: 1px solid #999;\">".$row['first_name']." ".$row['last_name']."</td>
<td style=\"text-align: center; border-bottom: 1px solid #999; border-right: 1px solid #999; padding-top: 2px ; padding-bottom: 3px ;\"><input type=\"button\" name=\"edit\" value=\"Edit\" class=\"selbtn\"> <input type=\"button\" name=\"delete\" value=\"Delete\" class=\"selbtn\"></td>
</tr>
";
$isAlternatingRow = !($isAlternatingRow);
}
Then just define styles for tr.defaultRow td and tr.alternatingRow td.
$class="even"
while($row = mysql_fetch_array($result))
{
if($class == "even")
{
echo "<tr class='$class'>";
$class="odd"
}
else
{
echo "<tr class='$class'>";
$class="even";
}
...
}
I did it like this:
Remember to add a CSS class called "even", with styling of course.
<?php
include 'connect.php';
echo "<table id='hor-zebra'>";
$i = 0;
while($row = mysql_fetch_array($result))
{
if($i % 2 == 0)
{
echo "<tr class='even'>";
echo "<td>" . $row['something'] . "</td>";
echo "</tr>";
}
else
{
echo "<tr>";
echo "<td>" . $row['something'] . "</td>";
echo "</tr>";
}
$i++;
}
echo "</table>";
mysql_close($con);
?>
Using predefined color outside the loop.
$rowCount = 0;
$color = array('#ffffff','#f3f3f3');
while($row = mysql_fetch_array($result)){
$i = ($rowCount % 2);
echo "<element bgcolor='".$color["$i"]."'></element>";
$rowCount++;
}

Categories