PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old April 30th, 2000, 10:32 AM
mojoman mojoman is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2000
Posts: 3 mojoman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I've read pretty much every post on four sites for six hours, and still have not found an answere to this. I have a query, and am trying to format the date to a "Friday June 6th, 2000" or whatever. The field is a date field. I run the query, but the line where the date would be just doesn't show up. Below is the script:

<?php

$db = mysql_connect("localhost", "******");
mysql_select_db("creed",$db);
$result = mysql_query("SELECT diaryweek, diarytitle,
diarybody, date_format(diarydate,'%M %D, %Y')
FROM tourdiary
where diaryweek like 'April 5 - 15' ORDER by diarydate DESC",$db);
printf("<center><font face=Arial,Helvetica size=3
color=yellow><b>Tour Diary: %s</font></b></center><br>n",
mysql_result($result,0,"diaryweek"));
if ($myrow = mysql_fetch_array($result)) {
echo "<table border=0 cellpadding=6 width=400 align=center>n";
do {

printf("<tr><td valign=top align=left>
<font face=Arial,Helvetica size=2
color=white><b>%s</b><p>%s<p></td></tr>n",
$myrow["diarydate"],
$myrow["diarybody"]);
} while ($myrow = mysql_fetch_array($result));
echo "</table>n";
} else {
echo "Sorry, no tour info";
}

?>

What am I doing wrong?

Reply With Quote
  #2  
Old April 30th, 2000, 11:25 AM
rod k rod k is offline
Apprentice Deity
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Jul 1999
Location: Niagara Falls (On the wrong side of the gorge)
Posts: 3,237 rod k User rank is Private First Class (20 - 50 Reputation Level)rod k User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 m 8 sec
Reputation Power: 17
Send a message via AIM to rod k
You need to alias the date_format result:

$result = mysql_query("SELECT diaryweek, diarytitle,
diarybody, date_format(diarydate,'%M %D, %Y') as diarydate
FROM tourdiary
where diaryweek like 'April 5 - 15' ORDER by diarydate DESC",$db);


That will work for you.


Reply With Quote
  #3  
Old April 30th, 2000, 12:36 PM
mojoman mojoman is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2000
Posts: 3 mojoman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
It gave me a:

: 0 is not a MySQL result index

Hmm. Does it have to do something with this part of the script using a printf statement?


if ($myrow = mysql_fetch_array($result)) {
echo "<table border=0 cellpadding=6 width=400 align=center>n";
do {

printf("<tr><Atd valign=top align=left><font face=Arial,Helvetica size=2
color=white><b>%s</b><p>%s<p></td></tr>n",
$myrow["diarydate"],
$myrow["diarybody"]);
} while ($myrow = mysql_fetch_array($result));
echo "</table>n";
} else {
echo "Sorry!";
}

Reply With Quote
  #4  
Old April 30th, 2000, 03:59 PM
rod k rod k is offline
Apprentice Deity
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Jul 1999
Location: Niagara Falls (On the wrong side of the gorge)
Posts: 3,237 rod k User rank is Private First Class (20 - 50 Reputation Level)rod k User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 m 8 sec
Reputation Power: 17
Send a message via AIM to rod k
It might have something to do with the alias being the same as the field name. Try changing the alias and the corresponding $myrow["diarydate"] to something else. If that doesn't work, put:
print mysql_error();
after the query.

It doesn't have anything to do with your printf statement. It means mysql returned an error.

Reply With Quote
  #5  
Old April 30th, 2000, 07:46 PM
mojoman mojoman is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2000
Posts: 3 mojoman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
It's working. My fault. No sleep for two days you start to lose focus.

There was no space between my alias and the "FROM tourdiary", so it basically said,

"date_format(diarydate,'%M %D, %Y') as dateFROM tourdiary"

and returned the error, database not found.

Thanks, saved my butt!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > Need help with date_format using PHP/MySQL.

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap