Tylor Eddy Posted January 22, 2012 Report Posted January 22, 2012 G'day guys, Im trying to call a certain amount of an aircraft for my new fleet page. I need some guidance in doing this as im not quite sure what the syntax is for echoing an amount of something. This is what im trying to do <?php if $aircraft->icao; == DH8 echo $amount ?> Any guidance would be great Tylor Quote
Moderators Parkho Posted January 23, 2012 Moderators Report Posted January 23, 2012 G'day guys, Im trying to call a certain amount of an aircraft for my new fleet page. I need some guidance in doing this as im not quite sure what the syntax is for echoing an amount of something. This is what im trying to do <?php if $aircraft->icao; == DH8 echo $amount ?> Any guidance would be great Tylor Try this <?php if($aircraft->name == DH8) { echo $amount ; } ?> Quote
Tylor Eddy Posted January 23, 2012 Author Report Posted January 23, 2012 Try this <?php if($aircraft->name == DH8) { echo $amount ; } ?> Thanks Parkho for the help, however i get a blank space where i am trying to display the number. I also tried replacing name with icao in your code, but that didn't seem to help either. Tylor Quote
Moderators Parkho Posted January 23, 2012 Moderators Report Posted January 23, 2012 Thanks Parkho for the help, however i get a blank space where i am trying to display the number. I also tried replacing name with icao in your code, but that didn't seem to help either. Tylor Your code was written wrong, so I just corrected it for you not knowing what you're trying to pull out. If you can post the entire codes for that fleet page of yours, then we can see where the problem is and fix it for you. Quote
Tylor Eddy Posted January 23, 2012 Author Report Posted January 23, 2012 Your code was written wrong, so I just corrected it for you not knowing what you're trying to pull out. If you can post the entire codes for that fleet page of yours, then we can see where the problem is and fix it for you. Ahh ok, i thought using $amount was the correct way of calling the number of that type of plane in my fleet, i take it there is more to it than what i put in my first post ? That's all the code i had, as i thought it was all i needed Thats all i have to show you, the rest of the page is irrelevant Tylor Quote
Moderators joeri Posted January 23, 2012 Moderators Report Posted January 23, 2012 do a print-r then you will get all the things you can pull from the database 1 Quote
Moderators Parkho Posted January 23, 2012 Moderators Report Posted January 23, 2012 Ahh ok, i thought using $amount was the correct way of calling the number of that type of plane in my fleet, i take it there is more to it than what i put in my first post ? That's all the code i had, as i thought it was all i needed Thats all i have to show you, the rest of the page is irrelevant Tylor Are you using any add-on for the fleet page? if yes, then we can write a little piece to pull out the number of fleet. here is an add-on that I'm using: http://forum.phpvms.net/topic/1522-fleet-table Quote
Tylor Eddy Posted January 23, 2012 Author Report Posted January 23, 2012 Thanks Joeri took a bit of research to work out what you meant, but that will definately come in handy Parkho i am using that fleet list, it is heavily modified, but that is the backbone of it. Tylor Quote
Moderators joeri Posted January 23, 2012 Moderators Report Posted January 23, 2012 lol sorry was connecting via my phone so long typing was out off the question Quote
Tylor Eddy Posted January 23, 2012 Author Report Posted January 23, 2012 lol sorry was connecting via my phone so long typing was out off the question No worries Quote
Moderators Parkho Posted January 23, 2012 Moderators Report Posted January 23, 2012 No worries Okay. Now we're talking, so you want to show how many aircraft of a certain type you got in your fleet? or please explain what exactly do you want to show in fleet page? Quote
Tylor Eddy Posted January 23, 2012 Author Report Posted January 23, 2012 Okay. Now we're talking, so you want to show how many aircraft of a certain type you got in your fleet? or please explain what exactly do you want to show in fleet page? That's what i'm trying to do I want to show an amount of a particular aircraft Tylor Quote
Moderators Parkho Posted January 23, 2012 Moderators Report Posted January 23, 2012 That's what i'm trying to do I want to show an amount of a particular aircraft Tylor <?php $amount = OperationsData::getAircraftByName(DH8); foreach($aircrafts as $aircraft) { if($aircraft->name == DH8) { echo $amount ; } } ?> Try this. But I haven't tested it. Quote
Tylor Eddy Posted January 23, 2012 Author Report Posted January 23, 2012 <?php $amount = OperationsData::getAircraftByName(DH8); foreach($aircrafts as $aircraft) { if($aircraft->name == DH8) { echo $amount ; } } ?> Try this. But I haven't tested it. G'day Parkho, Just gave it a shot, but i got this: Warning: Invalid argument supplied for foreach() in /home/qantasvi/public_html/lib/skins/brilliancev1/a.tpl on line 244 I tried changing it to foreach($fleet as $aircraft) but that just gave me a blank space again regards Tylor Quote
Moderators Parkho Posted January 23, 2012 Moderators Report Posted January 23, 2012 G'day Parkho, Just gave it a shot, but i got this: Warning: Invalid argument supplied for foreach() in /home/qantasvi/public_html/lib/skins/brilliancev1/a.tpl on line 244 I tried changing it to foreach($fleet as $aircraft) but that just gave me a blank space again regards Tylor change the $aircrafts to $allaircrafts, I think that might be it. Quote
Moderators Parkho Posted January 23, 2012 Moderators Report Posted January 23, 2012 Wait! <?php $amount = OperationsData::getAircraftByName(DH8); foreach($fleet as $aircraft) { if($aircraft->name == "DH8") { echo $amount ; } } ?> Try this Quote
Txmmy83 Posted January 23, 2012 Report Posted January 23, 2012 does not work for me best regards Thomas Quote
Moderators Parkho Posted January 23, 2012 Moderators Report Posted January 23, 2012 does that work? and where does it count up? best regards Thomas Don't know, didn't test it and waiting for Taylor. Quote
Tylor Eddy Posted January 23, 2012 Author Report Posted January 23, 2012 Don't know, didn't test it and waiting for Taylor. G'day Parkho, Just tested both of your suggestions, and it still won't give an amount, this is one persistant bit of code haha Tylor Quote
Moderators Parkho Posted January 23, 2012 Moderators Report Posted January 23, 2012 Okay here you go: <?php foreach ($fleet as $aircraft) { $amount = OperationsData::getAircraftByName($aircraft->name); echo count($amount) ; } ?> Now if you want to put that in the table then <?php foreach ($fleet as $aircraft) { $amount = OperationsData::getAircraftByName($aircraft->name); ?> <tr><td align="center"><?php echo count($amount) ;?></td></tr> <?php } ?> Tested and working. Quote
Tylor Eddy Posted January 23, 2012 Author Report Posted January 23, 2012 Okay here you go: <?php foreach ($fleet as $aircraft) { $amount = OperationsData::getAircraftByName($aircraft->name); echo count($amount) ; } ?> Now if you want to put that in the table then <?php foreach ($fleet as $aircraft) { $amount = OperationsData::getAircraftByName($aircraft->name); ?> <tr><td align="center"><?php echo count($amount) ;?></td></tr> <?php } ?> Tested and working. I must be missing something that this code needs because i get: 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Quote
Moderators Parkho Posted January 23, 2012 Moderators Report Posted January 23, 2012 I must be missing something that this code needs because i get: 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 how many a/c do you have? 1 Quote
Tylor Eddy Posted January 23, 2012 Author Report Posted January 23, 2012 how many a/c do you have? Not that many ! haha about 64 dash 8 aircraft Quote
Moderators Parkho Posted January 23, 2012 Moderators Report Posted January 23, 2012 Not that many ! haha about 64 dash 8 aircraft okay! wait i'm testing it 1 Quote
Tylor Eddy Posted January 23, 2012 Author Report Posted January 23, 2012 Not that many ! haha about 64 dash 8 aircraft I just realised what's different, what i am trying to get is an amount of a particular aircraft, not my whole fleet. Sorry, i only just realised when i looked at the code Quote
Moderators Parkho Posted January 24, 2012 Moderators Report Posted January 24, 2012 I just realised what's different, what i am trying to get is an amount of a particular aircraft, not my whole fleet. Sorry, i only just realised when i looked at the code Okay I got it! this goes to your .tpl anywhere in the table: <tr> <td align="center">DH8:</td> <td align="center"><?php echo OperationsData::getAircraftByName(DH8);?></td> </tr> Now change this in your OperationsData.class.php : public static function getAircraftByName($name) { $name = DB::escape(strtoupper($name)); $sql = 'SELECT * FROM ' . TABLE_PREFIX .'aircraft WHERE UPPER(`name`)=\''.$name.'\''; return DB::get_row($sql); } To this: public static function getAircraftByName($icao) { $query = "SELECT * FROM " . TABLE_PREFIX ."aircraft WHERE icao ='".$icao."'"; $results = DB::get_results($query); return DB::num_rows($results); } Remember to put aircraft icao (A322) instead of aircraft name (A320-200) in the .tpl 2 Quote
Tylor Eddy Posted January 24, 2012 Author Report Posted January 24, 2012 Okay I got it! this goes to your .tpl anywhere in the table: <tr> <td align="center">DH8:</td> <td align="center"><?php echo OperationsData::getAircraftByName(DH8);?></td> </tr> Now change this in your OperationsData.class.php : public static function getAircraftByName($name) { $name = DB::escape(strtoupper($name)); $sql = 'SELECT * FROM ' . TABLE_PREFIX .'aircraft WHERE UPPER(`name`)=\''.$name.'\''; return DB::get_row($sql); } To this: public static function getAircraftByName($icao) { $query = "SELECT * FROM " . TABLE_PREFIX ."aircraft WHERE icao ='".$icao."'"; $results = DB::get_results($query); return DB::num_rows($results); } Remember to put aircraft icao (A322) instead of aircraft name (A320-200) in the .tpl Works great now, ill give you rep for all your hard work Thankyou very much Tylor Quote
Moderators Parkho Posted January 24, 2012 Moderators Report Posted January 24, 2012 Works great now, ill give you rep for all your hard work Thankyou very much Tylor Actually! It wasn't that hard but I had to sleep since it was 2 in the morning. lol but thanks glad it worked for you. Quote
Tylor Eddy Posted January 24, 2012 Author Report Posted January 24, 2012 Actually! It wasn't that hard but I had to sleep since it was 2 in the morning. lol but thanks glad it worked for you. Haha, no worries Thanks again Quote
Moderators Parkho Posted January 24, 2012 Moderators Report Posted January 24, 2012 Haha, no worries Thanks again Anytime Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.