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

    Join Date
    Jul 2000
    Location
    Boston MA USA
    Posts
    23
    Rep Power
    0
    ok... so everything is displaying correctly except the time (see www.likwid.org for what i mean)

    now it keeps on using the same date for *every* posting (even though they're different datetimes)
    now what the hell am i doing wrong?
    thnx


    <?php
    // connect to the db duh
    $db = mysql_connect("localhost", "user", "pass");
    mysql_select_db("db",$db);
    // select and arrange the data by the datetime row latest first etc
    $result = mysql_query("select * from body order by date desc");
    // insert the table parameters
    echo "<table border=0 cellpadding=0 cellspacing=10 width=475 height=473 bgcolor=#333399>n";
    // get the date column, which is (i presume) a datetime type column
    $thedatetime = mysql_result($result,0,"date");
    // the function
    function changeFormat($fromQuery) {
    // let's split first by spaces
    $splitDateTime = explode(" ",$fromQuery);
    // and now $splitDateTime is an array which $splitDateTime[0] is the date and $splitDateTime[1] is the time..
    // let's split these again
    $DateElements = explode("-",$splitDateTime[0]);
    $TimeElements = explode(":",$splitDateTime[1]);
    // Now we format it now that its been split up
    $ReturnVar = '<b>'.$DateElements[1].'.'.$DateElements[2].'.'.$DateElements[0].'</b><font size=-1> '.$TimeElements[0].':'.$TimeElements[1].'</font>';
    // now the row for the date/time/comment
    echo "<tr bgcolor=#333366><td>n";
    // spit out the time/date for the hell of it
    echo $ReturnVar;
    }
    for($x=0;$x<mysql_num_rows($result);$x++) {
    // changeFormat(mysql_result($result,$x,"date");
    // call the function where it rearranges the date/time
    changeFormat($thedatetime);
    printf(" <font size=-2>%s</font></td></tr><tr><td valign=top>%s</td></tr>n", mysql_result($result,$x,1), mysql_result($result,$x,2));
    }

    echo "</table>n";
    ?>
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jul 2000
    Posts
    669
    Rep Power
    15
    I think its because you are only grabbing the first result, if you will be getting more than one record from the db you need to use a while loop like:

    <?php
    // connect to the db duh
    $db = mysql_connect("localhost", "user", "pass");
    mysql_select_db("db",$db);
    // select and arrange the data by the datetime row latest first etc
    $result = mysql_query("select * from body order by date desc");
    // insert the table parameters
    echo "<table border=0 cellpadding=0 cellspacing=10 width=475 height=473 bgcolor=#333399>n";
    // get the date column, which is (i presume) a datetime type column
    //I believe this is where the problem lies
    //$thedatetime = mysql_result($result,0,"date");
    //Should be further down page, see below

    // the function
    function changeFormat($fromQuery) {
    // let's split first by spaces
    $splitDateTime = explode(" ",$fromQuery);
    // and now $splitDateTime is an array which $splitDateTime[0] is the date and $splitDateTime[1] is the time..
    // let's split these again
    $DateElements = explode("-",$splitDateTime[0]);
    $TimeElements = explode(":",$splitDateTime[1]);
    // Now we format it now that its been split up
    $ReturnVar = '<b>'.$DateElements[1].'.'.$DateElements[2].'.'.$DateElements[0].'</b><font size=-1> '.$TimeElements[0].':'.$TimeElements[1].'</font>';
    // now the row for the date/time/comment
    echo "<tr bgcolor=#333366><td>n";
    // spit out the time/date for the hell of it
    echo $ReturnVar;
    }
    while ($myrow = mysql_fetch_array($result)) {
    // call the function where it rearranges the date/time
    changeFormat($myrow["date"]);

    //Where you have the mysql_results change the number sto be the field names in questions
    printf(" <font size=-2>%s</font></td></tr><tr><td valign=top>%s</td></tr>n", $myrow["fieldname1"], $myrow["fieldname2"]);
    }

    echo "</table>n";
    ?>


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

    Join Date
    Jul 2000
    Location
    Boston MA USA
    Posts
    23
    Rep Power
    0
    thanks man

    it works correctly this time (and i mean correctly)

    thnx endlessly for the help

Similar Threads

  1. Replies: 10
    Last Post: May 13th, 2004, 07:38 PM
  2. Wscript.Shell | VBScript :: Set current working directory
    By Onslaught in forum Visual Basic Programming
    Replies: 2
    Last Post: February 3rd, 2004, 02:12 AM
  3. working with ODBC
    By jp1234 in forum Oracle Development
    Replies: 0
    Last Post: February 1st, 2004, 03:26 PM
  4. LAN not working
    By dave2k in forum Computer Hardware
    Replies: 1
    Last Post: January 11th, 2004, 05:18 AM
  5. Replies: 8
    Last Post: December 18th, 2003, 09:29 AM

IMN logo majestic logo threadwatch logo seochat tools logo