Trying to locate source to convert asp to php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tazdog
Forum Newbie
Posts: 10
Joined: Tue Aug 10, 2004 4:50 pm
Location: Grand Prarie, TX
Contact:

Trying to locate source to convert asp to php

Post 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
lostboy
Forum Contributor
Posts: 329
Joined: Mon Dec 30, 2002 8:12 pm
Location: toronto,canada

Post 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;
tazdog
Forum Newbie
Posts: 10
Joined: Tue Aug 10, 2004 4:50 pm
Location: Grand Prarie, TX
Contact:

Post by tazdog »

I will give that a shot.. I appreciate the help...
Scott
tazdog
Forum Newbie
Posts: 10
Joined: Tue Aug 10, 2004 4:50 pm
Location: Grand Prarie, TX
Contact:

well maybe not..

Post 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>&nbsp;Your Information has been entered.";
Any help would be great..
thanks Scott
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

line 20, syntax error.
tazdog
Forum Newbie
Posts: 10
Joined: Tue Aug 10, 2004 4:50 pm
Location: Grand Prarie, TX
Contact:

Post 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
lostboy
Forum Contributor
Posts: 329
Joined: Mon Dec 30, 2002 8:12 pm
Location: toronto,canada

Post 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>&nbsp;Your Information has been entered.";

//end if
Last edited by lostboy on Thu Sep 23, 2004 2:18 pm, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I'm not sure what you are trying to do with that line.. maybe removing the 'if' component..
tazdog
Forum Newbie
Posts: 10
Joined: Tue Aug 10, 2004 4:50 pm
Location: Grand Prarie, TX
Contact:

Post 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>&nbsp;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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

uh.. line 1 of lostboy's post will never be true.
User avatar
dull1554
Forum Regular
Posts: 680
Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W

Post 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.....
Post Reply