PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

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 Dev Shed Forums Sponsor:
  #1  
Old February 22nd, 2013, 02:21 AM
zxcvbnm's Avatar
zxcvbnm zxcvbnm is offline
A Change of Season
Click here for more information.
 
Join Date: Mar 2004
Posts: 1,599 zxcvbnm User rank is Second Lieutenant (5000 - 10000 Reputation Level)zxcvbnm User rank is Second Lieutenant (5000 - 10000 Reputation Level)zxcvbnm User rank is Second Lieutenant (5000 - 10000 Reputation Level)zxcvbnm User rank is Second Lieutenant (5000 - 10000 Reputation Level)zxcvbnm User rank is Second Lieutenant (5000 - 10000 Reputation Level)zxcvbnm User rank is Second Lieutenant (5000 - 10000 Reputation Level)zxcvbnm User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 2 Weeks 5 Days 18 m 22 sec
Reputation Power: 70
Help needed with update_batch();

Hello;
I have a form with 200+ textareas and I need to create an array and batch_update so I update everything in one hit. The Active Record that I use works like this:
PHP Code:
 $data = array(
   array(
      
'title' => 'My title' ,
      
'name' => 'My Name 2' ,
      
'date' => 'My date 2'
   
),
   array(
      
'title' => 'Another title' ,
      
'name' => 'Another Name 2' ,
      
'date' => 'Another date 2'
   
)
);

$this->db->update_batch('mytable'$data'title');

// Produces:
// UPDATE `mytable` SET `name` = CASE
// WHEN `title` = 'My title' THEN 'My Name 2'
// WHEN `title` = 'Another title' THEN 'Another Name 2'
// ELSE `name` END,
// `date` = CASE
// WHEN `title` = 'My title' THEN 'My date 2'
// WHEN `title` = 'Another title' THEN 'Another date 2'
// ELSE `date` END
// WHERE `title` IN ('My title','Another title') 
Can someone help me fix my form and so I can create the batch array?

This is my form:
Code:
<form action="http://localhost/systematicattraction/" method="post">
<ul>
<?php foreach ($items as $item):
?>
<li><?php echo $item['id'];?>&nbsp;&nbsp;<input name="id[]" checked="checked" type="checkbox" value="<?php echo $item['id'];?>" />&nbsp;<textarea  name="title[]"><?php echo $item['title'];?></textarea></li>
<?php endforeach; ?>
</ul>
<input type="submit" value="Assign" />
</form>
I tried a few things but I didn't succeed.

Reply With Quote
  #2  
Old February 22nd, 2013, 04:05 AM
Jacques1's Avatar
Jacques1 Jacques1 is offline
pollyanna
Click here for more information.
 
Join Date: Jul 2012
Location: Germany
Posts: 1,870 Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 2 Days 22 m 32 sec
Reputation Power: 813
Hi,

automatic indexing with "name[]" won't get you very far, because it only creates simple arrays for each "name".

Make a counter and then use explictit indices:

PHP Code:
<?php

for ($i 0$i 10$i++)
    echo 
'
        <input type="text" name="test[' 
html_escape($i) . '][foo]" />
        <input type="text" name="test[' 
html_escape($i) . '][bar]" />
        <br />
    '
;

Reply With Quote
  #3  
Old February 22nd, 2013, 07:52 PM
zxcvbnm's Avatar
zxcvbnm zxcvbnm is offline
A Change of Season
Click here for more information.
 
Join Date: Mar 2004
Posts: 1,599 zxcvbnm User rank is Second Lieutenant (5000 - 10000 Reputation Level)zxcvbnm User rank is Second Lieutenant (5000 - 10000 Reputation Level)zxcvbnm User rank is Second Lieutenant (5000 - 10000 Reputation Level)zxcvbnm User rank is Second Lieutenant (5000 - 10000 Reputation Level)zxcvbnm User rank is Second Lieutenant (5000 - 10000 Reputation Level)zxcvbnm User rank is Second Lieutenant (5000 - 10000 Reputation Level)zxcvbnm User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 2 Weeks 5 Days 18 m 22 sec
Reputation Power: 70
Quote:
Originally Posted by Jacques1
Hi,

automatic indexing with "name[]" won't get you very far, because it only creates simple arrays for each "name".

Make a counter and then use explictit indices:

PHP Code:
<?php

for ($i 0$i 10$i++)
    echo 
'
        <input type="text" name="test[' 
html_escape($i) . '][foo]" />
        <input type="text" name="test[' 
html_escape($i) . '][bar]" />
        <br />
    '
;
Thanks all sorted but why is html_escape neccessary?

Reply With Quote
  #4  
Old February 23rd, 2013, 04:51 AM
Jacques1's Avatar
Jacques1 Jacques1 is offline
pollyanna
Click here for more information.
 
Join Date: Jul 2012
Location: Germany
Posts: 1,870 Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 2 Days 22 m 32 sec
Reputation Power: 813
In this particular case, it's not necessary. However, I'd generally escape all variables before echoing them, so that there's no risk of accidentally skipping a variable.

Reply With Quote
  #5  
Old February 23rd, 2013, 02:59 PM
zxcvbnm's Avatar
zxcvbnm zxcvbnm is offline
A Change of Season
Click here for more information.
 
Join Date: Mar 2004
Posts: 1,599 zxcvbnm User rank is Second Lieutenant (5000 - 10000 Reputation Level)zxcvbnm User rank is Second Lieutenant (5000 - 10000 Reputation Level)zxcvbnm User rank is Second Lieutenant (5000 - 10000 Reputation Level)zxcvbnm User rank is Second Lieutenant (5000 - 10000 Reputation Level)zxcvbnm User rank is Second Lieutenant (5000 - 10000 Reputation Level)zxcvbnm User rank is Second Lieutenant (5000 - 10000 Reputation Level)zxcvbnm User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 2 Weeks 5 Days 18 m 22 sec
Reputation Power: 70
Quote:
Originally Posted by Jacques1
In this particular case, it's not necessary. However, I'd generally escape all variables before echoing them, so that there's no risk of accidentally skipping a variable.
How did you learn php? What do you recommend for a mid level programmer to do/study to become expert?

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > Help needed with update_batch();

Developer Shed Advertisers and Affiliates



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 | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap