help me in substr
Posted: Sat Mar 28, 2009 2:25 pm
can some body help me. i want to subtract a interger value from a varchar value. i mean for example the varchar value is : A-10034/09
i want just 10034 (ignorig "A-" and "/09") for removing "A-" i uses "substr" command.but how can i remove "/09". using len in substr cant fulfill my problem as the lenth of A-*****/09 varies.
<?php
include('datacon.php');
$sq1 = "SELECT regno FROM patientreg";
$result=mysql_query($sq1);
$num=mysql_num_rows($result);
$sn=1;
for ($i=1; $i<=$num; $i++)
{
$row=mysql_fetch_array($result);
$val=$row['regno'];
$sub= substr($val,2);
//echo $sub."<br>";
$sql2="INSERT INTO patientreg(order) VALUES('$sub')";
$query=mysql_query($sql2);
}
?>
and also my subtracting value "$sub" is not inserting in another column of the same table..
or tell me how can i copy a whole column to another empty column of same table with the subtraction of first two and last tree character.
i want just 10034 (ignorig "A-" and "/09") for removing "A-" i uses "substr" command.but how can i remove "/09". using len in substr cant fulfill my problem as the lenth of A-*****/09 varies.
<?php
include('datacon.php');
$sq1 = "SELECT regno FROM patientreg";
$result=mysql_query($sq1);
$num=mysql_num_rows($result);
$sn=1;
for ($i=1; $i<=$num; $i++)
{
$row=mysql_fetch_array($result);
$val=$row['regno'];
$sub= substr($val,2);
//echo $sub."<br>";
$sql2="INSERT INTO patientreg(order) VALUES('$sub')";
$query=mysql_query($sql2);
}
?>
and also my subtracting value "$sub" is not inserting in another column of the same table..
or tell me how can i copy a whole column to another empty column of same table with the subtraction of first two and last tree character.
Code: Select all