user1321210
user1321210

Reputation:

PHP Select query

Hello All,

       for()
          {
            SELECT * from x union select * from y union select * from z
          }

I added union to all other queries which comes,when for loop runs but in my last line ,i've to remove the UNION ,how to do this.

Thanks in advance!

Upvotes: 0

Views: 293

Answers (1)

Travesty3
Travesty3

Reputation: 14469

You haven't given much information to work with, but I'm assuming you're starting with an array of query strings. If so, try this:

$queries = array();
$queries[] = "SELECT * FROM x";
$queries[] = "SELECT * FROM y";
$queries[] = "SELECT * FROM z";

$query = implode(" UNION ", $queries);

// $query now contains "SELECT * FROM x UNION SELECT * FROM y UNION SELECT * FROM z"

Upvotes: 1

Related Questions