#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2000
    Posts
    3
    Rep 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?
  2. #2
  3. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    18
    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.

  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2000
    Posts
    3
    Rep 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!";
    }
  6. #4
  7. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    18
    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.
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2000
    Posts
    3
    Rep 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!

Similar Threads

  1. php/mysql Developer needed for online game
    By Lord Melo in forum Project Help Wanted
    Replies: 1
    Last Post: October 29th, 2003, 09:15 PM
  2. PHP/MySQL Application Design/Architecture Books
    By glambert in forum PHP Development
    Replies: 7
    Last Post: April 10th, 2003, 09:52 PM
  3. PHP/MySQL Issues... Please help.
    By misteraven in forum PHP Development
    Replies: 14
    Last Post: August 7th, 2002, 08:03 PM
  4. PHP/MySQL Backend
    By Cujo in forum PHP Development
    Replies: 4
    Last Post: May 15th, 2002, 08:00 PM
  5. Need Qualified PHP/MySQL Programmer
    By ITGL72 in forum PHP Development
    Replies: 0
    Last Post: February 18th, 2002, 11:47 AM

IMN logo majestic logo threadwatch logo seochat tools logo