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
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(); 

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.