CodeCharge Studio
search Register Login  

Web Reporting

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> Archive -> GotoCode Archive

 Delete in grid by 0 input

Print topic Send  topic

Author Message
Ivo
Posted: 06/04/2003, 2:31 PM

User: CC, PHP, MySql, WinXP

Oke maybe this is a (new) idea to solve my problem. But I need some help.., please.
I want my grid (my shoppingbasket) has the option to delete the product and update the quantity of the product. I don't
know how to delete by checkbox and update quantity in one form:
http://www.gotocode.com/disc_viewt.asp?mid=21367

So maybe my new idea works better and easyer. I want to use the update script (page's open event) :

$max = dLookUp("orderline", "max(orderline_id)", "1=1");
$min = dLookUp("orderline", "min(orderline_id)", "1=1");

for ($i=$min; $i<= $max; $i++)
{
$quantity = get_param("$i");
if ($quantity != "")
{
$quantity = str_replace(",", ".", $quantity);
$sSQLu = "UPDATE orderline SET quantity=" . $quantity . " WHERE orderline_id=".$i;
$db->query($sSQLu);
}
}

and I want to build in this script the option like:
if quantity input is 0 delete from orderline where orderline_id=".$i;

I worked very hard (with my poor PHP experience) to let this work and my deadline for my school project is this week :-(
so maybe somebody can help me..

I think it must be someting like this, but it does not work:

$max = dLookUp("orderline", "max(orderline_id)", "1=1");
$min = dLookUp("orderline", "min(orderline_id)", "1=1");

for ($i=$min; $i<= $max; $i++)
{
$quantity = get_param("$i");
if ($quantity != "")
{
$quantity = str_replace(",", ".", $quantity);
$sSQLu = "UPDATE orderline SET quantity=" . $quantity . " WHERE orderline_id=".$i;
$db->query($sSQLu);
}
else if ($quantity = "0")
{
$sSQLd = "delete from orderline where orderline_id=".$i;
$db->query($sSQLu);
}
}

Please help me.
Best Regards,
Ivo
Karen
Posted: 06/04/2003, 5:53 PM

Why don't you use checkbox and then have 2 buttons, one update and one delete? Depending on which button is clicked, then execute the corresponding SQL statement on the rows where the checkbox(es) are checked.

Hope that helps.
rclayh
Posted: 06/04/2003, 6:33 PM

I don't know if CodeCharge will do this but in Studio you can just use the updateable grid builder. Set the quantity field to an editable text box. Set all the other field values to labels and CodeCharge Studio will add the delete checkbox at the end of the record. Does it work the same in CC?
Ivo
Posted: 06/04/2003, 11:34 PM

rclayh:
no there is not a option in cc like that. now I know why I must use studio ;).

Karen:
Maybe it is an option but not so clear how to do that. You have a idea? Now I have in the header and footer the script for the form and button:
<form name="grid" method="GET" action="shop.php">
...
<input type=submit value=submit> </form>

Tnx
Karen
Posted: 06/05/2003, 1:32 AM

Here's an example that I've done but I've left out the details in between since it's not applicable. But it's much easier to use CCS if you can. I've tried both and CCS does it without any extra coding.

Anyway, this sample does 2 things. If button 'Create New Order' is clicked, then new records will be inserted into a new order (order number auto-increment), else button 'Copy to Order' is clicked, the records will be copied to the order number selected. You can adapt this to delete and update buttons. I've assumed you know how to code the checkboxes and all the other stuff related to editable grid as detailed in the tips/articles.

In the form header, you have something like this...
-----------------------------------------------------
<Form name="grid" action="Admin_CreateOrder.php" method="post">

Then in the form footer, you have something like this...
---------------------------------------------------------
<input type="submit" name=button value="Create New Order">
<font style="font-size:10pt; color:#000000">User ID: </font><input type="text" name=userid size="3">
blah, blah, etc.......
<input type="submit" name=button value="Copy to Order">
<font style="font-size:10pt; color:#000000">Order No.: </font><input type="text" name=order size="6">
</Form>

This will give you the 2 buttons.


Then in the form open event
----------------------------
$order_action = get_param("button");

if(strcmp($order_action,"Create New Order")==0)
{
blah, blah, etc
}
else
{
if(strcmp($order_action,"Copy to Order")==0)
{
blah, blah, etc
}
}


Hope this helps.
Ivo
Posted: 06/05/2003, 2:03 AM

What is "strcmp" in the script?
Ivo
Posted: 06/05/2003, 3:27 AM

I wrote the script but I have a error..
Parse error: parse error, unexpected $ in C:\Inetpub\wwwroot\shop\shop.php on line 338

The page's open event script:

$max = dLookUp("orderline", "max(orderline_id)", "1=1");
$min = dLookUp("orderline", "min(orderline_id)", "1=1");

for ($i=$min; $i<= $max; $i++)
{
$order_action = get_param("button");
$aantal = get_param("$i");
$box = get_param("$i");

if(strcmp($order_action,"update")==0)
{
$aantal = str_replace(",", ".", $aantal);
$sSQLu = "UPDATE orderline SET aantal=" . $aantal . " WHERE orderline_id=".$i;
$db->query($sSQLu);
}
else
{
if(strcmp($order_action,"delete")==0)
{
$sSQLd = "delete from orderline where orderline_id=".$i;
$db->query($sSQLd);
}
}

Before show is:
$fldbox = "<input type=checkbox name=$fldorderline_id value=OFF>";
$fldaantal = "<input type=text name=" . $fldorderline_id . " value=". $fldaantal ." size=4>";

Header / Footer.
<Form name="grid" action="shop.php" method="post">
..
<input type="submit" name=button value="update">
<input type="submit" name=button value="delete">
</Form>

Maybe you can see something that is not good in the script.
Best Regards
Ivo
Tom
Posted: 06/05/2003, 3:40 AM

You need an extra } at the end
Ivo
Posted: 06/05/2003, 4:12 AM

The update works very good, but when I delete all my products ar deleted from the basket and not only the on I checked..
Ivo
Posted: 06/05/2003, 1:46 PM

Who can help me? I think I almost have the solution, and a big problem is now a small problem. I have everything working (thanks to Karen). But I'm working this day on one small problem and I can not fix it. With the latest script I can update and I can check a product with the checkbox and delete. But the problem is when I want to delete, all the products of the shoppingcard are gone.. Not only the checked one..

Thanks for helping, I hope my last post about this subject ;)

Ivo
Karen
Posted: 06/05/2003, 7:08 PM

It looks like your checkbox is not really working, i.e., you are not retrieving its value properly. The update is not affected probably becoz it just updates to the same and you won't even notice it. Why don't you check out how to set the checkbox in this article http://www.gotocode.com/art.asp?art_id=51&.

That's where I adapted my own code from. If you're still having problems, I'll try to post some of my own code here but you'll have to check out how to use the php functions from the manual yourself or goto www.php.net to check.

Hope that helps!
ivo
Posted: 06/06/2003, 4:47 AM

It works now. Changes are:

In the open event:
if ($box==0)

and in the before show:
$fldbox = "<input type=checkbox name=" . $fldorderline_id . " value=0>";

Thanks for helping!
Ivo

   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

Web Database

Join thousands of Web developers who build Web applications with minimal coding.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.