Web Hosting Vodahost    

Home Take The Royal Tour! Order Now Features Prices
Go Back   Web Hosting > VodaHost Web Hosting Support > mySQL & PHP

Notices

mySQL & PHP Discussions, information and help with mySQL and PHP.

Reply
 
LinkBack Thread Tools
  #1  
Old 05-04-2008, 05:54 AM
Corporal
 
Join Date: May 2008
Posts: 10
Default Updating multiple fields

Hey guys,
I have a code here that works fine, the problem is i want to update more than 1 field.
PHP Code:
function updateField($username$table$field$value) {
 
con=connect(); //My connection function
 
$query "UPDATE " .$table" SET " .$field"=" .$value" WHERE username='$username'";
 
$result mysql_query($query$con) or die(mysql_error());

Am I allowed to use an array or do I have to use
PHP Code:
while($query "UPDATE " .$table" SET " .$field"=" .$value" WHERE username='$username'";) {
 
mysql_query($query$con);

Thanks
Matt
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #2  
Old 05-04-2008, 06:46 PM
Corporal
 
Join Date: May 2008
Posts: 10
Default Re: Updating multiple fields

Hello?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old 05-07-2008, 03:24 AM
Corporal
 
Join Date: May 2008
Posts: 10
Default Re: Updating multiple fields

Hey guys, thanks for the help ;)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old 05-07-2008, 10:28 AM
navaldesign's Avatar
General & Forum Moderator
 
Join Date: Oct 2005
Location: Italy
Posts: 8,830
Default Re: Updating multiple fields

You got no help because no help can be offered.

There is no way to batch update a database, at least to my knowledge. You can only create a loop that will repeat the same operation as many times as required.
__________________
Navaldesign
Logger Lite: Low Cost, Customizable, multifeatured Login script
Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5  
Old 05-07-2008, 08:26 PM
Corporal
 
Join Date: May 2008
Posts: 10
Default Re: Updating multiple fields

a loop such as
PHP Code:
while($query "UPDATE " .$table" SET " .$field"=" .$value" WHERE username='$username'";) { 
 
mysql_query($query$con); 

?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6  
Old 05-07-2008, 09:30 PM
navaldesign's Avatar
General & Forum Moderator
 
Join Date: Oct 2005
Location: Italy
Posts: 8,830
Default Re: Updating multiple fields

The loop depends on the logic, but there i can't see the logic in the loop you posted. The loop depends on what you need to to.

If you can explain the logic, we will be able to help.
__________________
Navaldesign
Logger Lite: Low Cost, Customizable, multifeatured Login script
Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #7  
Old 05-07-2008, 10:25 PM
Watdaflip's Avatar
Brigadier General
 
Join Date: Sep 2005
Location: Cincinnati, Ohio
Posts: 1,637
Default Re: Updating multiple fields

All that while loop is checking for is if $query = something... which since you are using a string that stays constant its always going to be assigned at the very least
"UPDATE SET WHERE username='$username'"

Now what you need to do is count how many elements are in the array using the count() function. Then just use a for loop (or while loop if you wanted) and go through each element of the array one by one until you have gone through it count() times.

PHP Code:
$count count($array);
for(
$i=0$i $count$i++)
{
// do whatever with... $array[$i]

Also keep in mind (I don't know if this will work in your exact situation), but you can update more then one column of the same row at a time, just format your query like
PHP Code:
UDPATE table_name SET column1='value1'column2='value2'column3='value3' WHERE username='$username' 
__________________
Freelance web programming
Do you need help installing a script, or need one written for you? I do freelance web programming (XHTML, CSS, PHP, MySQL). Feel free to contact me through my website and I will get back to you with a quote asap.

Register/Login Script

Do you use a Password Protected Directory? Need a way to allow users to make their own account, try my .htaccess Login Script
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #8  
Old 05-13-2008, 02:39 AM
Corporal
 
Join Date: May 2008
Posts: 10
Default Re: Updating multiple fields

Quote:
Originally Posted by Phouber View Post
Hey guys, thanks for the help ;)
Sorry if I offended any1 i was just trying to keep the topic active :D
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT +1. The time now is 01:45 AM.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC7
2007 VodaHost.com - All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53