Jump to content

Recommended Posts

Can anybody clarify the usefulness of "AS" and elaborate on how it operates.

 

If I select a 'bananas' AS 'yeelow fruit' will it change the TITLE in the table?  Or the table that is being viewed?

If I dump a list of 'FRUITS' into and HTML table, will using AS rename each column for me, or is that handled by MY coing of the HTML table?

Link to comment
https://forums.phpfreaks.com/topic/262880-select-field-name-as-question/
Share on other sites

If you SELECT a field from a table and use any MySQL functions while doing so, using an alias makes it easier to reference the field in an associative array when outputting the results.

 

if you were to do this:

$query = "SELECT DATE_FORMAT(date_field, '%M-%D-%Y') FROM table";
$result = mysql_query($query);

 

You would need to access that field in an associative array like this:

$array = mysql_fetch_assoc($result);
echo $array['DATE_FORMAT(date_field, '%M-%D-%Y')'];

 

With an alias, it becomes more straightforward:

$query = "SELECT DATE_FORMAT(date_field, '%M-%D-%Y') AS mydate FROM table";
$result = mysql_query($query);
$array = mysql_fetch_assoc($result);
echo $array['mydate'];

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.