Good Day. Call me Angel.
I'm havng trouble with Live Edit Table. Appears not to be working for me. I have this system. A small rental system actually, that would save the details for the rented properties. Here's the actual table:

<img src="https://fbcdn-sphotos-g-a.akamaihd.net/hphotos-ak-xpa1/t1.0-9/10314749_882248248457445_2787632760191268129_n.jpg">
(other columns are trimmed)

The admin has to fill the information needed to display the details of the property into a table. Then the database would post all the said details except for the No. of Rented Property/ies column. (must be empty at first until a client came for tenancy) That is when the column No.ofRentedProperty must fill. I'm trying to capture the idea of a Live Table Edit similar to the comments function in facebook. Where user could place a comment by just clicking a textbox (but on my part should be a hidden textbox on a span tag) then enters his/her post.

I tried to insert a made-up record as an example, everything has been successfully saved on the database and displays on the table (just as the plan) But when I tried the Live Edit to place a value for the No.ofRentedProperty, nothing happens. I mean, it does act like that of commmentbox on FB, but as soon as I hit enter, it actually didn't save. I found that very disturbing since the column for Amount Tendered relies on it. This column should multiply the value of No.ofRentedProperty to the Rent Cost (just another column beside) and display to its cell. But, since the Live Edit isn't working, even the Amount Tendered sisplays nothing.

You see on the image that there is a row where everything was properly displayed. That is when I tried to manually insert the next record on the database. That is when the multiplication works. But the manual use of insert statement isn't an option right? What's the point of having the system anyway?

Do you guys have any idea how to make this Live Edit Work? After all, only one column is being involved which is the NoOfRentedProperty. Suggestion?

Recommended Answers

All 2 Replies

Your situation is not clear to me. Please be more descriptive. Paste more code here possibly the html form.

sorry... am not so good in explaning. Anyways, I have 3 .php file for this system. 1. index which is the first page displays the record and stuffs obviously. 2. is the table_edit that has the insert/update statement (use to update the table for No.ofRemainingProperties and insert No.ofRentedProperties), and 3rd was the saveinfo where the original insert statement from textboxes on the tab at the side of index was taken.

By default, the index must display the details from the db. On its side was a tab where the textboxes gathers the record for the ff: property_details,tenant,location,price,qty and the startDate. This will all go to the saveinfo.php. Once saved, the index would retrieve the everything from the db.
Well, not really everything since the No.ofRentedProperties must be empty. only the values of the ff columns would be displayed: Date, Stall Details, Tenant, No.ofRemaining Property and Rent Cost. The remaining property column has the original quantity. It will be reduced however when a value was added to RentedProperty.

Only when a value for No.ofRentedProperty was added through a live_edit_table format (similar to that of FB commentbox) should the the Amount Tendered would display the product of No.RentedProperty*Rent Cost.

here are the codes:

index.php

$sql=mysql_query("select * from inventory");
$i=1;
while($row=mysql_fetch_array($sql))
{
$id=$row['id'];
$item=$row['item'];
$tenant=$row['details'];
$location=$row['location'];
$qtyleft=$row['qtyleft'];
$qtysold=$row['qtysold'];
$price=$row['price'];
$sales=$row['sales'];
$date=$row['startDate'];

if($i%2)
{
?>
<tr id="<?php echo $id; ?>" class="edit_tr">
<?php } else { ?>
<tr id="<?php echo $id; ?>" bgcolor="#f2f2f2" class="edit_tr">
<?php } ?>
<input type="text" value="<?php echo $id; ?>" name="uid" hidden>
<td class="edit_td">
<span class="text"><?php echo $date; ?></span> 
</td>
<td>
<span class="text"><?php echo $item; ?></span> 
</td>
<td>
<span class="text"><?php echo $tenant; ?></span> 
</td>
<td>
<span class="text"><?php echo $location; ?></span> 
</td>
<td>
<span class="text"><?php echo $qtyleft; ?></span>
</td>
<td>

<span id="last_<?php echo $id; ?>" class="text">
<?php
$sqls=mysql_query("select * from sales where date='$date' and inventory_id='$id'");
while($rows=mysql_fetch_array($sqls))
{
echo $rows['qty'];
$rtrt=$rows['qty'];
}
?>
</span> 
<input type="text" value="<?php echo $qtyleft; ?>"  class="editbox" id="last_input_<?php echo $id; ?>" name="id"/>
</td>
<td>
<span id="first_<?php echo $id; ?>" class="text"><?php echo $price; ?></span>
<input type="text" value="<?php echo $price; ?>" class="editbox" id="first_input_<?php echo $id; ?>" />
</td>
<td>

<span class="text">
<?php
$sqls=mysql_query("select * from sales where date='$date' and inventory_id='$id'");
while($rows=mysql_fetch_array($sqls))
{
$rtyrty=$rows['qty'];
$rrrrr=$rtyrty*$price;
echo $rrrrr;
}

?>
</span> 
</td>
</tr>

<?php
$i++;
}
?>

</table>

<br />
Total Sales of this day:
        <b>Php <?php
function formatMoney($number, $fractional=false) {
    if ($fractional) {
        $number = sprintf('%.2f', $number);
    }
    while (true) {
        $replaced = preg_replace('/(-?\d+)(\d\d\d)/', '$1,$2', $number);
        if ($replaced != $number) {
            $number = $replaced;
        } else {
            break;
        }
    }
    return $number;
}       
$result1 = mysql_query("SELECT sum(sales) FROM sales where date='$date'");
while($row = mysql_fetch_array($result1))
{
    $rrr=$row['sum(sales)'];
    echo formatMoney($rrr, true);
 }

?>

table_edit.php

<?php
include("db.php");
if($_POST['id'])
{
$id=mysql_escape_String($_POST['id']);
$qty_sold=mysql_escape_String($_POST['qtysold']);
$price=mysql_escape_String($_POST['price']);
$da=$_POST['startDate'];
$qty=$_POST['qty'];
$sql=mysql_query("select * from inventory where id='$id'");
while($row=mysql_fetch_array($sql))
{
$qtyleft=$row['qtyleft'];
$price=$row['price'];
}
$ssss=$qtyleft-$qty_sold;
$sale=$qty_sold*$price;
$sales_sql=mysql_query("select * from sales where date='$da' and inventory_id='$id'");
$count=mysql_num_rows($sales_sql);

if($count==0)
{
mysql_query("INSERT INTO sales (inventory_id, qty, date, sales) VALUES ('$id','$qty_sold','$da','$sale')");
}
if($count!=0)
{
mysql_query("UPDATE sales set qty='$qty+$qty_sold',sales='$sale' where date='$da' and inventory_id='$id'");
}

$sql = "update inventory set qtyleft='$ssss',price='$price',sales=sales+'$sale',qty_sold=qty_sold+'$qty_sold' where id='$id'";
mysql_query($sql);
}
?>

saveinfo.php

<?php
include("db.php");
$proname=$_POST['proname'];
$tenant=$_POST['tenant'];
$location=$_POST['location'];
$price=$_POST['price'];
$pqty=$_POST['pqty'];
$qtysold=$_POST['qtysold'];
$date=$_POST['startDate'];
mysql_query("INSERT INTO inventory (item,details,location,qtyleft,qtysold,price,startDate) VALUES ('$proname','$tenant','$location','$pqty','$qtysold','$price','$date')");
?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.