Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. PHP + MySQL Timeout Error

PHP + MySQL Timeout Error

Scheduled Pinned Locked Moved Web Development
databasephpmysqlcomtools
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • 4 Offline
    4 Offline
    47_MasoN_47
    wrote on last edited by
    #1

    I'm working on a script for my employer's website that will take form data and enter it into a MySQL database. Easy enough...until they wanted it to never have any gaps in the "id" field. They want the "id" field to be automatically generated and for it to never have any gaps in it if we decide to delete someone out of the database for whatever reason. To do this I wrote the following code (this isn't in it's entirety, just the pieces that are pertinent.) $id = 0; $query = mysql_query("SELECT * FROM ORDER BY id") or die(mysql_error()); $row = mysql_fetch_array($query) or die(mysql_error()); // This while loop checks the 'id' field and finds if there are any gaps, automatically // setting the $id variable to the smallest unused value while( $row['id'] = ($id + 1)){ $id += 1; } $id +=1; It looks to me that it should say "while the id field (1) = $id + 1 (1) then add 1 to $id and repeat until the id field doesn't = $id + 1 anymore." For some reason though, when I run the script from the website it just sits there until I get this error back from Firefox. Fatal error: Maximum execution time of 30 seconds exceeded in /var/www/www.website.com/htdocs/script.php on line 33 If I take the while statement out of the code and just have it echo back the values of $row['id'] and $id + 1 it brings back 1 and 1. But if I add the while loop in there it errors out again. I've tried while, do while, and if statements all to no avail. My apologies for the lengthiness, but I wasn't sure how to make this more concise.

    A 1 Reply Last reply
    0
    • 4 47_MasoN_47

      I'm working on a script for my employer's website that will take form data and enter it into a MySQL database. Easy enough...until they wanted it to never have any gaps in the "id" field. They want the "id" field to be automatically generated and for it to never have any gaps in it if we decide to delete someone out of the database for whatever reason. To do this I wrote the following code (this isn't in it's entirety, just the pieces that are pertinent.) $id = 0; $query = mysql_query("SELECT * FROM ORDER BY id") or die(mysql_error()); $row = mysql_fetch_array($query) or die(mysql_error()); // This while loop checks the 'id' field and finds if there are any gaps, automatically // setting the $id variable to the smallest unused value while( $row['id'] = ($id + 1)){ $id += 1; } $id +=1; It looks to me that it should say "while the id field (1) = $id + 1 (1) then add 1 to $id and repeat until the id field doesn't = $id + 1 anymore." For some reason though, when I run the script from the website it just sits there until I get this error back from Firefox. Fatal error: Maximum execution time of 30 seconds exceeded in /var/www/www.website.com/htdocs/script.php on line 33 If I take the while statement out of the code and just have it echo back the values of $row['id'] and $id + 1 it brings back 1 and 1. But if I add the while loop in there it errors out again. I've tried while, do while, and if statements all to no avail. My apologies for the lengthiness, but I wasn't sure how to make this more concise.

      A Offline
      A Offline
      Ashish Sehajpal
      wrote on last edited by
      #2

      while( $row['id'] = ($id + 1)){ don't you think that you are using ASSIGNMENT operator instead of EQUALITY COMPARISON operator i.e. = instead of ==

      Ashish Sehajpal

      4 1 Reply Last reply
      0
      • A Ashish Sehajpal

        while( $row['id'] = ($id + 1)){ don't you think that you are using ASSIGNMENT operator instead of EQUALITY COMPARISON operator i.e. = instead of ==

        Ashish Sehajpal

        4 Offline
        4 Offline
        47_MasoN_47
        wrote on last edited by
        #3

        Ah...wow I feel dumb. Yeah that was the problem...the script works beautifully now. I guess I skipped that chapter when I was teaching myself PHP. Thanks!

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups