Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

253
Views
Expiry date IF santance is not working with MYSQL UPDATE

I have table with many rows. I have exp date and I want to change status of those rows where date is already exp.

It work well if I do not use UPDATE. If I just echo them. But when I want to UPDATE status of this row to 0, problems start. My problem is that it change only 1 row and not all of them that needs to be whit status 0.

$sql = "SELECT * FROM table";
$result = mysqli_query($conn, $sql);
$resultcheck = mysqli_num_rows($result);
$id = $row['id'];

if($resultcheck > 0) {
while($row = mysqli_fetch_assoc($result)) {

$expdate = $row['date'];
$exp = strtotime($date);

$today = date('m/d/Y');
$td = strtotime($today);

if($td>$exp) {
$status=0;

$sql = " UPDATE table SET status = '$status' WHERE ID = '$id' ";
$result = mysqli_query($conn, $sql);
}
}
}

Any advice how to fix that, I tried several option but nothing worked.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

  1. Use row['id'] instead of $id.

$sql = " UPDATE table SET status = '$status' WHERE ID = 'row['id']' ";

  1. Rename $result for update. You are reusing the same variable name, hence, after a success update, it will set $result to true and the while loop will stop.
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!