Shannon Hollingsworth
Shannon Hollingsworth

Reputation: 61

Concatenate Query Results: Possible?

Wondering if this is how it works:

$result .= mysqli_query($query1);
$result .= mysqli_query($query2);

Would $result be the combination of queries 1 and 2?

Upvotes: 2

Views: 678

Answers (2)

Explosion Pills
Explosion Pills

Reputation: 191819

No, because you have to fetch the results from mysqli_query. That function will only return the result resource.

The fetch results are usually not a string either but rather an array or object. This means that concatenation still wouldn't work. You may do something like:

$result = mysqli_query($query1);
$row = mysqli_fetch_array($result);
$value .= $row['selectedValue'];
$result = mysqli_query($query2);
$row = mysqli_fetch_array($result);
$value .= $row['otherSelectedValue'];

Upvotes: 1

Orangepill
Orangepill

Reputation: 24665

If you are selected the same fields in both queries you can do this:

$result = mysqli_query($query1." union ".$query2);

Upvotes: 0

Related Questions