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

[eluser]BoyBlue[/eluser]
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?



thanks,
Ryan
#2

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

[eluser]Unknown[/eluser]
Thanks for posting this. i really enjoyed reading this.

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

[eluser]BoyBlue[/eluser]
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) {

$movie_year=substr($row->release_date,0,4);

echo $movie_year; } ?>

For the Upper Case:
Code:
<? foreach ($movie_query->result() as $row) {
  
  $upper_rating=strtoupper($row->rated);
  
  echo $upper_rating; } ?>
#5

[eluser]boltsabre[/eluser]
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:

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

[eluser]BoyBlue[/eluser]
Great suggestion boltsabre--I will do it!!




Theme © iAndrew 2016 - Forum software by © MyBB