problem in INSERTing a array data in a column

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
anaspk
Forum Newbie
Posts: 7
Joined: Wed Mar 25, 2009 1:38 am

problem in INSERTing a array data in a column

Post by anaspk »

array $sub2 cant insert the values in a colum 'ord' of table order in the same database
<?php
include('datacon.php');
$sq1 = "SELECT regno FROM patientreg";
$result=mysql_query($sq1);
$num=mysql_num_rows($result);

for ($i=1; $i<=$num; $i++)
{
$row=mysql_fetch_array($result);
$val=$row['regno'];
$regno = $val;
$sub= substr($val,2);
$len=strlen($sub)-3;
$sub2= substr($sub,0,$len);
$sql2="INSERT INTO order(ord) VALUES('$sub2')";
echo $sub2."<br>";

//$sql2="UPDATE patientreg SET order = '$sub2' WHERE regno = '$regno'";
$query=mysql_query($sql2);
}
?>
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: problem in INSERTing a array data in a column

Post by papa »

Won't work:
$row=mysql_fetch_array($result);
$val=$row['regno'];

Use:
http://us.php.net/manual/en/function.my ... -assoc.php
Post Reply