Re: [PHP] Re: Using one submit button

2002-04-17 Thread Kevin Stone

Looks good except the names in your HTML input fields are going to be id[]
and price[].. no $i in there.  Keep in mind there's probably a more
efficient way of doing this.  But sometimes programming is just about making
things work.. you can worry about the details later.  :D
-Kevin


- Original Message -
From: "Jennifer Downey" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, April 17, 2002 12:07 PM
Subject: Re: [PHP] Re: Using one submit button


> Thank you Jason and Kevin for your time and help.
>
> Does this look like what I should have?
>
> if(isset($update))
> for ($i=0; $i {
> if ($id[$i] == $row[id])
> {
>
>
>  $query = "UPDATE {$config["prefix"]}_shop SET price = $price[$i]
> where uid = {$session["uid"]} AND id = $id[$i]";
>  $ret = mysql_query($query) or die(mysql_error());
> }
> else
> {
>
>  echo " name=\"id[$i]\" value=\"$id\"> name=\"price[$i]\" size='8' MAXLENGTH='8'>";
>
> Jennifer
>
> "Kevin Stone" <[EMAIL PROTECTED]> wrote in message
> 004301c1e633$e1e20090$6601a8c0@kevin">news:004301c1e633$e1e20090$6601a8c0@kevin...
> > -
> > I picked up your question soon after you submited it then my internet
went
> > down so I wasn't able to send it.  Looks like it's been answered by
> someone
> > else since then but here you go anyway.  I didn't want to feel as though
> I'd
> > wasted my time.  :D
> > -kevin
> > -
> >
> > Looks like you want to extract the values from the $price array in the
> same
> > order as you extracted the associated rows from the database.  At first
> > glance I can say you aren't passing enough information to be able to
> > determine an order for updating. You'll need to send the product ids
along
> > with the prices and then create a counter to loop through the ids array
> and
> > test each case.
> >
> > I would sugget you build an $id[] list the same way as the $price[] list
> but
> > generate them as hidden fields.  Then within the if(isset($update))
> > statement loop through all $id values for each itteration of the while
> > loop...
> >
> > for ($i=0; $i > {
> > if ($id[$i] == $row[id])
> > {
> > // we know that there are the same number of ids as there are
> prices
> > so we can use $i for the $price index as well.
> > $query = "UPDATE $table SET price = $price[$i] WHERE id =
> $id[$i]";
> > // do update..
> > }
> > }
> >
> > -Kevin
> >
> > - Original Message -
> > From: "Jennifer Downey" <[EMAIL PROTECTED]>
> > To: <[EMAIL PROTECTED]>
> > Sent: Wednesday, April 17, 2002 10:11 AM
> > Subject: [PHP] Re: Using one submit button
> >
> >
> > > I have no takers on this one?
> > >
> > > Just to let you know I have been working on this to here is some new
> code.
> > > What I need this to do is update the price in the db table.
> > >  if I have on item it is fine. If I have two items it won't update the
> > first
> > >  items price but will the second. if I try to enter a price in the
first
> > >  items textbox it doesn't update and then deletes the second item's
> price.
> > >
> > >  If I have 15 items and using one submit button how do I get this to
> > update
> > >  all items that are listed?
> > >
> > > $query = "SELECT uid, id, name, image, type, quantity, price FROM
> > > {$config["prefix"]}_shop WHERE uid = {$session["uid"]}";
> > >$ret = mysql_query($query);
> > >while($row = mysql_fetch_array($ret))
> > > {
> > >$uid = $row['uid'];
> > >$id = $row['id'];
> > >$name = $row['name'];
> > >$image = $row['image'];
> > >$iquantity = $row['quantity'];
> > >$itype = $row['type'];
> > >$iprice = $row['price'];
> > >
> > > if($update)
> > > {
> > >  $eprice = '$price[]';
> > >  $query = "UPDATE {$config["prefix"]}_shop SET price =
'$eprice'
> > > where uid = {$session["uid"]} AND id = '$id'";
> > >  $ret = mysql_query($query) or die(mysql_error());
> > > }
> > > else
> > > {
> > >

Re: [PHP] Re: Using one submit button

2002-04-17 Thread Jennifer Downey

Thank you Jason and Kevin for your time and help.

Does this look like what I should have?

if(isset($update))
for ($i=0; $i";

Jennifer

"Jason Wong" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]...
> On Thursday 18 April 2002 00:11, Jennifer Downey wrote:
> > I have no takers on this one?
> >
> > Just to let you know I have been working on this to here is some new
code.
> > What I need this to do is update the price in the db table.
> >  if I have on item it is fine. If I have two items it won't update the
> > first items price but will the second. if I try to enter a price in the
> > first items textbox it doesn't update and then deletes the second item's
> > price.
> >
> >  If I have 15 items and using one submit button how do I get this to
update
> >  all items that are listed?
> >
> > $query = "SELECT uid, id, name, image, type, quantity, price FROM
> > {$config["prefix"]}_shop WHERE uid = {$session["uid"]}";
> >$ret = mysql_query($query);
> >while($row = mysql_fetch_array($ret))
> > {
> >$uid = $row['uid'];
> >$id = $row['id'];
> >$name = $row['name'];
> >$image = $row['image'];
> >$iquantity = $row['quantity'];
> >$itype = $row['type'];
> >$iprice = $row['price'];
> >
> > if($update)
> > {
> >  $eprice = '$price[]';
>
> I don't know what else is wrong with your code, but this is *definitely*
> going to cause problems.
>
> I assume you mean:
>
>   $eprice = $price[];
>
> But even this is wrong. You should probably be keeping a counter, eg $i,
then
> use:
>
>   $eprice = $price[$i];
>
> [snip]
>
> > value=\"\" name=\"price[]\" size='8'
>
>   value=\"\" name=\"price[$i]\" size='8'
>
> --
> Jason Wong -> Gremlins Associates -> www.gremlins.com.hk
> Open Source Software Systems Integrators
> * Web Design & Hosting * Internet & Intranet Applications Development *
>
> /*
> We have a equal opportunity Calculus class -- it's fully integrated.
> */


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.344 / Virus Database: 191 - Release Date: 4/2/2002



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Re: Using one submit button

2002-04-17 Thread Jennifer Downey

Thank you Jason and Kevin for your time and help.

Does this look like what I should have?

if(isset($update))
for ($i=0; $i";

Jennifer

"Kevin Stone" <[EMAIL PROTECTED]> wrote in message
004301c1e633$e1e20090$6601a8c0@kevin">news:004301c1e633$e1e20090$6601a8c0@kevin...
> -
> I picked up your question soon after you submited it then my internet went
> down so I wasn't able to send it.  Looks like it's been answered by
someone
> else since then but here you go anyway.  I didn't want to feel as though
I'd
> wasted my time.  :D
> -kevin
> -
>
> Looks like you want to extract the values from the $price array in the
same
> order as you extracted the associated rows from the database.  At first
> glance I can say you aren't passing enough information to be able to
> determine an order for updating. You'll need to send the product ids along
> with the prices and then create a counter to loop through the ids array
and
> test each case.
>
> I would sugget you build an $id[] list the same way as the $price[] list
but
> generate them as hidden fields.  Then within the if(isset($update))
> statement loop through all $id values for each itteration of the while
> loop...
>
> for ($i=0; $i {
> if ($id[$i] == $row[id])
> {
> // we know that there are the same number of ids as there are
prices
> so we can use $i for the $price index as well.
> $query = "UPDATE $table SET price = $price[$i] WHERE id =
$id[$i]";
> // do update..
> }
> }
>
> -Kevin
>
> - Original Message -
> From: "Jennifer Downey" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Wednesday, April 17, 2002 10:11 AM
> Subject: [PHP] Re: Using one submit button
>
>
> > I have no takers on this one?
> >
> > Just to let you know I have been working on this to here is some new
code.
> > What I need this to do is update the price in the db table.
> >  if I have on item it is fine. If I have two items it won't update the
> first
> >  items price but will the second. if I try to enter a price in the first
> >  items textbox it doesn't update and then deletes the second item's
price.
> >
> >  If I have 15 items and using one submit button how do I get this to
> update
> >  all items that are listed?
> >
> > $query = "SELECT uid, id, name, image, type, quantity, price FROM
> > {$config["prefix"]}_shop WHERE uid = {$session["uid"]}";
> >$ret = mysql_query($query);
> >while($row = mysql_fetch_array($ret))
> > {
> >$uid = $row['uid'];
> >$id = $row['id'];
> >$name = $row['name'];
> >$image = $row['image'];
> >$iquantity = $row['quantity'];
> >$itype = $row['type'];
> >$iprice = $row['price'];
> >
> > if($update)
> > {
> >  $eprice = '$price[]';
> >  $query = "UPDATE {$config["prefix"]}_shop SET price = '$eprice'
> > where uid = {$session["uid"]} AND id = '$id'";
> >  $ret = mysql_query($query) or die(mysql_error());
> > }
> > else
> > {
> >
> >  echo " > CELLSPACING='0'>";
> >  echo "";
> >  echo "$name";
> >  echo " > size=2>$iquantity";
> >  echo " > href='$PHP_SELF?id=$id&remove=yes'>X";
> >  echo " > value=\"\" name=\"price[]\" size='8'
> > MAXLENGTH='8'>";
> >  echo "";
> >echo "";
> > }
> > }
> > echo " > Prices\">";
> > echo "";
> > "Jennifer Downey" <[EMAIL PROTECTED]> wrote in message
> > [EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> > > Hi all,
> > >
> > > I thought I was going to give php a break today but I can't it's too
> > > adicting.
> > >
> > > I am having a little problem with a submit button in which it is
suppose
> > to
> > > update records from a form.
> > >
> > > Here is the code
> > >
> >
>
> --
> > --
> > > 
> > >
> > >
> > > echo "My Locker |  > > href=\"myshop.php\">My Shop | My
> > > Items";
> > > echo " > CELLSPACING='0'> > > width=20%>Image > > size=2>Name > > size=2>Quantity > > size=2>Remove Item width=30%> > > size=2>Price";
> > > echo "";
> > >
> > >  $query = "SELECT uid, id, name, image, type, quantity FROM
> > > {$config["prefix"]}_shop WHERE uid = {$session["uid"]}";
> > >  $ret = mysql_query($query);
> > >  while($row = mysql_fetch_array($ret))
> > > {
> > >  $uid = $row['uid'];
> > >  $id = $row['id'];
> > >  $name = $row['name'];
> > >  $image = $row['image'];
> > >  $iquantity = $row['quantity'];
> > >  $itype = $row['type'];
> > >
> > >
> > >  echo " > > CELLSPACING='0'>";
> > >  echo "";
> > >  echo "$name";
> > >  echo " > > size=2>$iquantity";
> > >  echo " > > href='$PHP_SELF?id=$id&remove=yes'>X";
> > >  echo " type=\"text\"
> > > value=\"\" name=\"price\" size='6'
> > > MAXLENGTH='8'>";
> > >  echo "";
> > >
> > >  echo "";
> > > }
> > > echo " > > Prices\">";
> > > 

Re: [PHP] Re: Using one submit button

2002-04-17 Thread Jason Wong

On Thursday 18 April 2002 00:11, Jennifer Downey wrote:
> I have no takers on this one?
>
> Just to let you know I have been working on this to here is some new code.
> What I need this to do is update the price in the db table.
>  if I have on item it is fine. If I have two items it won't update the
> first items price but will the second. if I try to enter a price in the
> first items textbox it doesn't update and then deletes the second item's
> price.
>
>  If I have 15 items and using one submit button how do I get this to update
>  all items that are listed?
>
> $query = "SELECT uid, id, name, image, type, quantity, price FROM
> {$config["prefix"]}_shop WHERE uid = {$session["uid"]}";
>$ret = mysql_query($query);
>while($row = mysql_fetch_array($ret))
> {
>$uid = $row['uid'];
>$id = $row['id'];
>$name = $row['name'];
>$image = $row['image'];
>$iquantity = $row['quantity'];
>$itype = $row['type'];
>$iprice = $row['price'];
>
> if($update)
> {
>  $eprice = '$price[]';

I don't know what else is wrong with your code, but this is *definitely* 
going to cause problems.

I assume you mean:

  $eprice = $price[];

But even this is wrong. You should probably be keeping a counter, eg $i, then 
use:

  $eprice = $price[$i];

[snip]

> value=\"\" name=\"price[]\" size='8'

  value=\"\" name=\"price[$i]\" size='8'

-- 
Jason Wong -> Gremlins Associates -> www.gremlins.com.hk
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *

/*
We have a equal opportunity Calculus class -- it's fully integrated.
*/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php