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 7714595
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T02:10:08+00:00 2026-06-01T02:10:08+00:00

I have this piece of php – mysql code: When a user tagged in

  • 0

I have this piece of php – mysql code:

When a user tagged in my database as a woman opens the page it queries the database for some data with the number 1012,1013,1014 else only 1012,1013.

// $php_variable=2 

            $SQL_M = "SELECT @gender:=$php_variable, B.id, B.notes, B.time_logged
            FROM database.evs B
            INNER JOIN (select @gender:=0) as Something
            WHERE
            CASE WHEN @gender=2
            THEN (B.items IN ('1012', '1013', '1014'))
            ELSE (B.items IN ('1012', '1013'))
            END
            ORDER BY B.time_logged ASC";


            $result = mysql_query($SQL_M);
            $mycount = mysql_num_rows($result);
            if ($mycount > 0)  {
                while ($mrow = mysql_fetch_array($result))
                {
                    extract($mrow);
                    echo ">>>>".$id."<br/>"
                    //Works locally - not on server.
                }
            }  

$php_variable is 2.

It should output items with item id in : 1012,1013,1014
Instead it outputs results for items in 1012,1013.

The strange thing is that I tested this query locally (from php and mysql query alone)
and on the server (Plesk – Mysql) and it runs just fine.

It doesn’t run within the php file in the server -also the ORDER is not functioning properly.

The query that should execute is:

$SQL_M = "SELECT B.id, B.notes, B.time_logged
FROM database.evs B
WHERE B.items IN ('1012', '1013', '1014')
ORDER BY B.time_logged ASC";

Php version: 5.16 (Local and server)
MySQL version: 5.0.77 (local and server)

Thanks in advance for your help.

  • 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-06-01T02:10:09+00:00Added an answer on June 1, 2026 at 2:10 am

    The way I would do it:

    $SQL_M = "SELECT B.id, B.notes, B.time_logged FROM database.evs B";
    if ($php_variable == 2)
    {
      $SQL_M .= " WHERE B.items IN ('1012', '1013', '1014')";
    }
    else
    {
      $SQL_M .= " WHERE B.items IN ('1012', '1013')";
    }
    $SQL_M .= " ORDER BY B.time_logged ASC";
    

    This can be written simpler still, but this is just to show the general idea.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this piece of code on a php page, at the bottom: window.opener.location.href=/index.html;
Let's say I have this little piece of code: <?php $tmp = str_split('hello world!',2);
I have a piece of PHP code that is generating over 6000 queries to
I have this piece of code: <?php $pattern = /<span\b[^>]*>(.*?)</; $html = file_get_contents(http://www.bicicletapublica.com.ar/mapa.aspx); $results
I have this piece of PHP code: <?php $username=$_POST['username']; $password=$_POST['password']; if($username&&$password){ $connect=mysql_connect(localhost,root,) or die(
I have this piece of code: function MyFunction() { $.ajax({ type: POST, url: ajax.php,
I have this piece of code <ul> <?php $categories = get_categories('include=9,4,5,6,7,8,3&hide_empty=0'); foreach ($categories as
I have this JQuery piece of code. I want to see wht php outputs.
I have to use this piece of code to save some values in table
I have this piece of code <?php for ($i=0;$i<sizeof($list[tags]); $i++) { if ($list[tags][$i][title]=='list') {

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.