turkman Posted August 15, 2008 Share Posted August 15, 2008 Hey, I need to make a function that will open any database and search through every record and in every record it will search through every field (considering each table will have a different number of fields and different names) Then i need it to check the fields in each row and if it finds a Y for example to replace it with a 1 Then i need it to copy this new information into a new table. is this possible? Link to comment https://forums.phpfreaks.com/topic/119892-solved-help-reading-through-all-fields-and-records-in-a-database/ Share on other sites More sharing options...
turkman Posted August 15, 2008 Author Share Posted August 15, 2008 actually got it working with this <?PHP include 'conf.php'; include 'opendb.php'; $q = "SELECT * FROM WLTable"; $res = mysql_query($q) or die (mysql_error()); while($row = mysql_fetch_array($res,MYSQL_ASSOC)){ while(list($var, $val) = each($row)){ echo "Value Before Str_replace = $val <br>"; $nu = str_replace('Y','1',$val); echo "Value after Str_replace = $nu <br>"; $qe = "UPDATE WLTable SET $var = $nu WHERE id = " .$row['id']; echo "$qe <br>"; mysql_query($qe); } } ?> Link to comment https://forums.phpfreaks.com/topic/119892-solved-help-reading-through-all-fields-and-records-in-a-database/#findComment-617642 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.