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

  • Home
  • SEARCH
  • 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 9224277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:16:46+00:00 2026-06-18T04:16:46+00:00

I have a MySQL table that looks like this: index | tag | posts

  • 0

I have a MySQL table that looks like this:

index  |  tag  |  posts
-------------------------
  1    | cats  |   9,10
  2    | a cat |   9,10
  3    | kitty |   9,10
  4    | meow  |   9,10

I am trying to just return the row that matches a search query.
I passed the search parameter using a simple ?search=cats.
This is the PHP that I’m using:

$search = $_GET['search'];
$query  = mysql_query("SELECT * FROM tags WHERE tag = '$search'");
echo(mysql_num_rows($query));
$result = mysql_fetch_array($query);
$print  = $result['posts'];
echo($print);

However the mysql_num_rows($query) prints 0 and the $print returns NULL. I can check it with ($print == ""), it evaluates to TRUE and mysql_num_rows($query) returns 4.
I tried setting the search query to something that wasn’t in the table and it retuned FALSE as expected. I also tried removing the WHERE tag = '$search' and it returns the table like it should.

Is there something I’m overlooking?

Edit

Took everyone’s advice and the code I’m using now is:

$search = mysql_real_escape_string($_GET['search']);
var_dump($search); //prints   string(4) "cats"   just like it should
$queryText = "SELECT * FROM tags WHERE tag = '%".$search."%'";
echo($queryText); //SELECT * FROM tags WHERE tag = '%cats%'
$query  = mysql_query($queryText) or die(mysql_error()); //no error
$rows   = mysql_num_rows($query); //this returns 0 and I know it should match 1 row
echo('rows: '.$rows);
$result = mysql_fetch_array($query);
$print  = $result['posts'];
echo($print); //empty

Still have the same problem. The mysql_query is retuning NULL instead of the row or FALSE if it doesn’t match.

(in the future I will use the mysqli API, but I would like to finnish this project in mysql. thanks for your suggestions and advice)

  • 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-18T04:16:48+00:00Added an answer on June 18, 2026 at 4:16 am

    Ok so after referring to the above edit you made, here is the solution

    Use “LIKE” instead of “=” when using wildcard “%”

    So your query now should be

    $queryText = "SELECT * FROM tags WHERE tag LIKE '%" . $search . "%'";
    

    [I created the exact same db on my local system and ran the same code you gave, After making the above changes, It runs as expected]

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

Sidebar

Related Questions

I have a mysql table that looks like this: id col2 col3 col4 1
I have a MySQL table that looks like this: `id` int(10) unsigned NOT NULL
I have a MySQL table that looks something like this: +-----+------------+ | id |
I have a MySQL database table called Participant that looks something like this: (idParticipant)
I have a MySQL Table that looks like this: The SQL to create the
Suppose I have a MySQL table called MyTable, that looks like this: +----+------+-------+ |
I have a partitioned table in MySQL that looks like this: CREATE TABLE `table1`
I have a table in MYSQL that looks like this (notice the html code)
I have a mysql table that looks like this: 1 value1 value2 3534 2
So I have a MySQL table that looks something like this: id timestamp action

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.