Page 1 of 2 12 Last
  • Jump to page:
    #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! you guys were a big help (both here and on the mysql board)
    this is my current standing
    <?php
    $db = mysql_connect("localhost", "user", "pass");
    mysql_select_db("table",$db);
    $result = mysql_query("SELECT * FROM body ORDER BY date DESC",$db);
    echo "<table border=0 cellpadding=0 cellspacing=10 width=475 height=473 bgcolor=#333399>n";
    while ($myrow = mysql_fetch_row($result)) {
    printf("<tr bgcolor=#333366><td><b>%s</b> <font size=-2>%s</font></td></tr><tr><td valign=top>%s</td></tr>n", $myrow[0], $myrow[1], $myrow[2]);
    }
    echo "</table>n";
    ?>

    ok... im using datetime for the time (woohoo!) and it works great...
    now i need to format from 'yyyy/mm/dd hh:mm:ss'
    to '<b>dd/mm/yy</b> hh:mm'
    yes thats html code in there
    i've looked at the date command in the manual but it dosen't help much
    any insight to this?

    Thanks!

    Ted/likwid
  2. #2
  3. No Profile Picture
    a total freak
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    33
    Rep Power
    15
    Actually there's a way to generate the datetime from mysql the way you wanted, but i just can't remember how (im sure these commands are all in the mysql manual).. but there's always another way around. You could just create a function, which then explode() the datetime by space, and then explode() them again by '-' and by ':'. And finally, return a variable which values the datetime setup you wanted..
    got the idea..?

    [This message has been edited by freakyG! (edited July 21, 2000).]
  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
    vaugely yes.... but i got lost along the way hehehe
  6. #4
  7. No Profile Picture
    a total freak
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    33
    Rep Power
    15
    ok, let's just hit those scripts..

    ...
    $result = mysql_query("select * from body order by date desc");
    // get the date column, which is (i presume) a datetime type column
    $thedatetime = mysql_result($result,0,"date");
    // call the function
    changeFormat($thedatetime);
    ...

    ok, now 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]);
    $ReturnVar = '<b>'.$DateElements[2].'/'.$DateElements[1].'/'.$DateElements[0].'</b> '.$TimeElements[0].':'.$TimeElements[1];
    return($ReturnVar);
    }
    ...

    getting my step now..?

    ------------------
    ---freakyG!---
    kinumedia, web developer

    [This message has been edited by freakyG! (edited July 21, 2000).]
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Location
    Boston MA USA
    Posts
    23
    Rep Power
    0
    ahhhhhhh! then i just need to change the printf to show those fields as the correct formatting (then i only need myrow 1 & 2)?

  10. #6
  11. No Profile Picture
    a total freak
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    33
    Rep Power
    15
    mmm.. actually you could of just echo or printf right in the function... so... instead of:

    ...
    return($ReturnVar);
    ...

    you'll might as well, do:

    ...
    echo $ReturnVar;
    ...

    pretty easy, huh?
    what's myrow[1] and myrow[2] anyway?


    ------------------
    ---freakyG!---
    kinumedia, web developer
  12. #7
  13. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Location
    Boston MA USA
    Posts
    23
    Rep Power
    0
    they're the rest of the data in the table

  14. #8
  15. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Location
    Boston MA USA
    Posts
    23
    Rep Power
    0
    bah http://www.likwid.org/test/multiplepulldata.php3
    it breaks still...
    i don't think i have it looped correctly...
    <?php
    // connect to the db duh
    $db = mysql_connect("localhost", "user", "pass");
    mysql_select_db("database",$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");
    // call the function
    changeFormat($thedatetime);
    // now the function itself
    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]);
    $ReturnVar = '<b>'.$DateElements[2].'.'.$DateElements[1].'.'.$DateElements[0].'</b> '.$TimeElements[0].':'.$TimeElements[1];
    echo "<tr bgcolor=#333366><td>n";
    echo $ReturnVar;
    }
    while ($myrow = mysql_fetch_row($result)) {
    printf("<font size=-2>%s</font></td></tr><tr><td valign=top>%s</td></tr>n", $myrow[1], $myrow[2]);
    }
    echo "</table>n";
    ?>
    i have a feeling i have to name the 2nd and 3rd rows and throw them up in the loop where it breaks apart the date/time?
  16. #9
  17. No Profile Picture
    a total freak
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    33
    Rep Power
    15
    i don't know what you really wanted the script to do,.. but it seems that the script worked just fine...
    did you want to include the date and time for each row of myrow[1] and myrow[2]..?
    is that what you meant?
  18. #10
  19. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Location
    Boston MA USA
    Posts
    23
    Rep Power
    0
    ayup
    if you look at it
    there's date and comment (in the dark blue row)
    then "woo1t" below it
    it should be then another date and comment (in the dark blue row) then "hopefully...." below it
    somehow the "comments" (ie: hey woo yeah) got shot out of the table up to the top *shrug*

    but yes... i want it to repeat date/time comment then body
    (as i have datetime comment and body as rows in my table)

    thnx
  20. #11
  21. No Profile Picture
    a total freak
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    33
    Rep Power
    15
    well, in that case, you should call the changeFormat function in the loop, right before (or on top of) the printf.. command
    so (if myrow[0] is the datetime column) it'll be more than less like:

    ...
    while ($myrow = mysql_fetch_row($result)) {
    changeFormat($myrow[0]);
    printf("<font size=-2>%s</font></td></tr><tr><td valign=top>%s</td></tr>n", $myrow[1], $myrow[2]);
    }
    ...

    does this solve the problem?
  22. #12
  23. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Location
    Boston MA USA
    Posts
    23
    Rep Power
    0
    so close yet so far
    it seems the issue is that it runs the first loop
    *then* the second.... (which finally adds the other info into everything but the first)

    so when it outputs
    you get a date and thats all for the first (processes the date... all done processing)
    then goes onto the second loop (takes the info from the first... and throws it into the loop for the rest of the fields in the table)

    blah!!!@$!@#$
  24. #13
  25. No Profile Picture
    a total freak
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    33
    Rep Power
    15
    that's why i set it to:

    changeFormat($myrow[0]);

    if your datetime column is at array numbro 0, then this will always fetch the corresponding datetime for each row..

    or.......

    you could might as well use the for looping such as:

    ..
    for($x=0;$x<mysql_num_rows($result);$x++) {
    changeFormat(mysql_result($result,$x,"date");
    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));
    }
    ..

    the mysql_result($result,$x,1) and mysql_result($result,$x,2) is the same thing as myrow[1], myrow[2]...

  26. #14
  27. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Location
    Boston MA USA
    Posts
    23
    Rep Power
    0
    you're prolly beginning to hate me now
    but i gotta learn somehow
    thats what i have at the bottom as of now
    the date/time loop does its thing... the first time around it *only* throws the date/time then proceeds to the comment/body loop and does its processing....
    i need to dump the $ReturnVar into the second loop (which i figure is the changeformat string)
    so i put the $ReturnVar into the printf?

    $ReturnVar = '<b>'.$DateElements[1].'.'.$DateElements[2].'.'.$DateElements[0].'</b> '.$TimeElements[0].':'.$TimeElements[1];
    echo "<tr bgcolor=#333366><td>n";
    echo $ReturnVar;
    }
    while ($myrow = mysql_fetch_row($result)) {
    changeFormat($myrow[0]);
    printf("<font size=-2>%s</font></td></tr><tr><td valign=top>%s</td></tr>n", $myrow[1], $myrow[2]);
    }

  28. #15
  29. No Profile Picture
    a total freak
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    33
    Rep Power
    15
    hey.. i see the script is totally working the way you wanted... so, what did you do to it? anything i dont know?
Page 1 of 2 12 Last
  • Jump to page:

Similar Threads

  1. adjusting time duration from a drop down menu
    By spyghost in forum HTML Programming
    Replies: 9
    Last Post: March 1st, 2004, 02:05 AM
  2. Text box Number formatting
    By Bijoos in forum Visual Basic Programming
    Replies: 6
    Last Post: February 17th, 2004, 09:19 PM
  3. time in - time out
    By newbiex in forum PHP Development
    Replies: 2
    Last Post: February 9th, 2004, 02:04 AM
  4. Replies: 0
    Last Post: February 1st, 2004, 11:13 AM
  5. Adding minutes to time and other calcs
    By Jez433 in forum PHP Development
    Replies: 5
    Last Post: January 21st, 2004, 06:00 PM

IMN logo majestic logo threadwatch logo seochat tools logo