Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3440986
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:29:51+00:00 2026-05-18T08:29:51+00:00

This doesn’t make sense.. I’m trying to sort posts according to the value of

  • 0

This doesn’t make sense.. I’m trying to sort posts according to the value of a URL parameter but my elseif statement isn’t working.

This is a function that adds another WHERE clause to the query. There are no MYSQL errors I’m just having statement trouble.

function sort_where($where)
{
  if (isset($_GET['sort'])) { 
      $sort = $_GET['sort'];

      if ($sort = "up") {
         $where .= " AND $sort > 1";
      } 
      elseif ($sort = "down") {
         $where .= " AND $sort > 1";
      }

   }

  return $where;
}

The query eventually looks like this

$query = "SELECT * FROM posts WHERE something = $something AND $sort > 1";

The if statement works, the elseif is ignored. I get posts with up > 1 regardless or vice-versa if $sort = down in the if statement.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T08:29:52+00:00Added an answer on May 18, 2026 at 8:29 am

    Actually, neither of the two inner ifs are working correctly.

    You need to use == not =. One equals sign means assignment, and if you assign to a truthy value it always evaluates to true in an if condition. That’s why your elseif appears to never happen.

    You may also need to fix your WHERE clauses, they don’t make sense to me (you’re sorting but comparing to an up column and a down column?). Or maybe that’s how you designed your table…


    Based on your comments, try the following SQL WHERE clauses and see if you get the correct posts:

    if ($sort == "up") {
       $where .= " AND up > down";
    } 
    elseif ($sort == "down") {
       $where .= " AND down > up";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This doesn't make sense to me yet. So the first while loop runs and
This doesn't seem like it should be difficult, but I'm stuck currently. I'm trying
This doesn't really make sense to me. My scroll bar works perfectly if LargeChange
this doesn't make any sense to me. must be wrong or painfully obvious. after
This doesn't have to be Java, but it's what I'm dealing with. Also, not
This doesn't need to be a real time solution, but are there some log
This doesn't seem to work in jqTouch or iUI. But I know it's possible
This does do the delays but doesn't seem to apply the style changes until
This doesn't give the full URL, which breaks as it's in a mailer <%=
This doesn't seem to be working: <select id=mySel onchange=alert('foo')> <option value=a>a</option> <option value=b>b</option> </select>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.