SunQuest
           PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsPHP RelatedPHP Coding

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old September 17th, 2002, 07:42 AM
Klyve1 Klyve1 is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Hove, UK
Posts: 10 Klyve1 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to Klyve1
INSERT question

Hi,
I have a page with multiple checkboxes that I then use to populate a table with those chosen... using this code:

$insert_act = "INSERT INTO `actlookup` (`acID`, `vID`, `actID`) VALUES ('', '', '')";

while(list($keyc, $Act) = each($acts))
{
$insert_act .= ", ('', '$vID', '$Act') "; }
$query = ($insert_act);
$result = mysql_query($query);

But as you can see I have used an empty row insert to allow me to use subsequent commas for the additional chosen options. Is there a way to use the first array item ($acts[0]) for this empty line and then the subsequent items in the latter code? I'm not sure if I've made this clear, let mme know. Cheers
Klyve

Reply With Quote
  #2  
Old September 17th, 2002, 08:24 AM
greggory greggory is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Reims, France
Posts: 82 greggory User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
RE: INSERT question

Do this
php Code:
Original - php Code
  1.  
  2. <?php
  3. $insert_act = "INSERT INTO `actlookup` (`acID`, `vID`, `actID`) VALUES ";
  4.  
  5. while(list($keyc, $Act) = each($acts))
  6. {
  7. $insert_act .= "('', '$vID', '$Act'),"; }
  8. $result = mysql_query(ereg_replace(",$","",$insert_act));
  9. ?>

Reply With Quote
  #3  
Old September 17th, 2002, 03:04 PM
Klyve1 Klyve1 is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Hove, UK
Posts: 10 Klyve1 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to Klyve1
RE: INSERT question

Thanks, that works great but I don't understand how it does work! It appears to still leave the trailing comma on the INSERT statement and in the past I haven't managed to get that to work.
Klyve

Reply With Quote
  #4  
Old September 17th, 2002, 03:41 PM
guyer guyer is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Bloomington, IN USA
Posts: 47 guyer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via Yahoo to guyer
RE: INSERT question

That ereg_replace() should remove the trailing comma. You can also use substr($insert_act,0,strlen($insert_act)).

Reply With Quote
  #5  
Old September 17th, 2002, 04:36 PM
Klyve1 Klyve1 is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Hove, UK
Posts: 10 Klyve1 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to Klyve1
RE: INSERT question

It doesn't appear so if I print the query to the screen but as it works I must assume it knocks the trailing comma off.
Thanks
Klyve

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPHP Coding > INSERT question


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway