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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T22:38:49+00:00 2026-05-18T22:38:49+00:00

I a set of tables and fields that I would like to select data

  • 0

I a set of tables and fields that I would like to select data from. I have tried the below code without success. Could any one explain to me why this does not work, and if possible, how to make it work.

$fields = "table1.field1, table2.field2, table3.field3, table4.field4";
$tables = "table1, table2, table3, table4";
$table = explode(', ', $tables); //explode the tables string
$field = explode(', ', $fields); //explode the fields string


$i=1;
while ($i<=4) { 
$sql = 'SELECT ' . $field[$i] . ' FROM ' . $table[$i] . ' WHERE ' . $field[$i] . ' LIKE "%' . $str . '%";';
$results = $readConn->query($sql);
$i++;
var_dump($results);
}
  • 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-18T22:38:50+00:00Added an answer on May 18, 2026 at 10:38 pm

    The SQL you’re creating looks like this:

    SELECT table2.field2 FROM table2 WHERE table2.field2 LIKE "%%";
    SELECT table3.field3 FROM table3 WHERE table3.field3 LIKE "%%";
    SELECT table4.field4 FROM table4 WHERE table4.field4 LIKE "%%";
    SELECT  FROM  WHERE  LIKE "%%";
    

    I don’t know what you’re setting $str to, so I don’t have it included here.
    The SQL should run, it looks fine, except that last one … You’ll want to adjust your loop to be, <4, instead of <=4

    Are you sure that you have a valid connection to the database? Are you getting back NULL or something as a result, or an error?

    Also, item #2 in Mark’s answer.
    Also, personally, I find this a lot more readable.

    $sql = sprintf("SELECT %s FROM %s WHERE %s LIKE '%%s%'", $field[$i], $table[$i], $field[$i], $str);
    

    than this

    $sql = 'SELECT ' . $field[$i] . ' FROM ' . $table[$i] . ' WHERE ' . $field[$i] . ' LIKE "%' . $str . '%";';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a set of tables in Oracle and I would like to identify
We have a set of tables and views that merely store some config data
I have a subroutine in excel that I would like to write data to
I'm mapping a set of tables that share a common set of fields: So
I have 2 tables set up like this (irrelevant rows omitted): > product -
I have a query that produces a result like this: The data is sorted
I would like to set up a table within a SQL Server DB that
I have 14 tables that describe a hierarchical XML data structure. One field is
I have a MySQL database that is exhibiting behavior I would like to understand
I have two tables, Sales (ISBN, Sale_Time, [Sale Data Fields]) and Affiliate_Sales (ISBN, Affiliate_Sale-Time,

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.