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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T22:59:38+00:00 2026-06-11T22:59:38+00:00

The code below searches my mysql database and comes back with postcodes like IG6,RM11,RM8,RM4,RM2,RM6,RM7,RM1,RM5

  • 0

The code below searches my mysql database and comes back with postcodes like IG6,RM11,RM8,RM4,RM2,RM6,RM7,RM1,RM5 and a distance using a stored procedure. (All ok)

PROBLEM: With these results, I want to search another table in same database that may have job information with those Postcodes (probably using LIKE).

What’s the best way to get this working? I have tried many examples (implode, arrays, etc)
Is one connection to database correct? How do I query the variable as it does come back with 2 columns, postcode and Distance. Should I split in an array (how?)

END PRODUCT: HGV Driver RM5, Cleaner RM5, Teacher RM5

(SELECT title FROM jobinfo WHERE location IN results from other query);

 <?php
    include ("conn.php");
    $first="RM5";

    $result = mysql_query("select outcode, GetDistance(Lat, Lon, (SELECT Lat from postcodes where outcode = '$first' limit 1),(SELECT Lon from postcodes where outcode = '$first' limit 1)) as Distance from postcodes having Distance < 3 order by Distance DESC;");
    while($row = mysql_fetch_array($result))
    {
        echo  ($row['outcode']) ;
    } 
    // This returns postcodes

    $resultb = mysql_query("SELECT title FROM jobinfo WHERE location IN ($results[outcode]) ");
    while($row = mysql_fetch_array($resultb))
    {
        echo  ($row['title']) ;
    }
    mysql_close($con);
?> 

Please help…..any reference to join table needs full explanation as all so far don’t 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-11T22:59:39+00:00Added an answer on June 11, 2026 at 10:59 pm

    First Prepare the output into the clause:

    in the first while loop:

    while($row = mysql_fetch_array($result))
     {
        $array[] = $row['outcode'] ;
     } 
    

    Then prepare the array for the IN clause:

    foreach ($array as $a) {$clause.= "'$a',";}
    $clause=substr($clause,0,-1)
    

    Finally use the clause for the IN statement:

    $resultb = mysql_query("SELECT title FROM jobinfo WHERE location IN ($clause) "
    

    ===== EDIT === LIKE statement

    For like.. you need multiple like statement OR together.. Using SQL LIKE and IN together

    Change the prepare clause code to this:

    foreach ($array as $a) {$clause.= " location LIKE '%$a%' OR";}
    $clause=substr($clause,0,-3)
    

    AND the sql becomes:

    $resultb = mysql_query("SELECT title FROM jobinfo WHERE $clause ");
    

    Of course you will want to addin some more error checking.. think of the possible injection.

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

Sidebar

Related Questions

Below is my code and currently it searches the whole webpage. I'm trying to
Code below is used to save PostgreSql database backup from browser in Apache Mono
The code below works well right now; however, it's serially executed. I'd like to
The below code searches, copies & pastes the found data into another worksheet. However,
I have a form that searches a MySQL database using PHP. Currently, when a
The code below obviously searches a directory for Files that contain the word FINAL
The piece of code below takes a string (userstring) and searches all .txt and
Code below is working well as long as I have class ClassSameAssembly in same
The code below simply didn't work. document.getElementById('files').addEventListener('change', handleFileSelect, false); reported by firebug that this
This code below allows me to find the word error in all my files

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.