Page 1 of 1
Trying to locate source to convert asp to php
Posted: Thu Sep 23, 2004 8:32 am
by tazdog
I have some asp code that I want to try and do the same thing with php, and I quite cannot figure it out.
What I really want to do is have an ID say XYZ1000
But everytime someone signs up I would like it to take the next number in the sequence. (ie XYZ1001)
Is there anywhere on the net or a book that could somehow explain this?
Below is the ASP code currently used. But I'm unable to convert it into php.
Here is the asp code:
Code: Select all
PilotID = 1000
strSQL = "SELECT * FROM Pilots"
RS.Open strSQL,CONN,1,1
Do Until RS.EOF
If RS.Fields("Name") = "Available" Then
PilotID = Mid(RS.Fields("PilotID"),4)
WTD = 1
Else
PilotID = PilotID + 1
WTD = 0
End If
RS.MoveNext
Loop
RS.Close
PilotID = "ZAV" & PilotID
thanks
Scott
Posted: Thu Sep 23, 2004 9:25 am
by lostboy
Code: Select all
$PilotID = 1000;
$strSQL = "SELECT * FROM Pilots" ;
$result = mysql_query($strSQL) or die ("CAn't complete query because ".mysql_error*());
if ($result){
while($rows = mysql_fetch_array($result)){
If ($rows["Name"] == "Available"){
$PilotID = substr($rows["PilotID"],4);
$WTD = 1;
}else{
$PilotID++;
$WTD = 0
}//end if
}//end while
}//end if
$PilotID = "ZAV" . $PilotID;
Posted: Thu Sep 23, 2004 10:21 am
by tazdog
I will give that a shot.. I appreciate the help...
Scott
well maybe not..
Posted: Thu Sep 23, 2004 12:02 pm
by tazdog
I think I'm missing something to tie the first code (listed above) with the rest. So I'm going to post the rest of the code to see where I have a hole.
Code: Select all
$dbcxn = mysql_connect("$host","$user","$pswd");
if (!$dbcxn) die ("Could not connect MySQL");
mysql_select_db($dbname,$dbcxn) or die ("Could not open database");
$PilotID = 1000;
$strSQL = "SELECT * FROM Pilots" ;
$result = mysql_query($strSQL) or die ("Can't complete query because ".mysql_error*());
if ($result){
while($rows = mysql_fetch_array($result)){
If ($rows["Name"] == "Available"){
$PilotID = substr($rows["PilotID"],4);
$WTD = 1;
}else{
$PilotID++;
$WTD = 0
}//end if
}//end while
}//end
if $PilotID = "ZAV" . $PilotID;
$sql = "INSERT INTO Pilots (Name, State, Country, Email, Passwd, BirthDate, Vatsim, BVIAccount, HubID) VALUES ('$fullname', '$state', '$country', '$email', '$passwd', '$birthdate', '$vatsim', '$bviaccount', '$hub')";
$result = mysql_query($sql);
echo "<b>Thank you!</b> Your Information has been entered.";
Any help would be great..
thanks Scott
Posted: Thu Sep 23, 2004 12:13 pm
by feyd
line 20, syntax error.
Posted: Thu Sep 23, 2004 2:10 pm
by tazdog
I understand that there is an error. Cause when you run the page you do not get anything displayed..
If someone can point on the net where I can read about this type of thing then I can learn about it and get it figured out..
thanks
Posted: Thu Sep 23, 2004 2:14 pm
by lostboy
Code: Select all
if ($PilotID == "ZAV" . $PilotID){
$sql = "INSERT INTO Pilots (Name, State, Country, Email, Passwd, BirthDate, Vatsim, BVIAccount, HubID) VALUES ('$fullname', '$state', '$country', '$email', '$passwd', '$birthdate', '$vatsim', '$bviaccount', '$hub')";
$result = mysql_query($sql);
echo "<b>Thank you!</b> Your Information has been entered.";
//end if
Posted: Thu Sep 23, 2004 2:16 pm
by feyd
I'm not sure what you are trying to do with that line.. maybe removing the 'if' component..
Posted: Thu Sep 23, 2004 2:28 pm
by tazdog
lostboy wrote:Code: Select all
if ($PilotID == "ZAV" . $PilotID){
$sql = "INSERT INTO Pilots (Name, State, Country, Email, Passwd, BirthDate, Vatsim, BVIAccount, HubID) VALUES ('$fullname', '$state', '$country', '$email', '$passwd', '$birthdate', '$vatsim', '$bviaccount', '$hub')";
$result = mysql_query($sql);
echo "<b>Thank you!</b> Your Information has been entered.";
//end if
I'm following along with what you are doing..!
But here is a question. Do I need to somehow put the PilotID table into the insert statement.? And do I also need to reference it like $PilotID into the Values area..?
*Feyd - What I'm trying to do is assign a specific ID for people when they sign up into the database..
But I would like it to get the next available ID thats not in the DB...
Does that make sense..?
thanks
Scott
Posted: Thu Sep 23, 2004 2:31 pm
by feyd
uh.. line 1 of lostboy's post will never be true.
Posted: Thu Sep 23, 2004 3:01 pm
by dull1554
yep its completely pointless, maybe its supposed to be setting a variable to be equal to "ZAV" concatinated onto the front of the pilotID
im a little confused by the whole thing.....