Welcome Guest, Not a member yet? Register   Sign In
Adjust MySQL data represented on the HTML Page...

I've been looking for this answer for a little while and I'm sort of stumped...

I'm grabbing data (date and rating of a movie) from a mysql table to display on an HTML page. The way it has been input into the database is... Date: "date type' in mysql (1995-06-30)
Rating: 'g', 'pg', 'pg13', or 'r'

I want the HTML page to display them as (date) '1995' and (rating) 'G' or 'PG' or 'PG13' or 'R'

What would be the easiest way to accomplish this without changing how the data is inserted into the table?


[eluser]TWP Marketing[/eluser]
Treat the date as a string array and read the first four characters as the year.
$someyear = $substr($date,0,3);
Use the strtoupper() function on your film rating value to force to upper case.

Thanks for posting this. i really enjoyed reading this.

[url="http://www.focusbis.com.au/"]Quality management system[/url]

Thanks so Much TWP Marketing!

Ok...so, here is the final code that works like a charm!

For the Year of Date only:
Quote:<? foreach ($movie_query->result() as $row) {


echo $movie_year; } ?>

For the Upper Case:
<? foreach ($movie_query->result() as $row) {
  echo $upper_rating; } ?>

You don't have to assign them to variables first, so to save on time and code, to increase page load speeds, reduce required server processing power, and reduce the risk of bugs, feel free to do it like this:

<? foreach ($movie_query->result() as $row) {
  echo substr($row->release_date,0,4);
  echo strtoupper($row->rated);
  } ?>

Great suggestion boltsabre--I will do it!!

Theme © iAndrew 2016 - Forum software by © MyBB