Jump to content

[SOLVED] echo an amount of something


Tylor Eddy

Recommended Posts

  • Moderators

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 ;
}

?>

Link to comment
Share on other sites

  • Moderators

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. smile.gif

Link to comment
Share on other sites

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. smile.gif

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

Link to comment
Share on other sites

  • Moderators

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

Link to comment
Share on other sites

  • Moderators

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.

Link to comment
Share on other sites

<?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

Link to comment
Share on other sites

  • Moderators

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.

Link to comment
Share on other sites

  • Moderators

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. wink.gif

Link to comment
Share on other sites

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. wink.gif

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

Link to comment
Share on other sites

  • Moderators

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?

  • Like 1
Link to comment
Share on other sites

  • Moderators

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 wink.gif

  • Like 2
Link to comment
Share on other sites

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 wink.gif

Works great now, ill give you rep for all your hard work

Thankyou very much :)

Tylor

Link to comment
Share on other sites

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.

Loading...
×
×
  • Create New...