Please help cant display image when I use php
$result = mysql_query("SELECT * FROM obs") or die(mysql_error());
echo "<center><table><tr><th width=200>Obs Number</th><th width=200>Name</th><th width=200>Purpose</th><th width=200>Date Of OB</th><th width=200>Destination</th><th width=200>Image</th></tr></center>";
while ($row = mysql_fetch_array($result)) {
echo '<tr>';
//cant display image
echo '<tr> <input type="hidden" name="showimage[]" value="'. $row['OBS_NUMBER'].'" >';
echo '<td width=200>' . $row['OBS_NUMBER'] . '</td>';
echo '<td width=200>' . $row['NAME'] . '</td>';
echo '<td width=200>' . $row['PURPOSE'] . '</td>';
echo '<td width=200>' . $row['DATE_OF_OB'] . '</td>';
echo '<td width=200>' . $row['DESTINATION'] . '</td>';
echo '<td width=200> <img src="data:image/jpeg;base64,' . base64_encode($row['imagesobs']) . '" width="250"></td>';
echo '</tr>';
}
Related
i have one table in locallhost ,In my table there is an item id,Now I want to send the id Related row to another page by clicking on EDIT . Thankful
The part of the program I think is difficult to write below
....
....
$response["travel"]=array();
while ($row = mysql_fetch_array($sql)) {
// Print out the contents of the entry
echo '<tr>';
echo '<td class="text-center">' . $i . '</td>';
echo '<td class="text-center">' . $row['companyname'] . '</td>';
echo '<td class="text-center">' . $row['cod'] . '</td>';
echo '<td class="text-center">' . $row['bigan'] . '</td>';
echo '<td class="text-center">' . $row['stop'] . '</td>';
echo '<td class="text-center">' . $row['date'] . '</td>';
echo '<td class="text-center">' . $row['time'] . '</td>';
echo '<td class="text-center">' . $row['price'] . '</td>';
echo '<td class="text-center">' .'EDIT' .'</td>';
$i++;
.......
.....
You don't use <?php inside strings, you use that when you've gone back into HTML mode. You should just concatenate the variable, like you do everywhere else
echo '<td class="text-center">' .'ویرایش' .'</td>';
EDITED
I have an sql query and I want to highlight the table row with a red highlight so that if the transaction_date = 0000-00-00 that whole row is highlighted with red. Here is the snippet of the code. The transaction_date shows the date that a specific training course was taken and if the course wasn't taken then the date that will be returned will be 0000-00-00. Any help would be greatly appreciated. Thank you.
$sql = "SELECT DATE_FORMAT(date_fluids, '%m/%d/%Y ') AS transaction_date, first_name, last_name, supervisor_group, trade, t_id, c_id, department_number, date_fluids, fluids_refresh, fluid_period, employee_type
FROM peopleinfo WHERE
(last_name LIKE '%$value1%' )
and
(trade LIKE '%$value2%')
and
(t_id LIKE '%$value3%')
and
(c_id LIKE '%$value4%')
and
(department_number LIKE '%$value5%')
and
(date_fluids LIKE '%$value6%')
and
(date_lock LIKE '%$value7%')
and
(date_confine LIKE '%$value8%')
and
(date_fall LIKE '%$value9%')
and
(supervisor_group LIKE '%$value10%')
AND
(employee_type='1')
ORDER BY last_name ASC";
$query = mysqli_query($conn, $sql);
$row = (mysqli_fetch_array($query));
if (!$query) {
die ('SQL Error: ' . mysqli_error($conn));
}
while ($row = mysqli_fetch_array($query))
{
if ($row['transaction_date'] == 0000-00-00){
echo '<tr class="highlight">';
echo '<td >' . $row['first_name']. '</td>';
echo '<td >' . $row['last_name']. '</td>';
echo '<td >' . $row['supervisor_group']. '</td>';
echo '<td >' . $row['trade']. '</td>';
echo '<td >' . $row['t_id']. '</td>';
echo '<td >' . $row['c_id']. '</td>';
echo '<td >' . $row['department_number']. '</td>';
echo '<td >' . $row['transaction_date']. '</td>';
echo '<td >'. $row['fluid_period']. '</td>';
echo '</tr>';
} else {
echo '<tr >';
echo '<td >' . $row['first_name']. '</td>';
echo '<td >' . $row['last_name']. '</td>';
echo '<td >' . $row['supervisor_group']. '</td>';
echo '<td >' . $row['trade']. '</td>';
echo '<td >' . $row['t_id']. '</td>';
echo '<td >' . $row['c_id']. '</td>';
echo '<td >' . $row['department_number']. '</td>';
echo '<td >' . $row['transaction_date']. '</td>';
echo '<td >'. $row['fluid_period']. '</td>';
echo '</tr>';
}
}
mysqli_free_result($query);
mysqli_close($conn);
?>
</tbody>
</table>
I would just do:
echo '<tr' . ($row['transaction_date'] === '0000-00-00' ? 'class="highlight"' : '') . '>
and then use css to highlight it however you want.
<!doctype html>
<?php
?>
<html>
<head>
<title>Midterm Review</title>
</head>
<body>
<h3>Tools Not Currently in Stock</h3>
<?php
$conn = mysqli_connect(This part works );
mysqli_select_db(this part works);
$query = "SELECT * FROM `midterm` WHERE stock='0'";
$result = mysqli_query($conn, $query);
echo '<table>';
echo '<tr><th>ID</th><th>Part Number</th><th>Description</th><th>Stock</th><th>Price</th><th>Received</th></tr>';
foreach ($result as $row) {
$row = mysqli_fetch_array($result);
echo '<tr>';
echo '<td>' . $row['id'] . '</td>';
echo '<td>' . $row['part_number'] . '</td>';
echo '<td>' . $row['description'] . '</td>';
echo '<td>' . $row['stock'] . '</td>';
echo '<td>' . $row['price'] . '</td>';
echo '<td>' . $row['received_date'] . '</td>';
echo '</tr>';
echo '</table>';
};
mysqli_close($conn);
?>
<!--<form method="post" action="midterm_confirmation.php">
<label>Part Number: </label><input type="text" name="partNumber" /><br />
<label>Description: </label><input type="text" name="description" /></br />
<label>Stock: </label><input type="number" name="stock" /><br />
<label>Price: </label><input type="text" name ="price" /></br />
<label>Received Date: </label><input type="text" name="receivedDate" /></br />
<input type="Submit" value="Add to Stock">
</form> -->
</body>
</html>
Basically my end result is that I am getting one table row, instead the two I am getting. Any suggestions? The table I have populates everything but is only running once, instead of posting for each line I have where stock is equal to zero.
See the snippet below. P.S. Don't mix templates and database layer, it's a bad smell...
<?php
// establish connection to $conn variable
$query = mysqli_query($conn, "SELECT * FROM `midterm` WHERE stock='0'");
echo '<table>';
echo '<tr><th>ID</th><th>Part Number</th><th>Description</th><th>Stock</th><th>Price</th><th>Received</th></tr>';
while ($row = mysqli_fetch_assoc($query)) {
echo '<tr>';
echo '<td>' . $row['id'] . '</td>';
echo '<td>' . $row['part_number'] . '</td>';
echo '<td>' . $row['description'] . '</td>';
echo '<td>' . $row['stock'] . '</td>';
echo '<td>' . $row['price'] . '</td>';
echo '<td>' . $row['received_date'] . '</td>';
echo '</tr>';
}
echo '</table>';
mysqli_close($conn);
?>
The problem is in closing of </table> It should be kept outside the loop.
while ($row = mysqli_fetch_assoc($query)) {
echo '<tr>';
echo '<td>' . $row['id'] . '</td>';
echo '<td>' . $row['part_number'] . '</td>';
echo '<td>' . $row['description'] . '</td>';
echo '<td>' . $row['stock'] . '</td>';
echo '<td>' . $row['price'] . '</td>';
echo '<td>' . $row['received_date'] . '</td>';
echo '</tr>';
// echo '</table>';// this is wrong.
};
echo '</table>';// this is correct. closing table inside loop is wrong, do it outside the loop.
You can simply use a while loop to do it like below:
<?php
// establish connection to $conn
$query = mysqli_query($conn, "SELECT * FROM `midterm` WHERE stock='0'");
echo '<table>';
echo '<tr><th>ID</th><th>Part Number</th><th>Description</th><th>Stock</th><th>Price</th><th>Received</th></tr>';
while ($row = mysqli_fetch_assoc($query)) {
echo '<tr>';
echo '<td>' . $row['id'] . '</td>';
echo '<td>' . $row['part_number'] . '</td>';
echo '<td>' . $row['description'] . '</td>';
echo '<td>' . $row['stock'] . '</td>';
echo '<td>' . $row['price'] . '</td>';
echo '<td>' . $row['received_date'] . '</td>';
echo '</tr>';
}
echo '</table>'; // this should be outside the loop
mysqli_close($conn);
?>
Or if you want to use a foreach then write an extra function for it:
<?php
function mysql_fetch_all($result) {
$rows = array();
while ($row = mysql_fetch_array($result)) {
$rows[] = $row;
}
return $rows;
}
// establish connection to $conn
$query = mysqli_query($conn, "SELECT * FROM `midterm` WHERE stock='0'");
echo '<table>';
echo '<tr><th>ID</th><th>Part Number</th><th>Description</th><th>Stock</th><th>Price</th><th>Received</th></tr>';
foreach (mysql_fetch_all($result) as $row){
echo '<tr>';
echo '<td>' . $row['id'] . '</td>';
echo '<td>' . $row['part_number'] . '</td>';
echo '<td>' . $row['description'] . '</td>';
echo '<td>' . $row['stock'] . '</td>';
echo '<td>' . $row['price'] . '</td>';
echo '<td>' . $row['received_date'] . '</td>';
echo '</tr>';
}
echo '</table>'; // this should be outside the loop
mysqli_close($conn);
?>
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>
Hello Im new in programing. I want to create a table using the alternate row color. But dont know how to do it. Here is my code. Please help me!
while ($row = mysqli_fetch_assoc($result)) {
echo '<tr>';
echo '<td>' . $row['a.ServiceID'] . '</td>';
echo '<td>' . $row['a.Title'] . '</td>';
echo '<td>' . $row['a.Description'] . '</td>';
echo '<td>' . $row['a.Notes'] . '</td>';
echo '<td>' . $row['a.SubmitBy'] . '</td>';
echo '<td>' . $row['a.AssignedEmp'] . '</td>';
echo '<td>' . $row['c.GroupName'] . '</td>';
echo '<td>' . $row['d.NameCategory'] . '</td>';
echo '<td>' . $row['e.TipoStatus'] . '</td>';
echo '<td>' . $row['f.TiposUrgencia'] . '</td>';
echo '<td>' . $row['g.CustomerName'] . '</td>';
echo '<td>' . $row['a.DayCreation'] . '</td>';
echo '<td>' . $row['a.ModifyBy'] . '</td>';
echo '<td>' . $row['a.ModifyTime'] . '</td>';
echo '</tr>';
}
mysqli_free_result($result);
echo '</table>';
$rowColors = Array('#FF0000','#00FF00'); $nRow = 0;
while ($row = mysqli_fetch_assoc($result)){
echo '<tr style="background-color:'.$rowColors[$nRow++ % count($rowColors)].';">';
// ....
echo '</tr>';
}
Or this could be edited to apply classes. Just place the class names in $rowColors, and change the echo to <tr class="'.$rowColors[...].'"> instead.
Working example can be found here.
$c = false;
while ($row = mysqli_fetch_assoc($result)) {
echo '<tr style="background:',(($c=!$c)? '#eee' : '#ddd' ),'">';
// ...
}
Or with CSS 3:
tr:nth-child(odd){ background:#eee; }
tr:nth-child(even){ background:#ddd; }
$rowColors = Array('#FFFFFF','#FF0000'); $i= 0;
while ($row = mysqli_fetch_assoc($result))
{
echo '<tr style="background-color:'.$rowColors[$i++ % count($rowColors)].';">';
echo '<td>' . $row['a.ServiceID'] . '</td>';
echo '<td>' . $row['a.Title'] . '</td>';
echo '<td>' . $row['a.Description'] . '</td>';
echo '<td>' . $row['a.Notes'] . '</td>';
echo '<td>' . $row['a.SubmitBy'] . '</td>';
echo '<td>' . $row['a.AssignedEmp'] . '</td>';
echo '<td>' . $row['c.GroupName'] . '</td>';
echo '<td>' . $row['d.NameCategory'] . '</td>';
echo '<td>' . $row['e.TipoStatus'] . '</td>';
echo '<td>' . $row['f.TiposUrgencia'] . '</td>';
echo '<td>' . $row['g.CustomerName'] . '</td>';
echo '<td>' . $row['a.DayCreation'] . '</td>';
echo '<td>' . $row['a.ModifyBy'] . '</td>';
echo '<td>' . $row['a.ModifyTime'] . '</td>';
echo '</tr>';
}
mysqli_free_result($result);
echo '</table>';
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" type="text/css" href="css/view.css">
<title>ShowList</title>
</head>
<body>
<table width="100%" height="830" border="0" cellspacing="0" cellpadding="0">
<tr>
<td colspan="3" align="left">
<?php include 'common/header.html'; ?>
</td>
</tr>
<tr>
<td colspan="3">
<?php include 'sepperatemunu.php'; ?>
</tr>
<tr height="720" width="1240" align="center" valign="middle">
<td>
<?php
$con=mysql_connect("localhost","root","");
if(!$con)
{
die('Could not Connect'.mysql_error());
}
mysql_select_db("USER", $con);
$color="1";
$row_count = 0;
$sql=mysql_query("select * from registration");
echo "<table border='1' width='100%' height='400' cellpadding='0' cellspacing='0' >
<tr>
<th>ID</th>
<th>Name</th>
<th>Age</th>
<th>DOB</th>
<th>Gender</th>
<th>MobileNo</th>
<th>Address</th>
<th>country</th>
<th>Modify</th>
</tr>";
?>
<?php
while($row=mysql_fetch_array($sql) )
{
if($color==1)
{
echo "<tr bgcolor='#FFFFFF'>";
echo "<td align='center'>" . $row['ID'] . "</td>";
echo "<td align='left'>" . $row['Name'] . "</td>";
echo "<td align='center'>" . $row['Age'] . "</td>";
echo "<td align='center'>" . $row['DOB'] . "</td>";
echo "<td align='center'>" . $row['Gender'] . "</td>";
echo "<td align='center'>" . $row['MobileNo'] . "</td>";
echo "<td align='left'>" . $row['Address'] . "</td>";
echo "<td align='center'>" . $row['Country'] . "</td>";
echo "<td align='center'>" ?>edit <?php "</td>";
echo "</tr>";
$color="2";
}
else
{
echo "<tr bgcolor='#808080'>";
echo "<td align='center'>" . $row['ID'] . "</td>";
echo "<td align='left'>" . $row['Name'] . "</td>";
echo "<td align='center'>" . $row['Age'] . "</td>";
echo "<td align='center'>" . $row['DOB'] . "</td>";
echo "<td align='center'>" . $row['Gender'] . "</td>";
echo "<td align='center'>" . $row['MobileNo'] . "</td>";
echo "<td align='left'>" . $row['Address'] . "</td>";
echo "<td align='center'>" . $row['Country'] . "</td>";
echo "<td align='center'>" ?>edit <?php "</td>";
echo "</tr>";
$color="1";
}
}
echo "</table>";
mysql_close($con);
?>
</td>
</tr>
<tr>
<td colspan="3" align="left">
<?php include 'common/footer.html'; ?>
</td>
</tr>
</table>
</body>
</html>
I think you want something like
$num = 0;
while ($row = mysqli_fetch_assoc($result)) {
$color= ($num % 2 == 0) ? 'color1' : 'color2';
$num++;
echo '<tr style="background-color:'.$color.';">';
echo '<td>' . $row['a.ServiceID'] . '</td>';
echo '<td>' . $row['a.Title'] . '</td>';
echo '<td>' . $row['a.Description'] . '</td>';
echo '<td>' . $row['a.Notes'] . '</td>';
echo '<td>' . $row['a.SubmitBy'] . '</td>';
echo '<td>' . $row['a.AssignedEmp'] . '</td>';
echo '<td>' . $row['c.GroupName'] . '</td>';
echo '<td>' . $row['d.NameCategory'] . '</td>';
echo '<td>' . $row['e.TipoStatus'] . '</td>';
echo '<td>' . $row['f.TiposUrgencia'] . '</td>';
echo '<td>' . $row['g.CustomerName'] . '</td>';
echo '<td>' . $row['a.DayCreation'] . '</td>';
echo '<td>' . $row['a.ModifyBy'] . '</td>';
echo '<td>' . $row['a.ModifyTime'] . '</td>';
echo '</tr>';
}
mysqli_free_result($result);
echo '</table>';
Use some binary variable to store the row color state in:
$colored = false;
while($row = mysqli_fetch_assoc($result)) {
// depending on the state of colored, choose color:
if($colored)
echo '<tr style=\"background-color:lightgray;\">';
else
echo '<tr style=\"background-color:white;\">'; // or '<tr>';
// change the state of $colored:
$colored = !$colored;
echo '<td>' . ...
...
echo '</tr>';
}
You can place the style information in your css (e.g. in two classes "backgroundbright" and "backgroundlow") and add these definitions to your trs:
// depending on the state of colored, choose color:
if($colored)
echo '<tr class=\"backgroundlow\">';
else
echo '<tr class=\"backgroundbright\">'; // or '<tr>';