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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:48:40+00:00 2026-05-23T11:48:40+00:00

My goal is to search column A for string B and if it is

  • 0

My goal is to search column A for string B and if it is found, return which row it was found in, and if it wasn’t found, I would need to know that as well in order to take a different course of action.

My current PHP code:

$string = "teststring";
$searchquery = "SELECT *
                  FROM AllStringsTable 
                 WHERE `Column_A` LIKE '$string'"

$searchresult = mysql_query($searchquery) or die(mysql_error());
$row = mysql_fetch_row($searchresult);
echo "The returned row was: $row";

This just breaks and does nothing, so I think I’m way off here. Also, I have read that for exact string searching that doesn’t require wildcard substrings, etc, LIKE is not needed. So I’m not sure what I would use instead…

  • 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-23T11:48:40+00:00Added an answer on May 23, 2026 at 11:48 am

    You’re almost there. You need the % wildcards:

    // First, prevent sql injection with mysql_real_escape_string
    $string = mysql_real_escape_string($string);
    
    $searchquery = "SELECT * FROM AllStringsTable WHERE `Column_A` LIKE '%{$string}%'";
    //  ----------------------------------------------------------------^^^-------^^^
    
    $searchresult = mysql_query($searchquery) or die(mysql_error());
    
    if (mysql_num_rows($searchresult) == 0) {
      echo "no rows found";
    }
    else {
    
      // You need to loop over the result resource to get all the rows.
      // Better to use mysql_fetch_array()
      while ($row = mysql_fetch_array($searchresult)) {
        $print_r $row;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want my search results to order by score, which they are doing, but
I'm trying to search a DataTable for a row I know exists. // This
My Goal: I would like to search for elements in large XML Schema spec.
Goal: In vB search results, to include posts that quotes the user when that
i need to parse a search string for keywords and phrases in php, for
Goal Java client for Yahoo's HotJobs Resumé Search REST API . Background I'm used
My goal for now is to have a user search for other users who
So my goal here is to have a single search field in an application
goal: I have the string 1234432144 I want to only replace the first 2
My Goal I would like to have a main processing thread (non GUI), and

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.