I am trying to take one query, and apply multiple select statements to it. The example I have is…
$news_query="SELECT *, DATE_FORMAT(`date`,'%d-%b-%Y') AS showdate, SUBSTRING_INDEX(body,' ',8) as body FROM NewsContent ORDER BY id DESC LIMIT 3";
This is taking a query, applying a date format change from 2012-09-15 to 15-Sep-2012, then limiting the amount of words in the text body, and then ordering the items in the table so that the last three appear.
The ordering works, but the date change and word limit doesn’t. Could anyone explain what I’m meant to do to allow these statements to apply? Could someone also help me figure out where ‘showdate’ should go? Does it replace my previous ‘$date’ string, or is it applied elsewhere?
Remember that * selects all columns from the table, so you have selected body from the table, and your shortened body as well. I’m not quite sure how MySQL will behave with that. If you give your new version of body a different name then there will be no problem. The new date and new body you have selected will not replace the previous ones, but appear as separate columns in the output (under the names showdate and whatever you change body to be called).