Jump to content

Code not working


dudejma

Recommended Posts

I'm trying to find the highest number and add one to it so that it creates a new pilot ID, but what happens with this code is it gets the same number every time. Anyone know why?

 

PS. Sorry for all the notes in the code. I like to do that to keep organized. I'm very new to PHP.

 

<?php

$hub = "1";

// Connects to database.
require "db_connect.php";

// Checks that database connects.
if (!$current_db) {
   die("An error has occured. Please contact the webmaster with error code: #A02.");
}

// Syntax to find last Pilot ID.
$sql = "SELECT MAX(pilotnum) FROM users WHERE hub=$hub";

// Runs above syntax.
$result = mysql_query($sql);

// Checks to see if syntax above finds an answer.
if (!$result) {
   die("An error has occured. Please contact the webmaster with error code: #A03.");       
}

// Gives results placeholder.
$pilotnum = mysql_result($result, pilotnum);

// Checks to see if a Pilot ID is found.
if (!pilotnum) {
   die("An error has occured. Please contact the webmaster with error code: #A04.");
}

// Adds one to the last Pilot ID.
++$pilotnum; 

echo $pilotnum;

?>

Link to comment
Share on other sites

It's not auto increment. I don't want it to be auto increment because there are six different hubs and each pilot is in a different hub. Each hub has it's own beginning number in their pilots' IDs. For example, a pilot in hub 1 would have a pilot ID in the one thousand range, a pilot in hub 2 would have a pilot ID in the two thousand range.

Link to comment
Share on other sites

So, you would need to go through all the data you have stored that is related to that pilot and update the id in it just because his hub changed?

 

That doesn't sound like an very efficient RDBMS design.

 

Wouldn't you rather just assign a fixed permanent id to each pilot and have a column in the pilot information table that holds the id of the hub he is based at?

 

^^^ Doing that would make ALL your code and queries simpler and faster and if the hub changed, all you would need to do is update one piece of data, the 'hub' column for that pilot.

Link to comment
Share on other sites

I thought of going that way but then I thought that it'd be nice to have it all organized this way where each hub has a different starter. But yea, that'd work better now that I think about it. Thanks! So what exactly would the code need to do to assign each new pilot a ID?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.