Forum Moderators: coopster

Message Too Old, No Replies

updating mysql table from php mysql query result

format text to date and update tbale with formatted date

         

randy1as

2:44 am on Oct 4, 2009 (gmt 0)

10+ Year Member



Converted excel xls to mysql table. The dates were entered as 121208 for 12 Dec 2008 and 21208 for 2nd Dec 2008.
Can format the date using substr function and strlen and show the result with while statement - but how do I update the filed - tried update SQL in the while statement didn't work. Help. I am factory fresh to MySql and PHP.
<?php
$link = mysql_connect('localhost', 'root', 'root');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db('test');
if (!$db_selected) {
die('Could not select database: ' . mysql_error());
}


$query = "SELECT * FROM pers ";
$result = mysql_query($query);

while($row = mysql_fetch_array($result)){

$DateMinusDash = $row [TOS];
/*$Pxno = &row[PersNo];*/
if (strlen($DateMinusDash) == 6)
$DateWithDash = (substr ($DateMinusDash,0,2).'-'.substr ($DateMinusDash,2,2).'-'.substr ($DateMinusDash,4,6));
$row [TOS] = $DateWithDash;

/*mysql_free_result($result);*/

/*$sql = "UPDATE pers SET TOS= $DateWithDash WHERE PersNo= $Pxno";*/

/*$result= mysql_query($sql);*/
echo $row["PersNo"]. $row["Name"] . " " .$row [TOS], "<br />\n";
/*mysql_free_result($result);*/
/*else
echo "false"*/
/*elseif (strlen($DateMinusDash) == 5)*/
/*echo $row["Name"] . " " .$row [TOS]."five", "<br />\n"; */
/*$strn= "abcdef";
/*$length = strlen(utf8_decode($strn));*/
/*if $length == 6;*/
/*$len = strlen($strn);
if ($len = 6)
echo $len;*/
}
?>

mack

3:48 pm on Oct 7, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Are you receiving an error message when you run the code?

Mack.

TheMadScientist

5:11 pm on Oct 7, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Actually Mack, this was a double post answered here:
[webmasterworld.com...]