PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Hi. Im using mysql and I have a 'date' column in my 'Logs' table that is a timestamp. I tried to write this code to display the month as a string of characters rather than two numbers. Like usual i cant get it to work. Any help would be greatly appreciated.
<?php
session_start();
include('connectDB.php');
//in the query below, 'date' is a mysql timestamp it goes 'yyy-mm-dd hh:mm:ss'
$query3 = 'SELECT MAX(date) FROM Logs WHERE id IN (SELECT id FROM Users WHERE id ='.$_SESSION['id'].')';
$result = mysql_query($query3);
$row = mysql_fetch_array($result);
$when = explode(' ',$row);
//this is where things go wrong. It does not give me what i want?? I threw in the echo just to see whats going on
echo $when[0];
echo $when[1];
///////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////
$date = $when[0];
$date2 = explode('-',$date);
$year = $date[0];
$month = $date[1];
$day = $date[2];
$months[0] = 'January';
$months[1] ='Febuary';
$months[2] = 'March';
$months[3] = 'April';
$months[4] = 'May';
$months[5] = 'June';
$months[6] = 'July';
$months[7] ='August';
$months[8] ='September';
$months[9] = 'October';
$months[10] ='November';
$months[11] ='December';
//supposed to display the name of the month
echo $months[$month];
?>
<?php
session_start();
include('connectDB.php');
//in the query below, 'date' is a mysql timestamp it goes 'yyy-mm-dd hh:mm:ss'
$query3 = 'SELECT MAX(date) as maxDate FROM Logs WHERE id IN (SELECT id FROM Users WHERE id ='.$_SESSION['id'].')';
$result = mysql_query($query3);
$row = mysql_fetch_array($result);
$when = $row['maxDate'];
?>
Ya, I think the problem has something to do with using the explode() function on the timestamp field. I know the $when array isnt holding what it is supposed to. Can someone please confirm that the variables being returned from the mysql_fetch_array() function are strings.
ThuggLife wrote:Ya, I think the problem has something to do with using the explode() function on the timestamp field. I know the $when array isnt holding what it is supposed to. Can someone please confirm that the variables being returned from the mysql_fetch_array() function are strings.
No, the mysql_fetch_array() return value is array type. That's what Mark Baker meant with his post.
There are 10 types of people in this world, those who understand binary and those who don't
ThuggLife wrote:Ya, I know that the mysql_fetch_array() returns an array. I was asking if the values stored in the array would be strings.
That values stored in that array will be the appropriate datatype based on the database column datatypes: Varchars will return strings, numbers will return float or integer as appropriate, dates will return integer, etc