Re: how save elements of an array in database

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Sorry this is not good idea.
You have to use the extended insert logic.
example

INSERT INTO `ascdes` (`id`, `name`, `sno`, `yn`) VALUES
(1, 'prabhakar', 1225, '1'),
(2, 'ram', 1226, '0'),
(3, 'venkat', 1227, '1'),
(4, 'santhosh', 1228, '0'),
(5, 'arijit', 1229, '1'),
(6, 'satyam', 1230, '1'),
(7, 'swetha', 1231, '0'),
(8, 'sasi', 1232, '1'),
(9, 'dugraprasad', 1233, '0');

this you can frame the logic as

<?php
 $arr = array("one", "two", "three");
 $insertDbSql = "INSERT INFO `myTbl`(arr_val) VALUES ";
  $comma = "";
foreach ($arr as $value) {
      $insertDbSql .= $comma."('".$value."')";
 }
  mysql_query($insertDbSql);
 ?>

this is correct logic

--- In php-objects@xxxxxxxxxxxxxxx, Prasad C <prasadcnair@...> wrote:
>
> If that's single dimensional array, implode it to string and store in DB as
> VARCHAR or MEDIUMTEXT or TEXT.
> Use explode when you want it back to array..
> 
> On Thu, Nov 4, 2010 at 1:37 PM, Joseph Griffin <griffinhere@...>wrote:
> 
> >
> >
> > you may use simple "foreach" loop for that.
> >
> > <?php
> > $arr = array("one", "two", "three");
> >
> > foreach ($arr as $value) {
> > $insertDbSql = "INSERT INFO `myTbl` VALUES('$value')";
> > }
> > ?>
> >
> > ________________________________
> > From: melissa_brown35 <melissa_brown35@...<melissa_brown35%40yahoo.com>
> > >
> > To: php-objects@xxxxxxxxxxxxxxx <php-objects%40yahoogroups.com>
> > Sent: Tue, November 2, 2010 2:52:03 PM
> > Subject:  how save elements of an array in database
> >
> >
> > how save elements of an array in database when we do not know that how many
> >
> > elements are in array Like elements might be 5 or 10.
> >
> > [Non-text portions of this message have been removed]
> >
> >  
> >
> 
> 
> 
> -- 
> -Prasad C
> +91 994 672 5488
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> Please don't print this e-mail unless absolutely necessary, lets save some
> trees, and Mother Nature
> 
> 
> [Non-text portions of this message have been removed]
>



[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Soap]     [Kernel Newbies]     [Yosemite]     [Yosemite Campsites]

  Powered by Linux