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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:49:40+00:00 2026-05-26T12:49:40+00:00

I have this mysql query using PHP and first part is working fine, but

  • 0

I have this mysql query using PHP and first part is working fine, but second part where have search function on site simply cannot get it workable to search properly.
Here is exact code:

<?
$qry = "
SELECT bidprice,timelive,match_title,
CASE 
WHEN game.result LIKE '' THEN 'PENDING'
WHEN game.result LIKE 1 THEN 'WON'
END AS result
FROM game
ORDER BY timelive DESC
";
$searchText = "";
if($_REQUEST['search_text']!=""){
    $searchText = $_REQUEST['search_text'];
$qry .=" WHERE game.bidprice LIKE '%$searchText%' OR game.timelive LIKE '%$searchText%'";
}

//for pagination
$starting=0;
$recpage = 10;//number of records per page

$obj = new pagination_class($qry,$starting,$recpage);       
$result = $obj->result;

?>

So this part of code from above code which is considering searching my ‘game’ table is not working:

$searchText = "";
if($_REQUEST['search_text']!=""){
    $searchText = $_REQUEST['search_text'];
$qry .=" WHERE game.bidprice LIKE '%$searchText%' OR game.timelive LIKE '%$searchText%'";

On my page I receive this error when open this page and try to search for word ‘football’:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL    server version for the right syntax to use near 'game.bidprice like   '%football%' OR game.timelive like   '%football%' at line 9

This search function is working fine when put some simple SELECT statement something like:
SELECT * FROM game
but when done those more complex select query with CASE and WHEN statements which i need its not functioning…

Please help me with proper code for proper search function

  • 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-26T12:49:41+00:00Added an answer on May 26, 2026 at 12:49 pm

    The problem is that you can’t have a WHERE clause after the ORDER BY. Your query currently looks like this:

    SELECT bidprice,timelive,match_title,
    CASE 
    WHEN game.result LIKE '' THEN 'PENDING'
    WHEN game.result LIKE 1 THEN 'WON'
    END AS finalization
    FROM game
    ORDER BY timelive DESC WHERE game.bidprice LIKE '%football%' OR game.timelive LIKE '%football%'
                          ^^^^^^^ error
    

    But you need it to look like this:

    SELECT
        bidprice,
        timelive,
        match_title,
        CASE 
            WHEN game.result LIKE '' THEN 'PENDING'
            WHEN game.result LIKE 1 THEN 'WON'
        END AS finalization
    FROM game
    WHERE game.bidprice LIKE '%football%' OR game.timelive LIKE '%football%'
    ORDER BY timelive DESC
    

    You should add the ORDER BY afterwards in your PHP script. Try something like this:

    $qry = "
    SELECT bidprice,timelive,match_title,
    CASE 
    WHEN game.result LIKE '' THEN 'PENDING'
    WHEN game.result LIKE 1 THEN 'WON'
    END AS result
    FROM game
    ";
    
    $searchText = "";
    if ($_REQUEST['search_text']!="")
    {
        $searchText = mysql_real_escape_string($_REQUEST['search_text']);
        $qry .= " WHERE game.bidprice LIKE '%$searchText%' " .
                " OR game.timelive LIKE '%$searchText%'";
    }
    
    $qry .= " ORDER BY timelive DESC";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a feeling I am completely borking this MySQL query but I'll ask
I have a query like this (Mysql 5.X, PHP - formatted for legibility) $query
I am working on an Asset Database problem using PHP / MySQL. In this
I need to develop this kind of application, i'm using php and mysql first
I'm writing my first website using php/mysql, and jquery. For the next part, the
Original Question mysql-server-6.0.10 I have this problem, I'm using the COMPRESS function to update
So i have this script: <?php $query = mysql_query( SELECT meetup AS text, id
I have this query which works correctly in MySQL. More background on it here
I have a MySQL query like this: SELECT *, SUM(...some SQL removed for brevety)
I have a MySQL query like this: SELECT DAYNAME(CreatedAt) AS TheDay, SUM(Amount) AS TheSum

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.