I need to change a value depending a result.
In this case, if my row "status" is "Active" I want to put something like that in a table:
<td>'.$row['register_status'].'</td>
<td>'if($row['status']=='Active'){print "<span class="glyphicon glyphicon-time" aria-hidden="true" style="color:orange"></span>";}'</td>
<td>'.$row['register_status'].'</td>
What is wrong?
Edit: Sorry. I did not put all code. Here starting my array and I put with quotes your code but can't run
if(mysql_num_rows($result) > 0)
{
$number = 1;
while($row = mysql_fetch_assoc($result))
{
$data .= '<tr>
<td>'.$row['register_status'].'</td>
<td>'
if($row['status']=='Active')
{
echo '<span class="glyphicon glyphicon-time" aria-hidden="true" style="color:orange"></span>';
}
'</td>
</tr>';
$number++;
}
}
else
{
// records now found
$data .= '<tr><td colspan="6">Records not found!</td></tr>';
}
$data .= '</table>';
echo $data;
Related
I wanna do if in by my status field.
if my status is "blocked" so the font background color will be in red and if the status is "authorized" so in green.
how should i do that?
foreach($data as $row)
{
$output .= '
<tr>
<td>'.$row->client_name.'</td>
<td>'.$row->adrress.'</td>
<td>'.$row->occupation.'</td>
<td>'.$row->payeee.'</td>
<td>'.$row->status.'</td>
</tr>
';
}
Try this
foreach($data as $row)
{
$output .= '
<tr>
<td>'.$row->client_name.'</td>
<td>'.$row->adrress.'</td>
<td>'.$row->occupation.'</td>
<td>'.$row->payeee.'</td>
#if($row->status == "blocked")
<td> <button type="button" class="btn btn-danger">blocked</button> </td>
#elseif($row->status == "authorized")
<td> <button type="button" class="btn btn-success">authorized</button> </td>
#endif
</tr>
OR
foreach($data as $row){
$output .= '
<tr>
<td>'.$row->client_name.'</td>
<td>'.$row->adrress.'</td>
<td>'.$row->occupation.'</td>
<td>'.$row->payeee.'</td>';
if($row->status == "bad"){
$output .= '<td style="background-color:red;">'.$row->status.'</td>';
} else if($row->status == "good") {
$output .= '<td style="background-color:green;">'.$row->status.'</td>';
}
$output .= '</tr>';
}
You shouldn't really be dealing with view logic in your controller.
But to do what you want in the controller
foreach($data as $row){
$output .= '
<tr>
<td>'.$row->client_name.'</td>
<td>'.$row->adrress.'</td>
<td>'.$row->occupation.'</td>
<td>'.$row->payeee.'</td>';
if($row->status == "bad"){
$output .= '<td style="background-color:red;">'.$row->status.'</td>';
} else if($row->status == "good") {
$output .= '<td style="background-color:green;">'.$row->status.'</td>';
}
$output .= '</tr>';
}
However what you should do is handle it in your blade file. Also you probably want to create styles in your style sheet and apply classes rather than inline the css.
this is the code that worked
foreach($data as $row){
$output .= '
<tr>
<td>'.$row->client_name.'</td>
<td>'.$row->adrress.'</td>
<td>'.$row->occupation.'</td>
<td>'.$row->payeee.'</td>';
if($row->status == "bad"){
$output .= '<td style="background-color:red;">'.$row->status.'</td>';
} else if($row->status == "good") {
$output .= '<td style="background-color:green;">'.$row->status.'</td>';
}
$output .= '</tr>';
}
page1, the code, below, works fine and lists recipe names i.e. BBQ Pork etc
<form action="recipe_show.php" method="post">
<?php
$result = mysql_query("SELECT recipe_name FROM recipes ORDER BY recipe_name ASC"); // Run the query
if ($result) { // If it ran OK, display the records
// Table header
echo '<table>
<td align="left"><b>Recipe Name</b></td>
</tr>';
// Fetch and print all the records
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo '<tr>
<td>'. $row['recipe_name'] .'</td>
</tr>';
}
echo '</table>'; // Close the table
mysql_free_result ($result); // Free up the resources
} else { // If it did not run OK
// Message
echo '<p class="error">The current recipe_name could not be retrieved. We apologize for any inconvenience.</p>';
// Debugging message
echo '<p>' . mysql_error($dbcon) . '<br><br />Query: ' . $q . '</p>';
} // End of if ($result)
mysql_close($dbcon); // Close the database connection.
?></p>
</form>
</div>
When I click the link, from page1, it opens page2. I get the headings but not the data for the BBQ Pork link. Below is the code on page2.
<form action="" method="post">
<?php
$recipe = mysql_real_escape_string($_GET['recipe_name']); //if using mysql
$myresult = "SELECT * FROM recipes WHERE recipe_name = '".$recipe. "'";
$num = mysql_num_rows($myresult);
for ($i = 0; $i < $num; $i++){
$row = mysql_fetch_array($myresult, MYSQL_ASSOC);
$row = (($i % 2) == 0) ? "table_odd_row" : "table_even_row";
echo "<tr row=".$row.">";
}
if ($myresult) { // If it ran OK, display the records
echo '<table>
<td width="250" align="center"><b>Recipe Name</b></td>
<td width="250" align="left"><b>Instructions</b></td>
<td width="250" align="left"><b>Directions</b></td>
<td width="250" align="left"><b>Notes</b></td>
</tr>';
while ($row = mysql_fetch_array($myresult, MYSQL_ASSOC)) {
echo '<tr>
<td align="left">' . $row['recipe_name'] . '</td>
<td align="left">' . $row['ingredients'] . '</td>
<td align="left">' . $row['directions'] . '</td>
<td align="left">' . $row['notes'] . '</td>
</tr>';
}
echo '</table>'; // Close the table
mysql_free_result ($myresult); // Free up the resources
} else {
echo '<p row="error">The current Recipe could not be retrieved. We apologize for any inconvenience.</p>';
echo '<p>' . mysql_error($dbcon) . '<br><br />Query: ' . $q . '</p>';
} ($myresult)
mysql_close($dbcon); // Close the database connection.
?>
Hope I have correctly set this out? Many thanks, in advance, for help and guidence
How can I join this table together, showing the header only once? I have tried to take th out of the while loop but I had no luck, maybe I made a mistake?
Here is my code so far:
<?php
function cart() {
foreach($_SESSION as $name => $value) {
if ($value>0){
if (substr($name, 0, 5)=='cart_') {
$id = substr($name, 5, (strlen($name)-5));
$get = mysql_query('SELECT id, name, price FROM products WHERE id='.mysql_real_escape_string((int)$id));?>
<center>
<table class='menufinal' border=0 width=75%>
<th>Remove Item</th>
<th>Item Name</th>
<th>Item Price</th>
<th>Quantity</th>
<th>Line Total</th>
<?php while ($get_row = mysql_fetch_assoc($get)) {
$sub = $get_row['price']*$value;?>
<tr>
<td><?echo '<img src="x.png"><br>'?></td>
<td><?echo $get_row['name']?></td>
<td><?echo '£' . number_format($get_row['price'], 2);?></td>
<td><?echo '- ' .$value. ' +' ?> </td>
<td> <?echo '£ ' . number_format($sub, 2);?> </td>
</tr>
<?
}
}
if (empty($total)) {
if (empty($sub)) {
//do nothing
} else {
$total = $sub;
}
} else {
$total += $sub;
}
}
}
if (!empty($total)){
echo '<br>Total: £' . number_format($total, 2) . '<br>';
echo '<div id="dorc"><p><img src="dishes.png" width="240" height="152"> <img src="spacer.png" width="200"> <img src="checkout.png" width="240" height="152">';
} else {
header ('Location: index.php');
}
}
?>
Currently this code displays:
Change the script as follow. Hope it will work
$value) {
if ($value>0){
if (substr($name, 0, 5)=='cart_') {
$id = substr($name, 5, (strlen($name)-5));
$get = mysql_query('SELECT id, name, price FROM products WHERE id='.mysql_real_escape_string((int)$id));?>
if($i==0)
{
print("
<center>
<table class='menufinal' border=0 width=75%>
<th>Remove Item</th>
<th>Item Name</th>
<th>Item Price</th>
<th>Quantity</th>
<th>Line Total</th>
</tr>
");
}
$i++;
while ($get_row = mysql_fetch_assoc($get)) {
$sub = $get_row['price']*$value;?>
<tr>
<td><?echo '<img src="x.png"><br>'?></td>
<td><?echo $get_row['name']?></td>
<td><?echo '£' . number_format($get_row['price'], 2);?></td>
<td><?echo '- ' .$value. ' +' ?> </td>
<td> <?echo '£ ' . number_format($sub, 2);?> </td>
</tr>
<?
}
}
if (empty($total)) {
if (empty($sub)) {
//do nothing
} else {
$total = $sub;
}
} else {
$total += $sub;
}
}
}
if (!empty($total)){
echo '<br>Total: £' . number_format($total, 2) . '<br>';
echo '<div id="dorc"><p><img src="dishes.png" width="240" height="152"> <img src="spacer.png" width="200"> <img src="checkout.png" width="240" height="152">';
} else {
header ('Location: index.php');
}
}
?>
Below is the corrected code, the creation of the table is moved outside of the loop.
Also the table header was added into a tr to create valid html, and also collected data into an $output variable to prevent a bug with your location redirect since data would already be written to the browser (you may vary well still have a problem with this since there is likely other output prior to this cart() function being called.
<?php
function cart() {
$output = '';
$output .= '<center>';
$output .= '<table class='menufinal' border=0 width=75%>';
$output .= '<tr>';
$output .= '<th>Remove Item</th>';
$output .= '<th>Item Name</th>';
$output .= '<th>Item Price</th>';
$output .= '<th>Quantity</th>';
$output .= '<th>Line Total</th>';
$output .= '</tr>';
foreach($_SESSION as $name => $value) {
if ($value>0){
if (substr($name, 0, 5)=='cart_') {
$id = substr($name, 5, (strlen($name)-5));
$get = mysql_query('SELECT id, name, price FROM products WHERE id='.mysql_real_escape_string((int)$id));
while ($get_row = mysql_fetch_assoc($get)) {
$sub = $get_row['price']*$value;
$output .= '<tr>';
$output .= '<td><img src="x.png"><br></td>';
$output .= '<td>' . $get_row['name'] . '</td>';
$output .= '<td>£ ' . number_format($get_row['price'], 2) . '</td>';
$output .= '<td>- ' .$value. ' +</td>';
$output .= '<td>£ ' . number_format($sub, 2) . '</td>';
$output .= '</tr>';
}
}
if (empty($total)) {
if (empty($sub)) {
//do nothing
} else {
$total = $sub;
}
} else {
$total += $sub;
}
}
}
$output .= '</table>';
if (empty($total)){
header ('Location: index.php');
exit;
}
$output .= '<br>Total: £' . number_format($total, 2) . '<br>';
$output .= '<div id="dorc"><p><img src="dishes.png" width="240" height="152"> <img src="spacer.png" width="200"> <img src="checkout.png" width="240" height="152">';
echo $output;
}
?>
I am designing a table that retrieved from database and when user hover on of the value in the table, it should gather the corresponding data from the db and show it on tooltip. when i do select query for all value in the table, the tooltip doesnt work. But when I query only 1 particular item in the database it works like a charm. I dont know whats wrong with this. Please help me,
code,
$fabSql = "SELECT FABRICATION.*,
MASTER_DRAWING.WEIGHT
FROM FABRICATION, MASTER_DRAWING
WHERE FABRICATION.HEAD_MARK = MASTER_DRAWING.HEAD_MARK";
$fabParse = oci_parse($conn, $fabSql);
oci_execute($fabParse);
while (($row = oci_fetch_array($fabParse, OCI_BOTH)) != false)
{
$totalFabPercentage = (($row['MARKING']*$markingPercentage)+($row['CUTTING']*$cuttingPercentage)+($row['ASSEMBLY']*$assemblyPercentage)+
($row['WELDING']*$weldingPercentage)+($row['DRILLING']*$drillingPercentage)+($row['FINISHING']*$finishingPercentage));
echo '<tr>';
echo '<td>'.$row['HEAD_MARK'].'</td>';
echo '<td>'.$row['ID'].'</td>';
if ($row['MARKING'] == 1){
echo '<td align="center" title="SIGNED BY : '.$row['MARKING_FAB_SIGN'].' on '.$row['MARKING_FAB_DATE'].'" class="jquery-tooltipped"><span class="glyphicon glyphicon-ok greenyellow"></span>';
} elseif ($row['MARKING'] == 0) {
echo '<td align="center"><span class="glyphicon glyphicon-refresh grey"></span>';
} else {
echo '<td align="center"><span class="glyphicon glyphicon-flag red"></span>';
}
if ($row['CUTTING'] == 1){
echo '<td align="center"><span class="glyphicon glyphicon-ok greenyellow"></span>';
} elseif ($row['CUTTING'] == 0) {
echo '<td align="center"><span class="glyphicon glyphicon-refresh grey"></span>';
} else {
echo '<td align="center"><span class="glyphicon glyphicon-flag red"></span>';
}
}
}
but when i do query like this, the tooltip works,
$fabSql = "SELECT FABRICATION.*,
MASTER_DRAWING.WEIGHT
FROM FABRICATION, MASTER_DRAWING
WHERE FABRICATION.HEAD_MARK = MASTER_DRAWING.HEAD_MARK
AND FABRICATION.HEAD_MARK = 'SMS-MH-BM1'";
How to make it like only 3 offers in row NOW I have one row and all offer is in one line I just want to to show max 3 td in tr and loop.
if(count($offer_list['item']) > 0)
{
$main_content .= '<table cellspacing="2" cellpadding="2" width=30>';
foreach($offer_list['item'] as $item)
{
$main_content .= '<td class="shop">
<a class="shop" style="display: block;" href="/shop/item/id/'.$item['id'].'">
<center><img src="item_images/'.$item['item_id'].'.gif"><br><font color="white"><b>'.$item['name'].'</font></b><font color="red"> <b> '.$item['points'].' points</font></b>';
if(!$logged)
{
$main_content .= '<p><b>[Login to buy]</b>';
}
else
{
$main_content .= '<br><b><font size=1 color="white">Your points balance is: '.$user_premium_points;
$main_content .= '<br><font color="white"> <fieldset class="shop"><legend>DESCRIPTION</legend>'.$item['description'].'</fieldset></font><br><font color="white"><b> [Click to buy] </b></font></form> </a></center></td>';
}
$main_content .= '';
}
$main_content .= '</tr></table>';
}
$row_count = 1;
$main_content .= '<table cellspacing="2" cellpadding="2" width=30>';
foreach($offer_list['item'] as $item) {
// Check, if we are at position "1". If so, start new row
if ($row_count === 1) { $main_content .= '<tr>'; }
$main_content .= '<td class="shop"><a class="shop" style="display: block;" href="/shop/item/id/'.$item['id'].'">
<center><img src="item_images/'.$item['item_id'].'.gif"><br><font color="white"><b>'.$item['name'].'</font></b><font color="red"> <b> '.$item['points'].' points</font></b>';
if(!$logged) {
$main_content .= '<p><b>[Login to buy]</b>';
}
else {
$main_content .= '<br><b><font size=1 color="white">Your points balance is: '.$user_premium_points;
$main_content .= '<br><font color="white"> <fieldset class="shop"><legend>DESCRIPTION</legend>'.$item['description'].'</fieldset></font><br><font color="white"><b> [Click to buy] </b></font></form> </a></center></td>';
}
// Check, if we we are at position "3". If so, end row. (set position back to 1)
// Otherwise increase position with one level.
if ($row_count === 3) {
$row_count = 1;
$main_content .= '</tr>';
}
else {
$row_count++;
}
} // end foreach
// This is code for filling the "blank" table cells, if you don't have exactly some item count / 3 = 0
if ($row_count !== 3) {
for ($i=0; $i<=(3-$row_count); $i++) {
$main_content .= '<td> </td>';
}
$main_content .= '</tr>';
}
$main_content .= '</table>';
PS: <center> is deprecated or more to say not valid HTML anymore.