[PHP] Problem with simple update

2003-01-24 Thread Steve Jackson
I am trying to set the order of a set of categories. Previously the
catid field sorted the order of the categories. However I changed this
to Order By catorder and then set about writing a simple update query to
allow people to set the order.

I can't see anything wrong with this:
Basically I pull the details from the categories DB into an array and
then display in a table. This works fine
?
while ($array = mysql_fetch_array($mysql))
{
echo trtd width='150'span class='adminisoleipa';
echo input type='hidden' name='categoryid'
value='{$array[catid]}';
echo {$array[catname]};
echo /tdtdinput type='text' size='2' name='catorder'
value='{$array[catorder]}';
echo /span/td/tr;
}
?
Then using this to update it seems to work till you check the update. It
sets the first two fields to one for some reason.
$query = update categories
 set catorder = '$catorder'
 where catid='$categoryid';

Any suggestions?

Steve Jackson
Web Developer
Viola Systems Ltd.
http://www.violasystems.com
[EMAIL PROTECTED]
Mobile +358 50 343 5159


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




Re: [PHP] Problem with simple update

2003-01-24 Thread Marek Kilimajer
remove the hidden field and use

input type='text' size='2' name='catorder[{$array[catid]}]' value='{$array[catorder]}'

in action script you do

foreach($_POST['catorder'] as $catid = $catorder) {
   update categories set catorder=$catorder where catid=$catid
}

Steve Jackson wrote:


I am trying to set the order of a set of categories. Previously the
catid field sorted the order of the categories. However I changed this
to Order By catorder and then set about writing a simple update query to
allow people to set the order.

I can't see anything wrong with this:
Basically I pull the details from the categories DB into an array and
then display in a table. This works fine
?
while ($array = mysql_fetch_array($mysql))
{
echo trtd width='150'span class='adminisoleipa';
echo input type='hidden' name='categoryid'
value='{$array[catid]}';
echo {$array[catname]};
echo /tdtdinput type='text' size='2' name='catorder'
value='{$array[catorder]}';
echo /span/td/tr;
}
?
Then using this to update it seems to work till you check the update. It
sets the first two fields to one for some reason.
$query = update categories
set catorder = '$catorder'
where catid='$categoryid';

Any suggestions?

Steve Jackson
Web Developer
Viola Systems Ltd.
http://www.violasystems.com
[EMAIL PROTECTED]
Mobile +358 50 343 5159


 



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




Re: [PHP] Problem with simple update

2003-01-24 Thread Marek Kilimajer
You must run

$result = mysql_query($query) or die(Query failure:  .mysql_error());

within the foreach loop, else $query will be only the last query assigned.

If you use get method in your form you need to use $_GET (or $_REQUEST) 
instead of $_POST

Steve Jackson wrote:

I can't get this to work.
I am trying to update multiple rows at the same time?
This is the code I have now adjusted to your specifications:
?
while ($array = mysql_fetch_array($mysql))
{
echo trtd width='150'span class='adminisoleipa';
//echo input type='hidden' name='categoryid{$array[catid]}';
echo {$array[catname]};
echo /tdtdinput type='text' size='2'
name='catorder[{$array[catid]}]' value='{$array[catorder]}'
;
//echo /tdtdinput type='text' size='2' name='catorder'
value='{$array[catorder]}';
echo /span/td/tr;
}
?

And the action:
foreach($_POST[catorder] as $catid = $catorder) 
	{
   $query = update categories set catorder=$catorder where
catid=$catid; 
	}
$result = mysql_query($query) or die(Query failure:  .mysql_error());

The error:
Warning: Invalid argument supplied for foreach() in
eshop_processcatorder.php on line 27
Query failure: Query was empty

Steve Jackson
Web Developer
Viola Systems Ltd.
http://www.violasystems.com
[EMAIL PROTECTED]
Mobile +358 50 343 5159





 

-Original Message-
From: Marek Kilimajer [mailto:[EMAIL PROTECTED]] 
Sent: 24. tammikuuta 2003 13:55
To: Steve Jackson
Cc: PHP General
Subject: Re: [PHP] Problem with simple update


remove the hidden field and use

input type='text' size='2' 
name='catorder[{$array[catid]}]' value='{$array[catorder]}'

in action script you do

foreach($_POST['catorder'] as $catid = $catorder) {
   update categories set catorder=$catorder where catid=$catid }

Steve Jackson wrote:

   

I am trying to set the order of a set of categories. Previously the 
catid field sorted the order of the categories. However I 
 

changed this 
   

to Order By catorder and then set about writing a simple 
 

update query 
   

to allow people to set the order.

I can't see anything wrong with this:
Basically I pull the details from the categories DB into an 
 

array and 
   

then display in a table. This works fine ?
while ($array = mysql_fetch_array($mysql))
{
echo trtd width='150'span class='adminisoleipa';
echo input type='hidden' name='categoryid'
value='{$array[catid]}';
echo {$array[catname]};
echo /tdtdinput type='text' size='2' name='catorder'
value='{$array[catorder]}';
echo /span/td/tr;
}
?
Then using this to update it seems to work till you check 
 

the update. It
   

sets the first two fields to one for some reason.
$query = update categories
   set catorder = '$catorder'
   where catid='$categoryid';

Any suggestions?

Steve Jackson
Web Developer
Viola Systems Ltd.
http://www.violasystems.com
[EMAIL PROTECTED]
Mobile +358 50 343 5159




 


 



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