Jump to content

[SOLVED] SQL Confusion...


Crew-Portal

Recommended Posts

Whats wrong with these few lines of code, And yes all varialbes are declared!

<?php
$query = "select count(*) from flights WHERE user_id = '$user_id_flights' AND air_id = '$air_id_flights' AND hours = '$h' AND minutes = '$m' AND flightplan = '$flightplan'";
$result = @mysql_query($sql,$connection) or include ('sql.php');
$existsalready = number_format(mysql_result($result,0));
if ($existsalready == '1'){
// Do This!!!
}
else {
// Do That!!
}
?>

Link to comment
Share on other sites

Maybe its not in that segment of code here is the rest of where it could be. (Please dont comment on how sloppy my code is. It runs and so im happy...

<?php
$arraynum1 = '0';
while (is_array($xml['FSHOST']['0']['FLIGHTPLANS']['0']['FLIGHTPLAN'][$arraynum1])){
if ($xml['FSHOST']['0']['FLIGHTPLANS']['0']['FLIGHTPLAN'][$arraynum1]['STATUSTEXT']['0']['VALUE'] == 'Closed'){
$query = "select count(*) from user WHERE username = '" . $xml['FSHOST']['0']['FLIGHTPLANS']['0']['FLIGHTPLAN'][$arraynum1]['PLAYERNAME']['0']['VALUE'] . "'";
$result = @mysql_query($sql,$connection) or include ('sql.php');
$flying = number_format(mysql_result($result,0));
if ($flying == 1){
$sql="SELECT air_id, user_id FROM user WHERE username = '" . $xml['FSHOST']['0']['FLIGHTPLANS']['0']['FLIGHTPLAN'][$arraynum1]['PLAYERNAME']['0']['VALUE'] . "'";
$result = @mysql_query($sql,$connection);
$num=mysql_num_rows($result);
while ($row = mysql_fetch_array($result)) {
$user_id_flights = $row['user_id'];
$air_id_flights = $row['air_id'];
}
$flightplan = $xml['FSHOST']['0']['FLIGHTPLANS']['0']['FLIGHTPLAN'][$arraynum1]['PLAN']['0']['VALUE'];
list($d,$h,$m) = explode(" ", $datefiled);
$d = rtrim($d, "d");
$h = rtrim($h, "h");
$m = rtrim($m, "m");
$query = "select count(*) from flights WHERE user_id = '$user_id_flights' AND air_id = '$air_id_flights' AND hours = '$h' AND minutes = '$m' AND flightplan = '$flightplan'";
$result = @mysql_query($sql,$connection) or include ('sql.php');
$existsalready = number_format(mysql_result($result,0));
if ($existsalready == '1'){
echo '';
}
else {
$sql="INSERT INTO flights (flight_type, user_id, air_id, hours, minutes, flightplan, flightdate)
VALUES (\"pirep\", \"$user_id_flights\", \"$air_id_flights\", \"$h\", \"$m\", \"$flightplan\", )";
$result = @mysql_query($sql,$connection) or include ('sql.php');
}
}
}
$arraynum1++;
}
?>

Link to comment
Share on other sites

Okay. Problem Again... Something Is Wrong With This Syntax

<?php
$sql="SELECT air_id, user_id FROM user WHERE username = '" . $xml['FSHOST']['0']['FLIGHTPLANS']['0']['FLIGHTPLAN'][$arraynum1]['PLAYERNAME']['0']['VALUE'] . "'";
$result = @mysql_query($sql,$connection);
$num=mysql_num_rows($result);
while ($row = mysql_fetch_array($result)) {
$user_id_flights = $row['user_id'];
$air_id_flights = $row['air_id'];
$flightplan = $xml['FSHOST']['0']['FLIGHTPLANS']['0']['FLIGHTPLAN'][$arraynum1]['PLAN']['0']['VALUE'];
$OPENTIMETEXT = $xml['FSHOST']['0']['FLIGHTPLANS']['0']['FLIGHTPLAN'][$arraynum1]['OPENTIMETEXT']['0']['VALUE'];
list($d,$h,$m) = explode(" ", $OPENTIMETEXT);
$d = rtrim($d, "d");
$h = rtrim($h, "h");
$m = rtrim($m, "m");
$query = "select count(*) from flights WHERE (user_id = $user_id_flights) AND (air_id = $air_id_flights) AND (hours = $h) AND (minutes = $m) AND (flightplan = $flightplan)";
$result = @mysql_query($sql,$connection) or include ('sql.php');
$existsalready = number_format(mysql_result($result,0));
if ($existsalready == 1){
echo '';
}
elseif ($existsalready == '0'){
$sql="INSERT INTO flights (flight_type, user_id, air_id, hours, minutes, flightplan, flightdate)
VALUES (\"pirep\", \"$user_id_flights\", \"$air_id_flights\", \"$h\", \"$m\", \"$flightplan\", \"$date\")";
$result = @mysql_query($sql,$connection) or include ('sql.php');
}
?>

And the segment that is not displaying the correct results is the:

<?php
$query = "select count(*) from flights WHERE (user_id = $user_id_flights) AND (air_id = $air_id_flights) AND (hours = $h) AND (minutes = $m) AND (flightplan = $flightplan)";
?>

It must be the way im using the AND statements because even if the record is there it goes to the record = 0 and if the records not there it still goes to the record = 0

Link to comment
Share on other sites

Okay that doesnt work either. I guess Im doing this completly wrong. I want it to check the colums:

flight_type, user_id, air_id, hours, minutes, flightplan

and see if there is a record:

\"pirep\", \"$user_id_flights\", \"$air_id_flights\", \"$h\", \"$m\", \"$flightplan\"

and if there is the script does nothing but if there isnt then it does:

"INSERT INTO flights (flight_type, user_id, air_id, hours, minutes, flightplan, flightdate)

VALUES (\"pirep\", \"$user_id_flights\", \"$air_id_flights\", \"$h\", \"$m\", \"$flightplan\", \"$date\")";

 

I guess i was coding this completly wrong. if anyone could help me with this I would just appreciate it completly!

Link to comment
Share on other sites

Okay figured it out! Im now using:

	$sql="SELECT * FROM flights WHERE user_id = '$user_id_flights' AND air_id = '$air_id_flights' AND hours = '$h' AND minutes = '$m' AND flightplan = '$flightplan'";
$result = @mysql_query($sql,$connection) or include ('sql.php');
$num=mysql_num_rows($result);
}
if($num >0) {
echo '';
}
else {
	$sql="INSERT INTO flights (flight_type, user_id, air_id, hours, minutes, flightplan, flightdate)
VALUES (\"pirep\", \"$user_id_flights\", \"$air_id_flights\", \"$h\", \"$m\", \"$flightplan\", \"$date\")";
$result = @mysql_query($sql,$connection) or include ('sql.php');
}

 

TOPIC SOLVED!!!!!!!!

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.