Sorry to have to ask for help. I’ve been working on this issue for a few days and I just can’t seem to find the error or my ways. (Could have something to do with the percocets the Oral Surgeon gave me. [Grin]) I’m trying to get a loop to read each line, check for the value and if the value is ‘X’ I want it to write a Y instead. However even after all the tweaking I’ve done it writes the Y to every field. I can’t see where I’m going wrong. And yes, I’ve been doing the testing on a copy of the real data.
// sets connect to server string
$conn = mysqli_connect('localhost', 'XXXXXXX', '*********', 'billboard');
// check connection
if (mysqli_connect_errno($conn)) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result=mysqli_query($conn, "SELECT * from data4 order by id");
$num_rows = mysqli_num_rows($result);
while($record = mysqli_fetch_array($result)) {
if(!empty($record)) {
// echo $record['id'] . " " . $record['onchart'] . " " . $record['have'] . " " . $record['raporhm'];
$onch=($record['onchart']);
$id=($record['id']);
if ($onch='X') {
$onch='Y';
} else {
$onch="";
}
$UpdateQuery = "UPDATE data4 SET onchart = '$onch' where id = '$id' ";
mysqli_query($conn, $UpdateQuery);
}
}
echo "Done";
?>