SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot
    Join Date
    May 2005
    Posts
    172
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question ORDER BY date DESC and Kevin Yank's Paging Result Sets

    Dear Forum

    I'm a beginner developing a hobby site based around Kevin's very worthy PHP/MySql introduction and more recently have employed his excellent Paging Result Sets.
    I would now love to have my results displayed in date descending order ( ORDER BY date DESC ) but haven't been able to patch this into Kevin's query.

    <?php
    require('pagedresults.php');

    $cnx = @mysql_connect('localhost','kyank','********');
    mysql_select_db('jokes',$cnx);
    $rs = new MySQLPagedResultSet("select * from jokes where aid=$aid",
    5,$cnx);
    ?>


    Can anybody help?
    Thanks

  2. #2
    Umm. PHP Guru....Naaaah jaswinder_rana's Avatar
    Join Date
    Jul 2004
    Location
    canada
    Posts
    3,193
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <?php
    require('pagedresults.php');

    $cnx = @mysql_connect('localhost','kyank','********');
    mysql_select_db('jokes',$cnx);
    $rs = new MySQLPagedResultSet("select * from jokes where aid=$aidorder by date desc limit 5,$cnx);//i think you meant limit not sure though
    ?>
    this page also has a tutorial http://www.webdevelopersnotes.com/tu...ring_data.php3

    also you can always download documententation for mysql which is of great help here. http://dev.mysql.com/get/Downloads/M....chm/from/pick
    ---------------------------
    Errors = Improved Programming.
    My Site

  3. #3
    SitePoint Zealot
    Join Date
    May 2005
    Posts
    172
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy didn't quite mean that.....

    Hi Jaswinder_rana

    Thank you for your help but your hunch was wrong I'm afraid.

    The 5 in the php here actually stipulates the number of results to be displayed per page - rather than the total that should be returned.

    <?php
    require (etc) ....
    $rs = new MySQLPagedResultSet("select * from jokes where aid=$aid",
    5,$cnx);
    ?>

    I looked at your links - very useful but my problem here really stems from using a select clause that is more sophisticated than my abilities (and perhaps the article).

    btw kevin's article is here - http://www.sitepoint.com/article/662

  4. #4
    Umm. PHP Guru....Naaaah jaswinder_rana's Avatar
    Join Date
    Jul 2004
    Location
    canada
    Posts
    3,193
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    oh, sorry
    i din't look that its not mysql query function

    but, still this query should do
    select * from jokes where aid=$aid order by date desc

    assuming date is in you aid table
    ---------------------------
    Errors = Improved Programming.
    My Site

  5. #5
    SitePoint Zealot
    Join Date
    May 2005
    Posts
    172
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    no need for apologies jaswinder_rana.


    I've tried this (plus a few other stabs in the dark - but with no luck.
    <?php
    require (etc) ....
    $rs = new MySQLPagedResultSet("select * from jokes where aid=$aid order by Date desc",
    5,$cnx);
    ?>

    This produces the error
    Parse error: parse error, unexpected T_VARIABLE in ..............

    btw - the Date would be in the Jokes table (and it would be the jokes i would want sorted by date rather than aid) - does this make a difference?

  6. #6
    SitePoint Zealot
    Join Date
    May 2005
    Posts
    172
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    fixed!

    Hi Jaswinder_rana

    but, still this query should do
    - You were right - it does still do I must have made a typo somewhere when I tried before.

    Thanks for stopping to help!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •