Forum Moderators: coopster

Message Too Old, No Replies

HELP! new to php mysql. Need help with parsing error for datge.

new to php mysql.

         

vram1980

4:40 am on May 25, 2007 (gmt 0)

10+ Year Member



I am setting up a blog for my on personal portfolio and all I need is to format the date! I am ready to curl up and die... i get this parse error when attempting to format the date:

Warning: mysql_result(): Thursday May 24th 2007 not found in MySQL result index 9 in /home/content/v/r/a/vram1980/html/inc/sel_blog.php on line 13

Here is the code:

$query = "SELECT * FROM blog";
$result = mysql_query($query);
$num = mysql_num_rows ($result);

if ($num > 0 ) {
$i=0;
while ($i < $num) {
$formatted = date('l F dS Y');
$date = mysql_result($result, $i, $formatted);
$title = mysql_result($result,$i,"title");
$entry = mysql_result($result,$i,"entry");
$id = mysql_result($result,$i,"id");

echo "<h4> $title</h4> $date<br>";
echo "<b>entry:</b> $entry<br>";

++$i; } } else { echo "The database is empty"; }

SOMEONE PLEASE HELP ME!

the date field is set as DATETIME and the inserts are CURTIME()

phparion

5:15 am on May 25, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Alternatively, you can format the date within your mysql query that will be better for quick performance rather than doing it in php.

you can do it with mysql built in fucntion date_format() [dev.mysql.com]

e.g

SELECT date_format(date_column_name,'desired format') as formatted_date FROM tablename

[edited by: dreamcatcher at 7:03 am (utc) on May 25, 2007]
[edit reason] Made link live [/edit]

vram1980

5:21 am on May 25, 2007 (gmt 0)

10+ Year Member



hmmm

how would i implement that into my code sample?

phparion

11:39 am on May 25, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



$date = $row['formatted_date'];

that's it!

@DC: I really don't know what tag should I use to make my link live? and is WebmasterWorld team thinking to include a bbcode bar on the text area to perform text formatting quickly like done on, for instance, devshed?

eelixduppy

1:30 pm on May 25, 2007 (gmt 0)



phparion, we have a list of style codes [webmasterworld.com] that the forum uses. Refer to that page if you want to format your text appropriately :)

phparion

7:08 pm on May 26, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Thanks Mod!