Alexhoward Posted May 26, 2008 Share Posted May 26, 2008 Hi guys, back again so soon, sorry. but i'm getting an error code from this piece for script that i don't understand: Undefined offset: 2 and : Undefined offset: 1 am i not doing this correctly...? <?php include("whatever.php"); mysql_connect($host, $db, $pass) or die ("Could not connect to mysql because ".mysql_error()); mysql_select_db($db) or die ("Could not select database because ".mysql_error()); $mysite_username = $HTTP_COOKIE_VARS["sitename"]; $year=mysql_query("SELECT dob FROM $table WHERE username = '$mysite_username'"); while($year1 = mysql_fetch_array($year)) $year1['dob']; list ($y, $sm, $d) = explode ('-', $year1); echo number_format($d); ?> Thanks for all your help, Quote Link to comment https://forums.phpfreaks.com/topic/107244-solved-explode-day-month-year-from-mysql-date/ Share on other sites More sharing options...
AndyB Posted May 26, 2008 Share Posted May 26, 2008 $year = mysql_query("SELECT dob FROM $table WHERE username = '$mysite_username'"); $year1 = mysql_fetch_array($year); $dob = $year1['dob']; // this line is revised list ($y, $sm, $d) = explode ('-', $dob); // slight change echo number_format($d); I assume it's a single result, so no while needed. Quote Link to comment https://forums.phpfreaks.com/topic/107244-solved-explode-day-month-year-from-mysql-date/#findComment-549867 Share on other sites More sharing options...
Alexhoward Posted May 26, 2008 Author Share Posted May 26, 2008 Hi Andy, Thanks for the reply I got it going like this, which i assume works, but now it's only single digits, e.g: 0 instead of 00 is there a way to make number_format double digits..? Thanks <?php $year=mysql_query("SELECT dob FROM $table WHERE username = '$mysite_username'"); while($year1 = mysql_fetch_array($year)) echo $year1['dob']; echo number_format(date($year1,"dd")); ?> Quote Link to comment https://forums.phpfreaks.com/topic/107244-solved-explode-day-month-year-from-mysql-date/#findComment-549869 Share on other sites More sharing options...
AndyB Posted May 26, 2008 Share Posted May 26, 2008 well, since day is a number anyway why not just skip the number format thing and echo $d Quote Link to comment https://forums.phpfreaks.com/topic/107244-solved-explode-day-month-year-from-mysql-date/#findComment-549872 Share on other sites More sharing options...
Alexhoward Posted May 26, 2008 Author Share Posted May 26, 2008 Hi Andy, because when i do that i get the errors as above... also, i have just been testing the code, and it appears that is does not work correctly...? Thanks for taking the time to look at this Quote Link to comment https://forums.phpfreaks.com/topic/107244-solved-explode-day-month-year-from-mysql-date/#findComment-549873 Share on other sites More sharing options...
Alexhoward Posted May 26, 2008 Author Share Posted May 26, 2008 it appears that it's not actually bringing anything back. yet if i do the same query in phpmyadmin, it works....? Quote Link to comment https://forums.phpfreaks.com/topic/107244-solved-explode-day-month-year-from-mysql-date/#findComment-549888 Share on other sites More sharing options...
Alexhoward Posted May 26, 2008 Author Share Posted May 26, 2008 Here's the answer. include("whatever.php"); mysql_connect($host, $db, $pass) or die ("Could not connect to mysql because ".mysql_error()); mysql_select_db($db) or die ("Could not select database because ".mysql_error()); $mysite_username = $HTTP_COOKIE_VARS["sitename"]; $year=mysql_query("SELECT dob FROM `profile` WHERE username = '$mysite_username'"); while($year1 = mysql_fetch_array($year)) $test = $year1['dob']; list($a, $v, $c) = explode('-',$test); echo $c yipee! i solved one Quote Link to comment https://forums.phpfreaks.com/topic/107244-solved-explode-day-month-year-from-mysql-date/#findComment-549897 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.