Fork me on GitHub
Get XOOPS XOOPSXOOPS FAQFAQ ForumsForums NewsNews ThemesThemes ModulesModules
New Posts New Topics All Posts All Forums Index General Modules Themes Development International XOOPS.org

Search

Donat-O-Meter

Make donations with PayPal!
Stats
Goal: $100.00
Due Date: Apr 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00

Learn XOOPS Core

Local Support

Advertisement

XOOPS Code hosted on SourceForge

Cumulus Tag Cloud

- 2 2.5 2.6 3.0 4 6 adslight Android AntiHarvesting AntiMalUser AntiSpam Apple Battlefield billige Blocks Bootstrap Captcha cell cent chronolabs CHUNG Clicks content CĂN demo docek download Dresses evden eve facebook Fat floor Food for free Gateway Google Guide herre Home Honeypot HP html5 Human HỘ IP iPhone jQuery List log Loss module modules Monster new newbb news NHÀ online PARK phone PHP Prevention profile project Protector publisher RESIDENCE responsive review Rights rmcommon Room security Sentry site Smartphone Smarty Smoking Spam stem Studio support tag tdmcreate template The Theme themes User userlog weight xoops Xortify XPayment ZendFramework

New Users

Registering user

# 137297

gregblevins

Welcome to XOOPS!

Forum Index


Board index » All Posts

Bottom   Previous Topic   Next Topic

(1) 2 3 4 ... 29664 »


#1 Posted on: Today 2:10 Re: Inserting multiple rows in database table
After briefly looking at your code....
For starters You need to put the foreach loop inside of the for loop instead of outside of it.

As is $datas is only going to contain the last copy of the array and you will only load the database with this last entry.

You need to place it inside the for loop in order for you to properly step through all of the entries.

Your foreach loop looks ok otherwise to me but I might be missing something.

You really need to first get your code in the right place and if it still isn't working you need to step through the code.

As zyspec mentioned you also need to make sure the database isn't setup with a unique field because if you keep running your code and you are only seeing one entry this is because you are only updating the entry you have instead of making a new one due to the unique field.

Your first $datas = array(); line is unnecessary because you are doing it a couple of lines later. Although this shouldn't cause any issues as is otherwise.

I also agree with Zyspecs comments about creating the object and deleting it afterwards. Otherwise your object could contain items you don't expect.
Rodney

Top

redheadedrod
Home away from home
Home away from home
Joined:
2008/2/26 10:05
From Grand Rapids, MI
Group:
Registered Users
Posts: 1249
(Show More) (Show Less)
Topic | Forum


#2 Posted on: 4/19 21:53 Re: XoopsTube 1.06 RC 1 for XOOPS 2.5.6
Quote:
alain01 wrote:
Yet in the last package !

Please, download the last package (1.06 beta1) here.

Alain01, I thought the last package was a release candidate??

Top

Cifug
Not too shy to talk
Not too shy to talk
Joined:
2007/12/13 8:43
From Brisbane Australia
Group:
Registered Users
Posts: 121
(Show More) (Show Less)
Topic | Forum


#3 Posted on: 4/19 14:54 Re: Inserting multiple rows in database table
Quote:
I'm not getting any syntax error, so I'll have to use other tools to check

Very often syntax is not the issue, but the logic in our thinking....

Just set breaks in your debugger, and compare the values there with what you expect. I am sure that very quickly you'll find a bug in your logic

Top


Please support XOOPS & DONATE
Use 2.5.6 | Debugging | Requests | Bugs
Mamba
Moderator
Moderator
Joined:
2004/4/23 13:58
From Ohio, USA
Group:
Webmaster
Registered Users
Designer Group
Posts: 7836
(Show More) (Show Less)
Topic | Forum


#4 Posted on: 4/19 13:55 Re: Inserting multiple rows in database table
Thank you for your suggestion zyspec, but does not work the same

As I said before probable lack of passing data to the browser

I'm not getting any syntax error, so I'll have to use other tools to check

@zyspec

If you want to take a look at the module code is in SVN

WARNING: This module is pre-alpha and not for test

Top

timgno
Module Developer
Module Developer
Joined:
2007/6/21 13:54
From Italy
Group:
Registered Users
Posts: 1189
(Show More) (Show Less)
Topic | Forum


#5 Posted on: 4/19 12:38 Re: Inserting multiple rows in database table
Looks to me like your foreach loop is incorrect.

foreach ($datas as $data => $value) {                 
                
$obj->setVars(array($data$value)); 
                
$fieldsHandler->insert($obj);                         
            }


Should be:
foreach ($datas as $data => $value) {
                
$obj->setVars($value); 
                
$fieldsHandler->insert($obj);                         
            }


It would also help to see your db table definitions and/or the class used to create the $obj object. For instance, do you have a db column that is 'unique' to use as a key? Seems to me like you should really create an object ($obj) in the last foreach loop and then destroy it after you insert it - just to make sure you don't inadvertently insert 'remnants' from the previous object's contents - just a thought.


Top

zyspec
Module Developer
Module Developer
Joined:
2004/9/21 8:28
From USA
Group:
Registered Users
Posts: 870
(Show More) (Show Less)
Topic | Forum


#6 Posted on: 4/19 11:05 Re: Inserting multiple rows in database table
Do not change anything!
I'm afraid that's something else

For example, the data are not loaded by the browser

From these pictures you can see what I get

Resized Image

Resized Image

Top

timgno
Module Developer
Module Developer
Joined:
2007/6/21 13:54
From Italy
Group:
Registered Users
Posts: 1189
(Show More) (Show Less)
Topic | Forum


#7 Posted on: 4/19 10:39 Re: Inserting multiple rows in database table
Did you try to debug it?

I am not sure I understand the code. You declare the datas as an array, but you don't populate it as an array, and then you try to use it as an array when you populate the DB

Shouldn't it be something like:

$datas[$i] = array('field_mid' => $table_mid[$i],


Top


Please support XOOPS & DONATE
Use 2.5.6 | Debugging | Requests | Bugs
Mamba
Moderator
Moderator
Joined:
2004/4/23 13:58
From Ohio, USA
Group:
Webmaster
Registered Users
Designer Group
Posts: 7836
(Show More) (Show Less)
Topic | Forum


#8 Posted on: 4/19 9:55 Re: Inserting multiple rows in database table
I'm not getting any error ...!

They just do not write the data in the database,

even if I get the message script

"Succerfully saved"

Top

timgno
Module Developer
Module Developer
Joined:
2007/6/21 13:54
From Italy
Group:
Registered Users
Posts: 1189
(Show More) (Show Less)
Topic | Forum


#9 Posted on: 4/19 7:41 Re: Inserting multiple rows in database table
Quote:
Unfortunately it does not work

What doesn't work? What errors are you getting?

Top


Please support XOOPS & DONATE
Use 2.5.6 | Debugging | Requests | Bugs
Mamba
Moderator
Moderator
Joined:
2004/4/23 13:58
From Ohio, USA
Group:
Webmaster
Registered Users
Designer Group
Posts: 7836
(Show More) (Show Less)
Topic | Forum


#10 Posted on: 4/19 5:09 Re: Inserting multiple rows in database table
Unfortunately it does not work

Have a look at this code

if ($table_nbfields 0) {
            
$datas = array();     
            for( 
$i 0$i $table_nbfields$i++ ) {                    
                
$datas = array('field_mid' => $table_mid[$i], 
                                
'field_tid' => $table_id[$i],                                
                                
'field_numb' => $table_nbfields[$i], 
                                
'field_name' => $_POST['field_name'][$i], 
                                
'field_type' => $_POST['field_type'][$i], 
                                
'field_value' => $_POST['field_value'][$i], 
                                
'field_attribute' => $_POST['field_attribute'][$i], 
                                
'field_null' => $_POST['field_null'][$i], 
                                
'field_default' => $_POST['field_default'][$i], 
                                
'field_key' => $_POST['field_key'][$i],    
                                
'field_autoincrement' => (($_REQUEST['field_autoincrement'][$i] == 1) ? '1' '0'),
                                
'field_element' => $_POST['field_element'][$i],                            
                                
'field_inlist' => (($_REQUEST['field_inlist'][$i] == 1) ? '1' '0'),
                                
'field_inform' => (($_REQUEST['field_inform'][$i] == 1) ? '1' '0'),
                                
'field_admin' => (($_REQUEST['field_admin'][$i] == 1) ? '1' '0'),
                                
'field_user' => (($_REQUEST['field_user'][$i] == 1) ? '1' '0'), 
                                
'field_block' => (($_REQUEST['field_block'][$i] == 1) ? '1' '0'), 
                                
'field_main' => (($i == $_REQUEST['field_main']) ? '1' '0'), 
                                
'field_search' =>  (($_REQUEST['field_search'][$i] == 1) ? '1' '0'), 
                                
'field_required' => (($_REQUEST['field_required'][$i] == 1) ? '1' '0')
                                );
                                                    
            }    
            foreach (
$datas as $data => $value) {                
                
$obj->setVars(array($data$value));
                
$fieldsHandler->insert($obj);                        
            }
        }


Top

timgno
Module Developer
Module Developer
Joined:
2007/6/21 13:54
From Italy
Group:
Registered Users
Posts: 1189
(Show More) (Show Less)
Topic | Forum



Top
(1) 2 3 4 ... 29664 »



[Advanced Search]