Jump to content

[SOLVED] Update table


Bifter

Recommended Posts

Hiya all,

 

Struggling a bit here; would really appreciate a little help - recon you guessed that tho....

 

 

<?php
mysql_select_db("ipendpoi_Purchase", $conn);
$result = mysql_query("SELECT * FROM po ORDER BY number DESC");
echo "<table width='100%' border='1'>
<tr>
<th>Date</th>
<th>PO Number</th>
<th>Requester</th>
<th>Amount</th>
<th>Vendor</th>
<th>Department</th>
<th>End User</th>
<th>Invoiced</th>
</tr>";
$rowclass = 0;
while($row = mysql_fetch_array($result))
  {
  echo "<tr class = row" . $rowclass . ">";
  echo "<td>" . "<div align=\"center\">" . $row['date'] . "</div>" . "</td>";
  echo "<td>" . "<div align=\"center\">" . "<a href=\"upload_directory/Purchase-Order-" . $row['number'] . ".pdf\">" . $row['number'] . "</a>" . "</div>" . "</td>";
  echo "<td>" . "<div align=\"center\">" . $row['requester'] . "</div>" . "</td>";
  echo "<td>" . "<div align=\"center\">" . "£"  . $row['amount'] . "</div>" . "</td>";
  echo "<td>" . "<div align=\"center\">" . $row['vendor'] . "</div>" . "</td>";
  echo "<td>" . "<div align=\"center\">" . $row['department'] . "</div>" . "</td>";
  echo "<td>" . "<div align=\"center\">" . $row['End_User'] . "</div>" . "</td>";
  echo "</tr>";
  $rowclass = 1 - $rowclass;
  }
echo "</table>";mysql_close($conn);
?>

This basically displays a list of purchase orders, there are a couple of thing I need to add - with a little help from you guys:

 

1: Incorporate a tick box that will indicate whether that PO has a corresponding invoice, the SQL table has an invoiced Column.

2: Display the total of the Amount column.

 

Thanks in advance,

B.

Link to comment
Share on other sites

okay but how to i work out the total amount?

ie total amount = account X qty

 

as for the check box i assumed you have a unique ID as if your posting this back to update your need to know what records have been checked, bur for display it doesn't matter to much

 

<?php
mysql_select_db("ipendpoi_Purchase", $conn);
$result = mysql_query("SELECT * FROM po ORDER BY number DESC");
echo "<table width='100%' border='1'>
<tr>
<th>Date</th>
<th>PO Number</th>
<th>Requester</th>
<th>Amount</th>
<th>Vendor</th>
<th>Department</th>
<th>End User</th>
<th>Invoiced</th>
</tr>";
$rowclass = 0;
while($row = mysql_fetch_array($result))
  {
  echo "<tr class = row" . $rowclass . ">";
  echo "<td>" . "<div align=\"center\">" . $row['date'] . "</div>" . "</td>";
  echo "<td>" . "<div align=\"center\">" . "<a href=\"upload_directory/Purchase-Order-" . $row['number'] . ".pdf\">" . $row['number'] . "</a>" . "</div>" . "</td>";
  echo "<td>" . "<div align=\"center\">" . $row['requester'] . "</div>" . "</td>";
  echo "<td>" . "<div align=\"center\">" . "£"  . $row['amount'] . "</div>" . "</td>";
  echo "<td>" . "<div align=\"center\">" . $row['vendor'] . "</div>" . "</td>";
  echo "<td>" . "<div align=\"center\">" . $row['department'] . "</div>" . "</td>";
  echo "<td>" . "<div align=\"center\">" . $row['End_User'] . "</div>" . "</td>";
  echo "<td>" . "<div align=\"center\">";
  /*if the value is "yes" then tick it*/
  $check = ($row['Invoiced'] == "yes")?"checked":"";
  /*I assume you have a unique ID called id*/
  echo "<input type=\"checkbox[".$row['id']."]\" name=\"Invoiced\" $check>";
  echo "</div>" . "</td>";
  echo "</tr>";
  $rowclass = 1 - $rowclass;
  }
echo "</table>";mysql_close($conn);
die;
?>

Link to comment
Share on other sites

I dont think I made myself very clear on this one - sorry, but I was looking for something along these lines:

 

<?
<style>
.rowgreen {
    background-color: #00FF00;
}
.rowred {
    background-color: #FF0000;
}
mysql_select_db("ipendpoi_Purchase", $conn);
$result = mysql_query("SELECT * FROM po ORDER BY number DESC");
echo "<table width='100%' border='1'>
<tr>
<th>Date</th>
<th>PO Number</th>
<th>Requester</th>
<th>Amount</th>
<th>Vendor</th>
<th>Department</th>
<th>End User</th>
<th>Invoiced</th>
</tr>";
function rowclass ( ) {
if ($row['invoiced'] == "Yes")
{return "green";}
else {return "red";}
}
while($row = mysql_fetch_array($result))
  {  
  echo "<tr class = row". rowclass () . ">";
  echo "<td>" . "<div align=\"center\">" . $row['date'] . "</div>" . "</td>";
  echo "<td>" . "<div align=\"center\">" . "<a href=\"upload_directory/Purchase-Order-" . $row['number'] . ".pdf\">" . $row['number'] . "</a>" . "</div>" . "</td>";
  echo "<td>" . "<div align=\"center\">" . $row['requester'] . "</div>" . "</td>";
  echo "<td>" . "<div align=\"center\">" . "£"  . $row['amount'] . "</div>" . "</td>";
  echo "<td>" . "<div align=\"center\">" . $row['vendor'] . "</div>" . "</td>";
  echo "<td>" . "<div align=\"center\">" . $row['department'] . "</div>" . "</td>";
  echo "<td>" . "<div align=\"center\">" . $row['End_User'] . "</div>" . "</td>";
  echo "<td>" . "<div align=\"center\">" . $row['invoiced'] . "<input type=\"checkbox\" name=\"checkbox\" id=\"checkbox\">";
  echo "<input type=\"submit\" name=\"Update\" id=\"Update\" value=\"Submit\">" . "</div>" . "</td>";
  echo "</tr>";
  }
echo "</table>";mysql_close($conn);
?>

 

So when the box is checked and update clicked the line

Link to comment
Share on other sites

The post submitted before I had finished:

 

<?php
<style>
.rowgreen {
    background-color: #00FF00;
}
.rowred {
    background-color: #FF0000;
}
mysql_select_db("ipendpoi_Purchase", $conn);
$result = mysql_query("SELECT * FROM po ORDER BY number DESC");
echo "<table width='100%' border='1'>
<tr>
<th>Date</th>
<th>PO Number</th>
<th>Requester</th>
<th>Amount</th>
<th>Vendor</th>
<th>Department</th>
<th>End User</th>
<th>Invoiced</th>
</tr>";
function rowclass ( ) {
if ($row['invoiced'] == "Yes")
{return "green";}
else {return "red";}
}
while($row = mysql_fetch_array($result))
  {  
  echo "<tr class = row". rowclass () . ">";
  echo "<td>" . "<div align=\"center\">" . $row['date'] . "</div>" . "</td>";
  echo "<td>" . "<div align=\"center\">" . "<a href=\"upload_directory/Purchase-Order-" . $row['number'] . ".pdf\">" . $row['number'] . "</a>" . "</div>" . "</td>";
  echo "<td>" . "<div align=\"center\">" . $row['requester'] . "</div>" . "</td>";
  echo "<td>" . "<div align=\"center\">" . "£"  . $row['amount'] . "</div>" . "</td>";
  echo "<td>" . "<div align=\"center\">" . $row['vendor'] . "</div>" . "</td>";
  echo "<td>" . "<div align=\"center\">" . $row['department'] . "</div>" . "</td>";
  echo "<td>" . "<div align=\"center\">" . $row['End_User'] . "</div>" . "</td>";
  echo "<td>" . "<div align=\"center\">" . $row['invoiced'] . "<input type=\"checkbox\" name=\"checkbox\" id=\"checkbox\">";
  echo "<input type=\"submit\" name=\"Update\" id=\"Update\" value=\"Submit\">" . "</div>" . "</td>";
  echo "</tr>";
  }
echo "</table>";mysql_close($conn);
?>

Link to comment
Share on other sites

okay, but you will still need to change

<input type=\"checkbox\" name=\"checkbox\" id=\"checkbox\">

to

<input type=\"checkbox\" name=\"checkbox[]\" value=\"".$row['ID']."\" id=\"checkbox\">

then you can then do this

print_r($_POST['checkbox']);

to get the IDs of the records you ticked

Link to comment
Share on other sites

BACKUP BACKUP your database

 

this should work but still backup first

 

i hope it makes sense

<style>
.rowgreen {
    background-color: #00FF00;
}
.rowred {
    background-color: #FF0000;
}
<?php
function rowclass ( )
{
if ($row['invoiced'] == "Yes")
{
	return "green";
}else{
	return "red";
}
}

mysql_select_db("ipendpoi_Purchase", $conn);
//1 or more ticked
if(count($_POST['invoiced']) > 0)
{
//Get the values and put them into a comma delimited string
$invoiced = implode(",",$_POST['invoiced']);
//update database
$result = mysql_query("UPDATE po SET invoiced ='Yes' WHERE number IN ($invoiced)");
echo "Updated";
}

$result = mysql_query("SELECT * FROM po ORDER BY number DESC");

echo "<table width='100%' border='1'>
<tr>
<th>Date</th>
<th>PO Number</th>
<th>Requester</th>
<th>Amount</th>
<th>Vendor</th>
<th>Department</th>
<th>End User</th>
<th>Invoiced</th>
</tr>";

echo "<form name=\"form1\" method=\"post\">";
while($row = mysql_fetch_array($result))
  {  
  echo "<tr class = row". rowclass () . ">";
  echo "<td>" . "<div align=\"center\">" . $row['date'] . "</div>" . "</td>";
  echo "<td>" . "<div align=\"center\">" . "<a href=\"upload_directory/Purchase-Order-" . $row['number'] . ".pdf\">" . $row['number'] . "</a>" . "</div>" . "</td>";
  echo "<td>" . "<div align=\"center\">" . $row['requester'] . "</div>" . "</td>";
  echo "<td>" . "<div align=\"center\">" . "£"  . $row['amount'] . "</div>" . "</td>";
  echo "<td>" . "<div align=\"center\">" . $row['vendor'] . "</div>" . "</td>";
  echo "<td>" . "<div align=\"center\">" . $row['department'] . "</div>" . "</td>";
  echo "<td>" . "<div align=\"center\">" . $row['End_User'] . "</div>" . "</td>";
  echo "<td>" . "<div align=\"center\">" . $row['invoiced'] . "<input type=\"checkbox\" name=\"invoiced[]\" value=\"".$row['number']."\" id=\"checkbox\">";
  echo "</tr>";
  }
echo "</table>";mysql_close($conn);
echo "<input type=\"submit\" name=\"Update\" id=\"Update\" value=\"Submit\">";
echo "</form>";
?>

 

EDIT: oops messed up the query (now fixed)

Link to comment
Share on other sites

okay change

i dumped that function as its not needed

<style>
.rowgreen {
    background-color: #00FF00;
}
.rowred {
    background-color: #FF0000;
}
<?php
mysql_select_db("ipendpoi_Purchase", $conn);
//1 or more ticked
if(count($_POST['invoiced']) > 0)
{
   //Get the values and put them into a comma delimited string
   $invoiced = "'".implode("','",$_POST['invoiced'])."'";
   //update database
   $result = mysql_query("UPDATE po SET invoiced ='Yes' WHERE number IN ($invoiced)");
   echo "Updated";
}

$result = mysql_query("SELECT * FROM po ORDER BY number DESC");

echo "<table width='100%' border='1'>
<tr>
<th>Date</th>
<th>PO Number</th>
<th>Requester</th>
<th>Amount</th>
<th>Vendor</th>
<th>Department</th>
<th>End User</th>
<th>Invoiced</th>
</tr>";

echo "<form name=\"form1\" method=\"post\">";
while($row = mysql_fetch_array($result))
  {
  $col = ($row['invoiced'] == "Yes")?"green":"red";
  echo "<tr class = \"row{$col}\" >";
  echo "<td>" . "<div align=\"center\">" . $row['date'] . "</div>" . "</td>";
  echo "<td>" . "<div align=\"center\">" . "<a href=\"upload_directory/Purchase-Order-" . $row['number'] . ".pdf\">" . $row['number'] . "</a>" . "</div>" . "</td>";
  echo "<td>" . "<div align=\"center\">" . $row['requester'] . "</div>" . "</td>";
  echo "<td>" . "<div align=\"center\">" . "£"  . $row['amount'] . "</div>" . "</td>";
  echo "<td>" . "<div align=\"center\">" . $row['vendor'] . "</div>" . "</td>";
  echo "<td>" . "<div align=\"center\">" . $row['department'] . "</div>" . "</td>";
  echo "<td>" . "<div align=\"center\">" . $row['End_User'] . "</div>" . "</td>";
  echo "<td>" . "<div align=\"center\">" . $row['invoiced'] . "<input type=\"checkbox\" name=\"invoiced[]\" value=\"".$row['number']."\" id=\"checkbox\">";
  echo "</tr>";
  }
echo "</table>";
mysql_close($conn);
echo "<input type=\"submit\" name=\"Update\" id=\"Update\" value=\"Submit\">";
echo "</form>";


?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.