Jump to content

[SOLVED] Help reading through all fields and records in a database


turkman

Recommended Posts

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?

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);
      }
  
}






?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.