yknip Posted May 4, 2012 Share Posted May 4, 2012 Hello everyone, need some help here.. Below are my codes.. ----------- $date = array("1001", "1002", "1003"); $sql="select ID from fid;"; $result = mysql_query($sql) or die("Query failed : " . mysql_error()); while($row = mysql_fetch_array($result, MYSQL_NUM)) { $test_id = $row[0]; foreach ($date as $datex){ $sql2="UPDATE tbl1 SET date1=(SELECT date1n FROM dat".$datex." WHERE ID=".$test_id.")"; mysql_query($sql2); ----------- I have tables 'dat1001','dat1002' and 'dat1003'. I want to get some values from that table and store them in another table ' tbl1'. It is updating but the values are zero. Thanks in advance... Link to comment https://forums.phpfreaks.com/topic/262054-php-and-mysql-help/ Share on other sites More sharing options...
darkfreaks Posted May 4, 2012 Share Posted May 4, 2012 $row[0] returns false that’s why Link to comment https://forums.phpfreaks.com/topic/262054-php-and-mysql-help/#findComment-1342928 Share on other sites More sharing options...
yknip Posted May 4, 2012 Author Share Posted May 4, 2012 hmm.. I echo $sql2 and I can see the ID's from fid table, so I guess it's not?.. also, when I try to change the variables from dat".$datex." to dat1001 and ".$test_id." to 123.. some are updating correctly.. Link to comment https://forums.phpfreaks.com/topic/262054-php-and-mysql-help/#findComment-1342932 Share on other sites More sharing options...
darkfreaks Posted May 4, 2012 Share Posted May 4, 2012 that is because you are replacing $test_id to an actual existing value $row[0] will return empty|false. Link to comment https://forums.phpfreaks.com/topic/262054-php-and-mysql-help/#findComment-1342934 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.