Results 1 to 8 of 8

Thread: MySQL Reverse Query?

  1. #1
    Join Date
    Sep 2008
    Posts
    241
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default MySQL Reverse Query?

    Does anyone know how to reverse the output of a MySQL query with PHP?
    I tried storing it into an array and flipping, but no luck.

    Any ideas?
    PM me if you need any help with math.
    I can try to help you with anything!


  2. #2
    Join Date
    Feb 2006
    Location
    Amsterdam
    Posts
    13,692
    Mentioned
    146 Post(s)
    Quoted
    130 Post(s)

    Default

    Quote Originally Posted by xXxBlender3DxXx View Post
    Does anyone know how to reverse the output of a MySQL query with PHP?
    I tried storing it into an array and flipping, but no luck.

    Any ideas?
    Can you give an example? You can't just invert any query.



    The best way to contact me is by email, which you can find on my website: http://wizzup.org
    I also get email notifications of private messages, though.

    Simba (on Twitter | Group on Villavu | Website | Stable/Unstable releases
    Documentation | Source | Simba Bug Tracker on Github and Villavu )


    My (Blog | Website)

  3. #3
    Join Date
    Sep 2008
    Posts
    241
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    This is what I had:

    PHP Code:
    <?php

    $dbconnect 
    mysql_connect("localhost"":norris:"":norris:");

    mysql_select_db(":norris:"$dbconnect);

    $articles mysql_query("SELECT * FROM Articles");

    while (
    $row mysql_fetch_array($articles))
    {
        print(
    '<a class="pagetitle" href="' $row['url'] . '">' $row['title'] . ' </a>');
        print(
    "\n<br />\n");
        print(
    '<div class="creator">' $row['creator'] . '</div>');
        print(
    "\n<br />\n");
        print(
    '<div class="description">' $row['description'] . '</div>');
        print(
    "<hr>\n");
    }

    mysql_close($dbconnect);

    ?>
    This is what I tried:
    PHP Code:
    <?php

    $dbconnect 
    mysql_connect("localhost"":norris:"":norris:");

    mysql_select_db(":norris:"$dbconnect);

    $articles mysql_query("SELECT * FROM Articles");
    $temp 0;

    while (
    $row mysql_fetch_array($articles))
    {
        
    $row['title'] = $title[$temp];
        
    $row['description'] = $description[$temp];
        
    $row['creator'] = $creator[$temp];
        
    $row['url'] = $url[$temp];
        
        
    $temp++;
    }

    $temp 0;

    while (
    $temp count($title))
    {
        print(
    '<a class="pagetitle" href="' $url[$temp] . '">' $title[$temp] . ' </a>');
        print(
    "\n<br />\n");
        print(
    '<div class="creator">' $creator[$temp] . '</div>');
        print(
    "\n<br />\n");
        print(
    '<div class="description">' $description[$temp] . '</div>');
        print(
    "<hr>\n");
    }

    mysql_close($dbconnect);

    ?>
    I want to make the query:
    PHP Code:
    1
    2
    3
    4
    5

    Become:
    PHP Code:
    6
    5
    4
    3
    2

    I can't store it into an array for some reason...
    Any ideas why?
    Last edited by Blender; 05-07-2009 at 11:03 PM.
    PM me if you need any help with math.
    I can try to help you with anything!


  4. #4
    Join Date
    Sep 2008
    Posts
    241
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Oops! Never mind...

    I typed:
    PHP Code:
        $row['title'] = $title[$temp];
        
    $row['description'] = $description[$temp];
        
    $row['creator'] = $creator[$temp];
        
    $row['url'] = $url[$temp]; 
    Instead of:
    PHP Code:
         $title[$temp] = $row['title'];
         
    $description[$temp] = $row['description'];
         
    $creator[$temp] = $row['creator'];
         
    $url[$temp] = $row['url']; 
    Fixed!
    Thanks for making me type it out!
    PM me if you need any help with math.
    I can try to help you with anything!


  5. #5
    Join Date
    Feb 2007
    Location
    Access Violation at 0x00000000
    Posts
    2,865
    Mentioned
    3 Post(s)
    Quoted
    18 Post(s)

    Default

    Can't you put "ORDER BY `title` DESC" in there?
    Ce ne sont que des gueux


  6. #6
    Join Date
    Sep 2008
    Posts
    241
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    It is a forum that I made.
    It displayed the oldest topics first, and newest last.
    I needed to flip it around.
    PM me if you need any help with math.
    I can try to help you with anything!


  7. #7
    Join Date
    Feb 2007
    Location
    Access Violation at 0x00000000
    Posts
    2,865
    Mentioned
    3 Post(s)
    Quoted
    18 Post(s)

    Default

    Well then "ORDER BY `post_date` DESC"?
    Ce ne sont que des gueux


  8. #8
    Join Date
    Feb 2006
    Location
    Amsterdam
    Posts
    13,692
    Mentioned
    146 Post(s)
    Quoted
    130 Post(s)

    Default

    Just use ORDER BY <ENTITY1> [ENTITY2...] as Floor66 stated. Also, ASC = Ascending Order, Desc = descending order. Each Entity can be ASC or DESC.



    The best way to contact me is by email, which you can find on my website: http://wizzup.org
    I also get email notifications of private messages, though.

    Simba (on Twitter | Group on Villavu | Website | Stable/Unstable releases
    Documentation | Source | Simba Bug Tracker on Github and Villavu )


    My (Blog | Website)

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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