At the moment my produces results from a database and then inserts all of the results into one HTML table.
Is there any way that it would be possible so that for each result returned it created an individual HTML table (opposed to all of the results going into one HTML table)
My code:
<table class=\"board\" width='100%' border='0' align='center' cellpadding='1' cellspacing='1'>
");
$type = $_GET["type"];
if ($type == "" || $type == "request") {
$get = mysql_query("SELECT * FROM request WHERE type='Request' AND deleted != 'yes' ORDER BY id DESC");
} else {
if ($type == "shoutout") {
$get = mysql_query("SELECT * FROM request WHERE type='Shoutout' AND deleted != 'yes' ORDER BY id DESC");
} else {
if ($type == "competition") {
$get = mysql_query("SELECT * FROM request WHERE type='Competition' AND deleted != 'yes' ORDER BY id DESC");
} else {
if($type == "all") {
$get = mysql_query("SELECT * FROM request WHERE deleted != 'yes' ORDER BY id DESC");
}
}
}
}
$num = #mysql_num_rows($get);
if ($num == 0) {
echo ("<div class=\"board\"><center><font color=\"red\">There aren't any requests in this category!<br />
Why not ask listeners to send in their requests?</font></center></div>");
} else {
while ($r = mysql_fetch_array($get)) {
echo "
<tr>
<td><font face=\"verdana\" size=\"1\"><b>User</b></td>
<td><font face=\"verdana\" size=\"1\"><b>$r[habboname]</b></td>
</tr>
<tr>
<td><font face=\"verdana\" size=\"1\"><b>Date</b></td>
<td><font face=\"verdana\" size=\"1\">$r[date]</td>
</tr>
<tr>
<td><font face=\"verdana\" size=\"1\"><b>IP</b></td>
<td><font face=\"verdana\" size=\"1\">$r[ip]</td>
</tr>
<tr>
<td><font face=\"verdana\" size=\"1\"><b>Message</b></td>
<td><font face=\"verdana\" size=\"1\">$r[message]</td>
</tr>
<tr>
<td><font face=\"verdana\" size=\"1\"><b>Type</b></td>
<td><font face=\"verdana\" size=\"1\">$r[type]</td>
</tr>
<tr>
<!-- <td><font face=\"verdana\" size=\"1\"><b>Refferer</b></td>
<td><font face=\"verdana\" size=\"1\">";
if($r[refferer] == 1){ echo "Site.com</td>"; } else { echo "Site1.com</td>"; }
echo "--></tr>
<tr>
<td><font face=\"verdana\" size=\"1\"><b>Commands</b></td>
<td><font face=\"verdana\" size=\"1\">Delete - Ban - <!--Alert-->Nominate LoTW</font></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
";
$id = htmlspecialchars($_GET['id']);
$delete = mysql_query("UPDATE request SET deleted = 'yes' WHERE id = '$id'");
}
echo ("</table></div>");
}
break;
case 'delete':
If you mean to create as many tables as there are returned rows, just put the opening <table> into the while's beginning and the closing </table> to the end of while. However, I don't understand why this would be desired. Do you really want to create many tables with just one row? It kind of defeats the purpose of a table. Make a list or use span's or anything else than tables instead.
while ($r = mysql_fetch_array($get)) {
echo "<table class=\"board\">
<tr>
<td><b>User</b></td>
<td><b>$r[habboname]</b></td>
</tr>
<tr>
<td><b>Date</b></td>
<td>$r[date]</td>
</tr>
<tr>
<td><b>IP</b></td>
<td>$r[ip]</td>
</tr>
<tr>
<td><b>Message</b></td>
<td>$r[message]</td>
</tr>
<tr>
<td><b>Type</b></td>
<td>$r[type]</td>
</tr>
<tr>
<!-- <td><b>Refferer</b></td>
<td>";
if($r[refferer] == 1){ echo "Site.com</td>"; } else { echo "Site1.com</td>"; }
echo "--></tr>
<tr>
<td><b>Commands</b></td>
<td>Delete - Ban - <!--Alert-->Nominate LoTW</font></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
</table>";
$id = htmlspecialchars($_GET['id']);
$delete = mysql_query("UPDATE request SET deleted = 'yes' WHERE id = '$id'");
}
echo "</div>"; //remove () after echo
Update. One another thing. Please don't use inline styling. You have table class="board" so you already probably know the power of CSS.
Second update. I removed <font ...> tags. Use CSS for example like this:
table.board{
width:100%;
border:0;
align:center;
cellpadding:1;
cellspacing:1;
}
table.board td{
font-family: Verdana, Geneva, Arial, sans-serif;
font-size: 1em;
}
CSS saves a lot of trouble when you want to change styling. And trust me, there will be a time when you want to change it (or your boss want's to bling-bling the site...).
ZZ-bb is absolutely right and as a hint try to put if/else construction in mysql - it will move faster or optimize it in php, like:
$get = mysql_query("SELECT * FROM request WHERE " . ($type == 'all' ? 'type = 1' : 'type = ucfirst($type)' ) . " AND deleted != 'yes' ORDER BY id DESC");
Related
Trying to get data to display from 2 different and basically unrelated tables. Don't want them joined, just discrete output to look like this in a select box:
Category: current category from table1 (this part works)
Entire list of categories from table 2 (correct number of empty option tags, no data showing)
DB connection code:
//DB CONNECTION//
$dbcnx = mysqli_connect("localhost", $DBASEUSER, $DBASEPASSWORD, $DBASE);
//Main Showcase
$sql = "SELECT * FROM `dprods`";
//////HEADER in main page
<?php
$ID=$_GET['ID'];
$CAT=$_GET['cat'];
?>
//////Main SECTION
<?php
require "db_conn.php";
$sql2 = "SELECT * FROM $DBTABLE WHERE ID=$ID";
$getinfo = mysqli_query($dbcnx, $sql2);
$row = mysqli_fetch_assoc($getinfo);
$PROD = $row['dtitle'];
$PRICE = $row['dprice'];
$PP = $row['dpplink'];
echo "<tr>
<td width=\"12%\">
<div align=\"right\"><b><font face=\"Arial, Helvetica, sans-serif\" size=2>Product
Category: </font></b></div>
</td>
<td colspan=2 width=\"88%\"><select name=\"dcat\"><option value=\"$CAT\">Current Category: $CAT</option>";
$dcat = "SELECT * FROM 'dcat'";
$getcat = mysqli_query($dbcnx, $dcat);
$row2 = mysqli_fetch_assoc($getcat);
while($row2 = mysqli_fetch_assoc($result))
{ echo " <option value=\"".$row2["dcategory"]."\">".$row2["dcategory"]."</option>";
}
echo "".$row["dprice"]."</select>
</tr>
<tr>
<td width=\"12%\"> </td>
<td width=\"24%\"> </td>
<td width=\"64%\"> </td>
</tr>
<tr>
<td width=\"12%\">
<div align=\"right\"><b><font face=\"Arial, Helvetica, sans-serif\" size=2>Product
Title: </font></b></div>
</td>
<td width=\"24%\"> <b><font face=\"Arial, Helvetica, sans-serif\" size=2>
<input type=\"text\" name=\"Title\" value=\"".$row["dtitle"]."\" size=35 maxlength=25>
</font></b><b><font face=\"Arial, Helvetica, sans-serif\" size=2> </font></b></td>
<td width=\"64%\"><b><font face=\"Arial, Helvetica, sans-serif\" size=2>Price</font></b>:
<b><font face=\"Arial, Helvetica, sans-serif\" size=2>
<input type=\"text\" name=\"Price\" value=\"".$row["dprice"]."\" maxlength=10 size=20>
</font></b></td>
</tr>
<tr>
<td width=\"12%\"> </td>
<td width=\"24%\"> </td>
<td width=\"64%\"> </td>
</tr>
<tr>
<td width=\"12%\">
<div align=\"right\"><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=2><b>PayPal
Link: </b></font></div>
</td>
<td colspan=2><font face=\"Arial, Helvetica, sans-serif\"><b>http://www.paypal.com</b>
</font>
<input type=\"text\" name=\"PP\" value=\"".$row["dpplink"]."\" size=50>
<font face=\"Arial, Helvetica, sans-serif\">Only put in what follows paypal.com</font></td>
</tr>
";
mysqli_close($dbcnx);
?>
Been working and researching this for hours and now I'm so horribly confused, lupus induced Swiss-cheese brain isn't helping. I think I'm very close, just unable to get the data from the 2nd table to display. Would appreciate any suggestions, but please keep it as simple as possible. Some of the complex code I've seen in my research confuses me even more. Thanks!
Try including getcat in your select query like this:
$dcat = "SELECT 'dcategory', 'getcat' FROM 'dcat'";
$getcat = mysqli_query($dbcnx, $dcat);
while($row2 = mysqli_fetch_assoc($getcat))
{
echo " <option value=\"".$row2["getcat"]."\">".$row2["getcat"]."</option>";
}
echo "</select>"
You could also use $dcat = "SELECT * FROM 'dcat'";, but the above is likely slightly more efficient.
Also, I don't see where $result was being set for this code while($row2 = mysqli_fetch_assoc($result))
It looks like $result isn't set, so it would obviously give you undesirable results.
You're also doing $row2 = mysqli_fetch_assoc($getcat); outside of the while loop, which will grab the first row before entering the loop. The loop would start at the second row.
Please look at http://php.net/manual/en/mysqli-result.fetch-assoc.php
Also, your script will be subject to SQL Injection, as mentioned in the comments. You will need to fix it so it is as safe as possible. Read the links in the comments and also make sure you're using prepared statements
adpro, your help was invaluable. I was more confused than I realized and your comments helped point that out to me. I went back & started from scratch with a clean query code that I could print out, mark up with colored hi-liters to follow the variables. Code now works as desired and I'm posting for anyone else who may need the clarification. I appreciate the input from everyone about the sql injection. My goal was to get the simple functionality working first before making it more complicated. Now I can add the protection to prevent sql injection.
<?php
require "db_conn.php";
$sql2 = "SELECT * FROM $DBTABLE WHERE ID=$ID";
$getinfo = mysqli_query($dbcnx, $sql2);
$row = mysqli_fetch_assoc($getinfo);
$PROD = $row['dtitle'];
$PRICE = $row['dprice'];
$PP = $row['dpplink'];
echo "<tr>
<td width=\"12%\">
<div align=\"right\"><b><font face=\"Arial, Helvetica, sans-serif\" size=2>Product
Category: </font></b></div>
</td>
<td colspan=2 width=\"88%\"><select name=\"dcat\"><option value=\"$CAT\">Current Category: $CAT</option>";
$sqlCAT = "SELECT * FROM dcat";
if($resultCAT = mysqli_query($dbcnx, $sqlCAT)){
if(mysqli_num_rows($resultCAT) > 0){
while($rowCAT = mysqli_fetch_array($resultCAT)){
echo "<option value=\"".$rowCAT['dcategory']."\">".$rowCAT['dcategory']."</option>";
}
// Free result set
mysqli_free_result($resultCAT);
} else{
echo "No records matching your query were found.";
}
} else{
echo "ERROR: Could not able to execute $sqlCAT. " . mysqli_error($dbcnx);
}
echo " </select>";
mysqli_close($dbcnx);
?>
I am a back end dev for a WordPress website: https://westtechshipping.com.
The admin side is where the majority of our time is spent. We deal with packages ordered by our customers and deliver them. I have a system put in place where you upload a .csv file and the PHP function reads the contents of the .csv, then updates the data into the database, then sends out an email to our clients.
Over time we realized that we cannot do a .csv upload with more than 30 entries because we would get errors like this one
I took this image from google images because I cannot recreate the error at the moment due to the time of this post, but the error is similar.
We also sometimes get a page that says this
We've tried many things and are not sure what the issue is. These hiccups cause our data to be uploaded twice and multiple emails to be sent out to each client.
We have spoken to our server hosting, go daddy, and followed their recommendations of editing our user.ini accordingly.
This are our PHP settings from our user.ini
If this is an issue with the code, below is the current code for our .csv upload feature.
if(isset($_POST["submitcsv"])) // Upload Package Amount CSV File
{
$file = $_FILES['file']['tmp_name'];
$handle = fopen($file, "r");
$c = 0;
$c2 = 0;
$row = 1;
while(($filesop = fgetcsv($handle, 1000, ",")) !== false)// What?
{
$Name = $filesop[0];
$AccID = $filesop[1];
$Freight = $filesop[2];
$Handling = $filesop[3];
$Consolidation = $filesop[4];
$Duty = $filesop[5];
$VTax = $filesop[6];
$Delivery = $filesop[7];
$Insurance = $filesop[8];
$Amount = $filesop[9];
$Statuscsv = $filesop[10];
$Pickup = $filesop[11];
$trackingnumber =$filesop[12];
if($row == 1) { $row++; continue;}
$num = count($filesop);
//Separating First name
$First_Name = substr($Name,0,strrpos($Name,' '));
if(strrpos($Name, ' ')!== false){
$First_Name = $First_Name;
}else{
$First_Name = $Name;
}
//Getting rid of blank costs
if(empty($Freight)){$Freight = "0";}
if(empty($Handling) ){$Handling = "0";}
if(empty($Consolidation)){$Consolidation = "0";}
if(empty($Duty) ){$Duty = "0";}
if(empty($VTax) ){$VTax = "0";}
if(empty($Delivery)){$Delivery = "0";}
if(empty($Insurance)){$Insurance = "0";}
if(empty($Amount)){$Amount = "0";}
//$pkg = get_packages_query($trackingnumber);
//$pkginv = get_invoices_by_trackingid($trackingnumber);
$userID = explode('WT100',$AccID);
$userdata = get_userdata( $userID[1] );
$site_name = get_bloginfo('name');
$messageinv = " <style>
#media screen (max-width:768px) { /* smartphones, iPhone, portrait 480x320 phones */
#packagetable{
margin-left:20px;
}
}
</style>
<div style='font-size:15px;'>
<strong> Dear ".$First_Name."</strong>, <br><br>
".$site_name." has a package available for you. You can come in to collect during our working hours of Monday- Friday 8AM to 5PM and Saturdays 9AM to 1PM.
</div>
<br><br>
<table id='packagetable' style='border:1px solid #8EAADB; margin-left:150px;'>
<tr class ='invhead' style='background-color:#4472C4; color:white;'>
<th>Charges</th>
<th>Amount (EC)</th>
</tr>
<tr class ='2ndtr' >
<td > Tracking Number </td>
<td> ".$trackingnumber."</td>
</tr>
<tr class ='1str' style='background-color:#D9E2F3; '>
<td > Shipping Charge: </td>
<td> $".$Freight." </td>
</tr>
<tr class ='2ndtr' >
<td > Duty Charge: </td>
<td> $".$Duty."</td>
</tr>
<tr class ='1str' style='background-color:#D9E2F3; '>
<td > Handling Fee: </td>
<td> $".$Handling." </td>
</tr>
<tr class ='2ndtr' >
<td > Consolidation Fee: </td>
<td> $".$Consolidation." </td>
</tr>
<tr class ='1str' style='background-color:#D9E2F3; '>
<td > Delivery Fee: </td>
<td> $".$Delivery." </td>
</tr>
<tr class ='2ndtr' >
<td > <strong>Total Amount: </strong> </td>
<td><strong>$".$Amount."</strong> </td>
</tr>
</table>
<div>
<br><br>
Thanks for using our service! We appreciate it.
<br><br>
Regards,<br>
".$site_name."
<br>______________________________________________________<br><br>
<strong>Call Us</strong><br><br>
<strong>Rodney Bay</strong>: 458-9378 <strong>Castries</strong>: 451-9378 <strong>Vieux Fort</strong>: 454-9378
</div>
";
$messageinvadmin .=
" <style>
#media screen (max-width:768px) { /* smartphones, iPhone, portrait 480x320 phones */
#packagetable{
margin-left:20px;
}
}
</style>
<div><strong>".$Name."</strong> with email address ".$userdata->data->user_email.", had an invoice update. <br><br>
View the changes below
</div>
<br><br>
<table id='packagetable' style='border:1px solid #8EAADB; margin-left:150px;'>
<tr class ='invhead' style='background-color:#4472C4; color:white;'>
<th>Charges</th>
<th>Amount (EC)</th>
</tr>
<tr class ='2ndtr' >
<td > Tracking Number </td>
<td> ".$trackingnumber."</td>
</tr>
<tr class ='1str' style='background-color:#D9E2F3; '>
<td > Shipping Charge: </td>
<td> $".$Freight." </td>
</tr>
<tr class ='2ndtr' >
<td > Duty Charge: </td>
<td> $".$Duty."</td>
</tr>
<tr class ='1str' style='background-color:#D9E2F3; '>
<td > Handling Fee: </td>
<td> $".$Handling." </td>
</tr>
<tr class ='2ndtr' >
<td > Consolidation Fee: </td>
<td> $".$Consolidation." </td>
</tr>
<tr class ='1str' style='background-color:#D9E2F3; '>
<td > Delivery Fee: </td>
<td> $".$Delivery." </td>
</tr>
<tr class ='2ndtr' >
<td > <strong>Total Amount: </strong> </td>
<td><strong>$".$Amount."</strong> </td>
</tr>
<tr class ='1str' style='background-color:#D9E2F3; '>
<td > Delivery Fee: </td>
<td> $".$Delivery." </td>
</tr>
</table>
_______________________________________________________
<br><br>
";
$closing = "Regards,<br>
".$site_name."
<br>______________________________________________________<br><br>
<strong>Call Us</strong><br><br>
<strong>Rodney Bay</strong>: 458-9378 <strong>Castries</strong>: 451-9378 <strong>Vieux Fort</strong>: 454-9378
</div>
";
$invtotalsql = mysql_fetch_assoc(mysql_query("SELECT invoice_total_charges FROM wp_xq4w067xaq_customer_invoice WHERE invoice_tracking_number = '$trackingnumber'"));
$packstatsql = mysql_fetch_assoc(mysql_query("SELECT pms_status FROM wp_xq4w067xaq_package WHERE tracking_id = '$trackingnumber'"));
if($Statuscsv == "Collected & Paid"){
$Statuscsv = 5;
}if($Statuscsv == "Available for Pick-Up"){
$Statuscsv = 4;
}if($Statuscsv == "Pending Invoice"){
$Statuscsv = 3;
}if($Statuscsv == "Paid"){
$Statuscsv = 7;
}if($Statuscsv == "Collected"){
$Statuscsv = 9;
}if($Statuscsv == "Shipped"){
$Statuscsv = 2;
}if($Statuscsv == "Received"){
$Statuscsv = 1;
}
if($invtotalsql['invoice_total_charges'] !== $Amount OR $packstatsql['pms_status'] !== $Statuscsv){
send_email_pkg2($userdata->data->user_email, $messageinv, $site_name. ' Package Amount Update',$userdata->user_email_2,$userdata->user_email_3);
//send_email_pkg("shipping#westtg.com", $messageinvadmin, $site_name. "Package Amount update");
//send_email_pkg("5sp4lr9#gmail.com", $messageinvadmin, $site_name. "Invoices");
//send_email_pkg("5sp4lr9#gmail.com", $message3, $site_name. "Minimum Invoices");
}
$sql = "UPDATE wp_xq4w067xaq_package SET pms_full_name='$Name',pms_status='$Statuscsv',pms_amount_owned='$Amount',pms_pickup='$Pickup' WHERE tracking_id='$trackingnumber'";
mysql_query($sql);
$c = $c + 1; // count number of package info updated
$sql2 = "UPDATE wp_xq4w067xaq_customer_invoice SET invoice_shipping_charge='$Freight',invoice_handling_fee='$Handling',invoice_consolidation_fee='$Consolidation',invoice_duty_charge='$Duty',invoice_added_tax='$Vtax',invoice_delivery_fee='$Delivery',invoice_insurance='$Insurance',invoice_total_charges='$Amount' WHERE invoice_tracking_number='$trackingnumber'";
mysql_query($sql2);
$c2 = $c2 + 1; // count number of invoices updated
//update_invoice2();
}
$finaladmin = $messageinvadmin.$closing;
send_email_pkg("shipping#westtg.com", $finaladmin, $site_name. "Package Amount update");
// Success OR Error Message
if($sql AND $sql2){
echo "Your database has imported successfully. You have inserted ". $c ." records in packages and ".$c2." records in invoices";
}else{
echo "Sorry! There is some problem.";
}
}
Currently the below puts everything into rows, I am wondering if there is a way to put these as individual tables every time instead of rows?
I am used to echo everything to rows as everything I have dealt with so far, is perfectly fine. But now I am at a point where it would be better to show all as individual tables.
I might not be explaining myself very well, sorry if not.
<table width="75%" border="0" cellpadding="0" cellspacing="2" class="table">
<tr align="center">
<td class="header"><center>Patch Version</center></td>
<td class="header"><center>Patch Date</center></td>
<td class="header"><center>Update By</center></td>
<?php if ($userlvl >= 3) { ?><td class="header"><center>Admin Settings</center></td></tr> <?php } else { } ?>
</tr>
<?
$result = mysql_query("SELECT * FROM updates WHERE del ='0' ORDER BY id DESC") or die(mysql_error());
while($row = mysql_fetch_array( $result )) {
?>
<tr>
</label></td>
<td class="header"><center><h4><? echo $row['patchversion'] ?></h3></center></td>
<td class="header"><center><h3><? echo $row['updatetime'] ?></h3></center></td>
<td class="header"><center><h4><? echo $row['addedby']?></h4></td>
<?php if ($userlvl >= 3) { ?><td class="header"><center><h4> <?php } else { } ?>
<?php if ($userlvl >= 3){ echo "( Edit )" ." - ". "( X )"; } else { } ?></center></td>
<tr><td class="cell" colspan="50"><? echo $row['news']?></td>
</tr>
<?php }
?>
</table>
Just move the table tags within your while loop, something like this for example:
<?php
while($row = mysql_fetch_array( $result )) {
?>
<table>
<tr>
<td class="header"><center><h4><? echo $row['patchversion'] ?></h3></center></td>
<td class="header"><center><h3><? echo $row['updatetime'] ?></h3></center></td>
<td class="header"><center><h4><? echo $row['addedby']?></h4></td>
<?php if ($userlvl >= 3) { ?><td class="header"><center><h4> <?php } else { } ?>
<?php if ($userlvl >= 3){ echo "( Edit )" ." - ". "( X )"; } else { } ?></center></td>
</tr>
</table>
<?php } ?>
Hope some one can help me out here, i guess am not calling my functions right.
Am trying to retrieve some data from my database and have a delete link attached to each items being retrieved, so that when ever i click on delete, it will delete that particular item which have the delete function.
My Code to retrieve items from database are as follows.
<?php
$con = mysql_connect("localhost","root","");
mysql_select_db("uloaku", $con);
$count = 1;
$y = mysql_query("SELECT * FROM transaction");
if(mysql_num_rows($y) != 0){
echo "<table bgcolor=\"white\" width=\"1000\" bordercolor=\"grey\" border=\"5\" >";
echo "<tr>
<td align=\"center\">No</td>
<td align=\"center\">Date</td>
<td align=\"center\">Current Balance</td>
<td align=\"center\">Avaliable Balance</td>
<td align=\"center\">Account Status</td>
<td align=\"center\">Delete Account</td>
</tr>";
while ($z = mysql_fetch_array($y, MYSQL_BOTH)){
echo "<tr>
<td align=\"center\">".$count++."</td>
<td align=\"center\">".$z[1]."</td>
<td align=\"center\">".$z[2]."</td>
<td align=\"center\">".$z[3]."</td>
<td align=\"left\" width=\"300\">".$z[4]."</td>
<td>delete</td>
</tr>";
}
echo "</table>";
}
?>
And my code to delete
<?php
session_start();
$con = mysql_connect("localhost","root","");
mysql_select_db("uloaku", $con);
$id = $_GET['id'];
$sql = mysql_query("DELETE FROM transaction WHERE id='$id' LIMIT 1") or die (mysql_error());
header("Location: vacct.php");
?>
I know am missing out the logic here and hope somebody can direct me or show me the easy way out. at the moment i can successfully retrieve my items from the data base my only problem is to be able to apply the delete function each time the delete button is tapped.
You have to pass the id when you click on the delete link:
<a href=\"delete.php?id=$z[theIdKey]\">
Use the below code.I have added validation and encryption
<?php
$con = mysql_connect("localhost","root","");
mysql_select_db("uloaku", $con);
$count = 1;
$y = mysql_query("SELECT * FROM transaction");
if(mysql_num_rows($y) != 0){
echo "<table bgcolor=\"white\" width=\"1000\" bordercolor=\"grey\" border=\"5\" >";
echo "<tr>
<td align=\"center\">No</td>
<td align=\"center\">Date</td>
<td align=\"center\">Current Balance</td>
<td align=\"center\">Avaliable Balance</td>
<td align=\"center\">Account Status</td>
<td align=\"center\">Delete Account</td>
</tr>";
while ($z = mysql_fetch_array($y, MYSQL_BOTH)){
echo "<tr>
<td align=\"center\">".$count++."</td>
<td align=\"center\">".$z[1]."</td>
<td align=\"center\">".$z[2]."</td>
<td align=\"center\">".$z[3]."</td>
<td align=\"left\" width=\"300\">".$z[4]."</td>
<td>delete</td>
</tr>";
}
echo "</table>";
}
?>
code to delete
<?php
session_start();
$con = mysql_connect("localhost","root","");
mysql_select_db("uloaku", $con);
$id = base64_decode($_GET['id']);
if(!empty($id)){
$sql = mysql_query("DELETE FROM transaction WHERE id='$id' LIMIT 1") or die (mysql_error());
}
header("Location: vacct.php");
?>
<td>delete</td>
How are you passing the id to delete to your delete.php script?
Change:
<td>delete</td>
to:
<td>delete</td>
if $z[0] is the ID.
In your delete.php, make sure you also escape the word "transaction" using backtick:
DELETE FROM `transaction` WHERE id=123
this is because "transaction" is a reserved mysql keyword.
Please also read on SQL Injections.
Hello i have a table with some fields like
here i want make colors for table entire rows..means if ASR value is 75 to 100 should get one color and 50 to 75 should get another color and below 50 should get another color.
and here is my php code
<table width="75%" border="1">
<tr>
<td align="center">channel no</td>
<td align="center">IP</td>
<td align="center">Total calls</td>
<td align="center">Connected calls</td>
<td align="center">Disconnected calls</td>
<td align="center">Duration</td>
<td align="center">ASR</td>
<td align="center">ACD</td>
</tr>
<?php
while ($row = mysql_fetch_assoc($result)) {
//$minutes = gmdate("H:i:s", $row['tduration']);
echo "<tr>
<td>".$row['channel']." </td>
<td>".$row['ip']." </td>
<td>".$row['totalcalls']." </td>";
if ($row['totalcalls']>1){
$sql1 = "SELECT count(duration) as count FROM gateways where duration=0 and ip='".$_POST['ip']."' and channel='".$row['channel']. "' and (connect_datetime BETWEEN ' ".$_POST['toval']." ' and '".$_POST['fromval']."' or disconnect_datetime BETWEEN ' ".$_POST['toval']." ' and '".$_POST['fromval']."' ) Group by channel";
$result1 = mysql_query($sql1, $link);
$norow=mysql_fetch_assoc($result1);
$attenedcalls=($row['totalcalls']-$norow['count']);
echo "<td>".$attenedcalls." </td>";
$disconnectedcalls=($row['totalcalls']-$attenedcalls);
echo "<td>".$disconnectedcalls." </td>";
echo " <td>".$row['tduration']." </td>";
echo "<td>".(($attenedcalls/$row['totalcalls'])*100)."</td>";
}else{
echo "<td>".$row['totalcalls']."</td>";
echo "<td>100</td>";
}
$minutes = gmdate("H:i:s", ($row['tduration']/$attenedcalls));
echo " <td>".$minutes." </td>
</tr>";
}
?>
</table>
thanks in advance
You can try like this
<table width="75%" border="1">
<tr>
<td align="center">channel no</td>
<td align="center">IP</td>
<td align="center">Total calls</td>
<td align="center">Connected calls</td>
<td align="center">Disconnected calls</td>
<td align="center">Duration</td>
<td align="center">ASR</td>
<td align="center">ACD</td>
</tr>
<?php
while ($row = mysql_fetch_assoc($result)) {
$color = '';
if ($row['totalcalls']>1){
$sql1 = "SELECT count(duration) as count FROM gateways where duration=0 and ip='".$_POST['ip']."' and channel='".$row['channel']. "' and (connect_datetime BETWEEN ' ".$_POST['toval']." ' and '".$_POST['fromval']."' or disconnect_datetime BETWEEN ' ".$_POST['toval']." ' and '".$_POST['fromval']."' ) Group by channel";
$result1 = mysql_query($sql1, $link);
$norow=mysql_fetch_assoc($result1);
$attenedcalls=($row['totalcalls']-$norow['count']);
$asr = (($attenedcalls/$row['totalcalls'])*100);
if($asr >= 75 && $asr <=100 ){
$color = 'red';
}else if($asr >= 50 && $asr < 75){
$color = 'cyan';
}else if($asr < 50){
$color = 'blue';
}
}
//$minutes = gmdate("H:i:s", $row['tduration']);
echo "<tr style='background-color : ".$color."'>
<td>".$row['channel']." </td>
<td>".$row['ip']." </td>
<td>".$row['totalcalls']." </td>";
if ($row['totalcalls']>1){
echo "<td>".$attenedcalls." </td>";
$disconnectedcalls=($row['totalcalls']-$attenedcalls);
echo "<td>".$disconnectedcalls." </td>";
echo " <td>".$row['tduration']." </td>";
echo "<td>".$asr."</td>";
}else{
echo "<td>".$row['totalcalls']."</td>";
echo "<td>100</td>";
}
$minutes = gmdate("H:i:s", ($row['tduration']/$attenedcalls));
echo " <td>".$minutes." </td>
</tr>";
}
?>
</table>
[...]
while ($row = mysql_fetch_assoc($result)) {
$asrVal=(($attenedcalls/$row['totalcalls'])*100);
if($asrVal>=50 && $asrVal <=75) $class="from50to75";
if($asrVal>=75 && $asrVal <=100) $class="from75to100";
if($asrVal<50) $class="below50";
//$minutes = gmdate("H:i:s", $row['tduration']);
echo "<tr class='$class'>
[...]
then add:
<style>
tr.from50to75 td{background-color:red;}
tr.from75to100 td{background-color:green;}
tr.below50 td{background-color:blue;}
</style>
Modify your while loop so that you compute the ASR value before emitting the <tr> tag. Use that value to select a class according to the classification you have set up, and emit a tag of the form <tr class=foo> where foo is the class name you have selected. Then it’s just a matter of writing CSS rules for the classes, using class selectors like tr.foo.
(Provided that you have not set color on the td cells. If you have, you need to use selectors like tr.foo td to override such settings.)