Jump to content

Displaying Derived results


Reno04

Recommended Posts

Hi

 

I'm new to using Mysql and php together and was wondering if someone could explain how i would display a derived column result. As in year - death_age. see below

 

$query  = "select name from prime_minister where  YEAR(CURRENT_DATE()) - birth_yr ";

$result = mysql_query($query);

 

 

if (mysql_affected_rows() >=1) {

echo '<h3>'.'The results of'.'<p>'.'<code>'. $query . '</code>' .'</p><p>are as follows:'.'</p>'.'</h3>';

} else {

  echo 'Check your SQL statement as there has been no data retrieved!';

  }

 

 

while($row = mysql_fetch_array($result, MYSQL_ASSOC))

{

 

 

 

echo "<br /> Name : {$row['name']} <br>".

echo "<br /> Current Age : {$row['??????']} <br>"; This part i dont understand what to write

 

}

 

 

  mysql_close(); //

Link to comment
https://forums.phpfreaks.com/topic/159421-displaying-derived-results/
Share on other sites

Sorry my mistake the query was typed wrong it

 

it should've been

 

Select name, Year(current_date())-birth_yr As age from prime_minister

 

the real problem i have is with php displaying the "as age" column as its derived and i don't know how to refer to it in my while loop see below

while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{



echo "<br /> Name : {$row['name']} <br>".
echo "<br /> Age : {$row['??????']} <br>";  // This part i dont understand what to write   

}


   mysql_close(); 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.