Two database queries housed within a single array

I am currently working with 2 queries that are extracting elements from 2 separate databases.

My goal is to combine the results of both queries into a single array. Right now, I have one array return, but I want to merge the data from these 2 queries into a unified array.

//DB QUERY
$query1 = $this->A_db->get();

//DB QUERY
$query2 = $this->B_db->get();

if($query1->num_rows() > 0){
    return $query->result_array();
}

Answer №1

It seems from your question that you are looking to combine arrays directly using the array_merge() function.

return array_merge($query1->result_array(), $query2->result_array());

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Laravel encounters a critical FatalErrorException within the SerializableClosure.php file

I encountered a problem with my Laravel application. Can someone assist me in troubleshooting this particular exception? FatalErrorException in SerializableClosure.php(153) : eval()'d code line 2: I am unable to call the getOwnerEmail() function ...

Guide on setting a session variable upon clicking an <a> hyperlink

Having this issue where I need to set a session variable when clicking on a regular link like: <a href="home" name="home">home</a> From my research, it seems PHP cannot capture the click event in order to set a session variable. I've he ...

Saving user input from a PHP form into a text file

Below is a simple PHP form that performs a calculation when submitted. Now, I want to save the inputs (height, weight) and calculation result to a text file without displaying the path of the file. Ideally, I would like each submission to add a new line in ...

Utilize cURL to submit form data and capture a JSON validation error response from an external API

My local web server has certain restrictions that require me to utilize cURL to process my comment form data on a remote server. The goal is to send the form data via cURL to a remote validation script. The validation script will then check for any errors ...

The function `filter_has_var` is a useful tool

I struggled with this function for a long time. Previously, I was using: if ( !filter_has_var(INPUT_POST, 'email') ) { code here etc. } Despite being the correct format, it never worked as expected. I referred to the documentation. After s ...

PHP - File_get_contents not recognizing CURL response

Here is the script I'm working on: <?php $auth_token = "privateprivateprivate"; $curl = curl_init("https://api-sandbox.coingate.com/v2/orders/"); $headers = array(); $headers[] = "Authorization: Token " .$auth_token; $output = curl_exec($curl); ...

PHP - Unable to store the input content

I've encountered an issue with my website where I need to create a form for users to submit new information or news. Below is the code snippet that I have: <?php include "0begin.php"; $title=$_POST["title"]; isset($title) or $title=$_GET["tit ...

How to increment hours, minutes, and seconds to a DateTime object in PHP

I have a specific timestamp and I need to add a certain number of hours, minutes, and seconds to it. Here is the method I attempted: date_default_timezone_set('UTC'); $now = DateTime::createFromFormat('U.u', number_format(microtime(t ...

Using the continue keyword within a ternary operator in PHP: a guide

I am interested in using the continue keyword within a ternary operator to simplify my code. I attempted to do so in the following manner, but encountered a syntax error. in_array($SqlPackageCategoryProductResultRowObj->product_id, $individualProduct)? ...

The webpage becomes unresponsive due to an Ajax request

Creating a generic way to call ajax requests on my webpage has been challenging. I've developed an extension method for calling post requests asynchronously. $.tiqPost = function(action,data,callback) { alert('Posting...'); $.fancyb ...

The division element nested within a select tag

HTML: <div class="row"> <div class="form-group"> <div class="col-xs-10"> <label for="class_code_reservation">Class Code</label> <select type="text" class="form-control" id="class_code_reservation" na ...

What is the correct mySQL command to insert URLs into a database?

I encountered an issue while attempting to insert a URL into a mySQL database. The URL string in question is: http://pbs.twimg.com/profile_images/1708867059/405000_10150426314376065_707061064_8645107_703731598_n_normal.jpg The error message that I am re ...

Implementing Jquery Ajax in the CodeIgniter framework

Recently, I have been encountering some issues while attempting to utilize jQuery ajax in Codeigniter. Despite having successfully implemented jQuery ajax in previous projects, my current code seems to be causing complications. Below is the snippet that I ...

Using Ajax with Bootstrap's typeahead feature

I've been struggling to implement typeahead on my website, and here's what I've attempted so far. Here is my HTML and code: <html> <head> <title>typeahead</title> <link href="//maxcdn.bootstrapcdn.com/ ...

Techniques for sending PHP variables to window.location using JavaScript

How can I successfully include a PHP variable in a JavaScript window.location function? The current code snippet below does not seem to be working for me. echo '<script>location.href = "reportConsumption.php?creategenReport="'.$genid.&apos ...

Update Laravel to use Bootstrap 4.00 alpha 2 instead of bootstrap-sass 3

Is there a way to accomplish this task by making changes to the package.json file? If so, how would it be done? current: { "private": true, "devDependencies": { "gulp": "^3.9.0", "laravel-elixir": "*", "bootstrap-sass": "^3.0.0" }, "d ...

A step-by-step guide on leveraging ajax for submitting comments in WordPress

I am currently working on developing a custom WordPress theme that includes a unique contact form. This contact form is designed to store data in a custom post type called "Messages" whenever a user submits the form. Below is the code snippet for the cont ...

My PHP script seems to be neglecting the value of the HTTP

After developing a login and signup system with essential files such as: register.php for registration, login.php for logging in, do_register.php to handle registration form submission, and do_login.php to process login form data; I encountered an issue ...

Is it permissible to utilize hyphens in query string parameters?

My question is similar to the one found here, but with a more specific focus on whether using hyphens in query string parameter values is syntactically correct. I am working with PHP to parse $_SERVER['QUERY_STRING']. I would like clarification ...

Implementing reCAPTCHA and PHP for Email Form Submission

Currently using GoDaddy as the web host for my website. Struggling to integrate reCAPTCHA into the email form on my site. I successfully pass the reCAPTCHA test, but emails are not being sent. So far, the website has been built using PHP and HTML only. ...