I am showing a list of users information. The users are set at different levels (1-5). I only want it to display information for users that are level 1. Here is basically the code.
<?php while ($rrows = mysql_fetch_array($rs_results)) {?>
<tr>
<td><input name="u[]" type="checkbox" value="<?php echo $rrows['id']; ?>" id="u[]"></td>
<td><?php echo $rrows['date']; ?></td>
<td><?php echo $rrows['user_level']; ?></td>
<td><?php echo $rrows['user_name'];?></td>
<td><?php echo $rrows['user_email']; ?></td>
<td> <span id="approve<?php echo $rrows['id']; ?>">
<?php if(!$rrows['approved']) { echo "Pending"; } else {echo "Active"; }?>
</span> </td>
<td><span id="ban<?php echo $rrows['id']; ?>">
<?php if(!$rrows['banned']) { echo "no"; } else {echo "yes"; }?>
</span>
</td>
</tr>
How would I say to display only information of users who's 'user_level' = '1'?
You could filter in two ways:
directly in the query, as indicated by #Fred
after fetching the recordset:
while ($rrows = mysql_fetch_array($rs_results)){
if ($rrows['user_level'] == 1){
// display as previously
You would need to put an if statement inside your while loop that checks the user level.
//php mysql while
If ($rrows['user_level'] == 1) {?>
//html code
}?>
Try put the row to if block, like in the following code. It's ugly practice. Will be better if You use condition in the mysql query.
<?php while ($rrows = mysql_fetch_array($rs_results)) {?>
<?if($rrows['user_level']==1){?>
<tr>
<td><input name="u[]" type="checkbox" value="<?php echo $rrows['id']; ?>" id="u[]"></td>
<td><?php echo $rrows['date']; ?></td>
<td><?php echo $rrows['user_level']; ?></td>
<td><?php echo $rrows['user_name'];?></td>
<td><?php echo $rrows['user_email']; ?></td>
<td> <span id="approve<?php echo $rrows['id']; ?>">
<?php if(!$rrows['approved']) { echo "Pending"; } else {echo "Active"; }?>
</span> </td>
<td><span id="ban<?php echo $rrows['id']; ?>">
<?php if(!$rrows['banned']) { echo "no"; } else {echo "yes"; }?>
</span> </td>
</tr>
<?} /*end if*/?>
<?} /*end while*/?>
Related
Here is the query statement that I have. For some reason it works for another table I have but doesn't work with this table. I checked phpmyadmin to see if I would create an error but there were zero errors.
$Store_ID = filter_input(INPUT_POST,'Store_ID',FILTER_VALIDATE_INT);
//DELETE the Store
$query="DELETE FROM store_location WHERE Store_ID = :Store_ID";
$statement2=$db->prepare($query);
$statement2->bindValue(':Store_ID',$Store_ID);
$statement2->execute();
$statement2->closeCursor();
Here is the table code for the Delete Button
<?php foreach ($stores as $s) : ?>
<tr>
<td><?php echo $s['Store_ID']; ?></td>
<td><?php echo $s['Loc_Street']; ?></td>
<td><?php echo $s['Loc_City']; ?></td>
<td><?php echo $s['Loc_State']; ?></td>
<td><?php echo $s['Rent']; ?></td>
<td><?php echo $s['License']; ?></td>
<td><?php echo $s['Inspect']; ?></td>
<td><form action="stores.php" method="post">
<input type ="hidden" name ="Store_ID" value ="<?php echo $s['Store_ID']; ?>"/>
<input type="button" name="delete" value="Delete"/>
</form></td>
</tr>
<?php endforeach; ?>
</table>
<?php
$i= 0;
foreach($purchaseorder as $tdata):
$i++;
?>
<tr >
<td><?php echo $tdata['pay_date']; ?></td>
<td><?php echo $tdata['cylinder']; ?></td>
<td><?php echo $tdata['amount']; ?></td>
<td><?php echo $tdata['rtgs_no']; ?></td>
<td><?php echo $tdata['cheque_no']; ?></td>
<td><?php echo $tdata['dd_no']; ?></td>
<td><?php echo if ($tdata['approve']=='true')
{
?>
<img src="/../img/green.png" alt="alt-tag"/>;
<?php
}
else
{
?>
<img src="/../img/red.png" alt="alt-tag" />;
<?php } ?></td>
</tr>
<?php
endforeach;
?>
my code is when i check a checkbox and submit a green tick should be displayed in list page..if its not checked and submitted a red cross should be displayed..but i get a error in the above code..what sholud i do?
<td><?php if ($tdata['approve']=='true')
{ ?>
<img src="/../img/green.png" alt="alt-tag"/>
<?php }
else
{ ?>
<img src="/../img/red.png" alt="alt-tag" />
<?php } ?></td>
<?php
foreach($purchaseorder as $tdata):
?>
<tr >
<td><?php echo $tdata['pay_date']; ?></td>
<td><?php echo $tdata['cylinder']; ?></td>
<td><?php echo $tdata['amount']; ?></td>
<td><?php echo $tdata['rtgs_no']; ?></td>
<td><?php echo $tdata['cheque_no']; ?></td>
<td><?php echo $tdata['dd_no']; ?></td>
<td><?php if($tdata['approve']==true)
{
?>
<img src="/../img/green.png" alt="alt-tag"/>;
<?php
}
else
{ ?>
<img src="/../img/red.png" alt="alt-tag" />;
<?php
} ?>
</td>
</tr>
<?php
endforeach;
?>
try this code and if possible show me the data thats comes on "$purchaseorder" variable
First make var_dump($tdata) and look 'approve' index value. If is set $tdata['approve'] then change code:
<td><?php if ($tdata['approve']=='true')
{ ?>
<img src="/../img/green.png" alt="alt-tag"/>
<?php }
else
{ ?>
<img src="/../img/red.png" alt="alt-tag" />
<?php } ?></td>
for this
<?php
$approveImg = ($tdata['approve']=='true') ? 'green.png' : 'red.png';
?>
<td>
<img src="/../img/<?=$approveImg?>" alt="alt-tag"/>
</td>
Also check paths to images
I want to be able too add this piece of code in a surrounded by an echo""
and stil be able to output the variables that is currently in the like below. This is where my mind is shutting down badly.
<td><?php echo $row_Recordset1['leaveID']; ?> </td>
<td><a href='Leavedetail.php?recordID=<?php echo $row_Recordset1['leaveID']; ?>'> <?php echo $row_Recordset1['serviceNumber']; ?> </a></td>
<td><?php echo $row_Recordset1['rank']; ?> </td>
<td><?php echo $row_Recordset1['organisation']; ?> </td>
<td><?php echo $row_Recordset1['lastName']; ?> </td>
<td><?php echo $row_Recordset1['firstName']; ?> </td>
<td><a class='btn btn-default' href='userDeleteProcess.php?id={$row_Recordset1['leaveID']}'>Delete</a></td>
You are in need of using ob_get_contents();
Your code will look like this.
<?php
ob_start();
?>
<td><?php echo $row_Recordset1['leaveID']; ?> </td>
<td><a href='Leavedetail.php?recordID=<?php echo $row_Recordset1['leaveID']; ?>'> <?php echo $row_Recordset1['serviceNumber']; ?> </a></td>
<td><?php echo $row_Recordset1['rank']; ?> </td>
<td><?php echo $row_Recordset1['organisation']; ?> </td>
<td><?php echo $row_Recordset1['lastName']; ?> </td>
<td><?php echo $row_Recordset1['firstName']; ?> </td>
<td><a class='btn btn-default' href='userDeleteProcess.php?id={$row_Recordset1['leaveID']}'>Delete</a></td>
<?php
$output = ob_get_contents();
ob_end_clean();
echo $output;
?>
In cases if you cannot use output buffering as #PratikSoni suggested, I would recommend looking up printf() or sprintf() functions for having formatted output.
Usage example:
$output .= sprintf("<td>%s </td>", $row_Recordset1['leaveID']);
This way you have it in a variable, and could do echo or whatever else you might need it for.
See if this works
<td><?php echo $row_Recordset1['leaveID']; ?> </td>
<td><a href='Leavedetail.php?recordID=<?php echo $row_Recordset1['leaveID']; ?>'> <?php echo $row_Recordset1['serviceNumber']; ?> </a></td>
<td><?php echo $row_Recordset1['rank']; ?> </td>
<td><?php echo $row_Recordset1['organisation']; ?> </td>
<td><?php echo $row_Recordset1['lastName']; ?> </td>
<td><?php echo $row_Recordset1['firstName']; ?> </td>
<td><a class='btn btn-default' href='userDeleteProcess.php?id={$row_Recordset1['leaveID']}'>Delete</a></td>
I have a problem getting a table to work.
I want to adjust a printable form for order list (opencart),
but I want address box on left and products ordered on right.
The problem is the number of products varies per order, so using rowspan on the address box does not work (I left the rowspan in the code).
<thead>
<tr>
<td><b><?php echo $text_to; ?></b></td>
<td><b><?php echo $column_product; ?></b></td>
<td class="text-center"><b><?php echo $column_quantity; ?></b></td>
</tr>
</thead>
<tbody><tr>
<td rowspan="10"><?php echo $order['shipping_address']; ?><br/><br/>
<?php echo $order['telephone']; ?>
<br />
<?php if ($order['shipping_method']) { ?>
<b><?php echo $text_shipping_method; ?></b> <?php echo $order['shipping_method']; ?><br />
<?php } ?></td></tr>
<?php foreach ($order['product'] as $product) { ?>
<td><?php echo $product['name']; ?>
<?php foreach ($product['option'] as $option) { ?>
<br />
<small> - <?php echo $option['name']; ?>: <?php echo $option['value']; ?></small>
<?php } ?></td>
<td class="text-center"><?php echo $product['quantity']; ?></td>
</tr>
<?php } ?>
</tbody>
</table>
You have all the information available it seems so you just need to change:
<td rowspan="10">
to:
<td rowspan="<?php echo count($order['product']); ?>">
However, you do need to check the generated html as it looks like you are not generating valid rows so you might need to change the logic a bit.
I am encountering a problem when printing out the array that is stored inside $description.
Here is my code:
<?php foreach($descriptions as $description) { foreach ($languages as $language) { ?>
<div class="tabs-add language_id_<?php echo $language['language_id']; ?>" id="tab-language-<?php echo $module_row; ?>-<?php echo $language['language_id']; ?>">
<table id="general" class="form">
<tr>
<td><?php echo $entry_title; ?></td>
<td><input type="text" name="announcement_module[<?php echo $module_row; ?>][title][<?php echo $language['language_id']; ?>]" id="title-<?php echo $module_row; ?>-<?php echo $language['language_id']; ?>" value="<?php echo isset($module['title'][$language['language_id']]) ? $module['title'][$language['language_id']] : ''; ?>" /></td>
</tr>
<tr>
<td><?php echo $entry_description; ?> <a onclick="removeMessage(this);"><?php echo $button_remove; ?></a></td>
<td><textarea name="announcement_module[<?php echo $module_row; ?>][description][<?php echo $description_row;?>][<?php echo $language['language_id']; ?>]" id="description-<?php echo $module_row; ?>-<?php echo $description_row;?>-<?php echo $language['language_id']; ?>"><?php echo isset($module['description'][$description_row][$language['language_id']]) ? $module['description'][$description_row][$language['language_id']] : ''; ?></textarea></td>
</tr>
</table>
</div>
I want to print out the $entry_description as many times the user wants. But I can't seem to print out more than one at a time. How do I solve this?