Asked  8 Months ago    Answers:  5   Viewed   24 times

Can someone Tell me how to join 3 table with php? Example

SELECT FROM table1, table2,table on INNERJOIN -------------------

let I have 3 table.(question table ,answer table and category table) Here is example form my webpage.

Time remaining 30 minutes(I will get "30 minutes" form Category table)
1. Question (from question table)
2. answer (from answer table)

I don't know how to join 3 table.

 Answers

97

it should be like that,

$this->db->select('*');    
$this->db->from('table1');
$this->db->join('table2', 'table1.id = table2.id');
$this->db->join('table3', 'table1.id = table3.id');
$query = $this->db->get();

as per CodeIgniters active record framework

Wednesday, March 31, 2021
 
cyber_truite
answered 8 Months ago
27

For me the issue was in the php.ini file. The property mysql.default_socket was pointing to file in a non-existent directory. The property was pointing to /var/mysql/mysql.sock but in OSX, the file was located in /tmp/mysql.sock.

Once I updated the entry in php.ini and restarted the webserver, the issue was resolved.

Wednesday, March 31, 2021
 
jcubic
answered 8 Months ago
81

Don't be afraid to change core files, just alter FCPATH/system/database/drivers/mysqli/mysqli_driver.php

function escape_str($str, $like = FALSE)
{
    if (is_array($str))
    {
        foreach ($str as $key => $val)
        {
            $str[$key] = $this->escape_str($val, $like);
        }

        return $str;
    }

    if (function_exists('mysqli_real_escape_string') AND is_object($this->conn_id))
    {
        $str = mysqli_real_escape_string($this->conn_id, $str);
    }
    else
    {
        $str = addslashes($str);
    }

    // escape LIKE condition wildcards
    if ($like === TRUE)
    {
        $str = str_replace(array('%', '_'), array('\%', '\_'), $str);
    }

    return $str;
}

I had the same issue


Better solution -> https://ellislab.com/forums/viewthread/228288/ "stated in github that it will be fixed in CodeIgniter 3.0 the fix already exists in that repository"

Wednesday, March 31, 2021
 
themihai
answered 8 Months ago
99

Be explicit about which table the column belongs to. This also applies to the SELECT part of the query:

SELECT table1.column AS column1, table2.column AS column2
FROM table1
LEFT JOIN table2
ON table1.column = table2.column

To save you some typing time, use table aliases:

SELECT t1.column AS column1, t2.column AS column2
FROM table1 AS t1
LEFT JOIN table2 AS t2
ON t1.column = t2.column
Wednesday, August 4, 2021
 
ariel
answered 3 Months ago
13

First lets get a list of values that exist in both tables. If you are using excel 2010 or later then in Sheet 3 A2 put the following formula:

=IFERROR(AGGREGATE(15,6,Sheet2!$A$1:$A$5000/(COUNTIF(Sheet1!$A$1:$A$5000,Sheet2!$A$1:$A$5000)>0),ROW(1:1)),"")

If you are using 2007 or earlier then use this array formula:

=IFERROR(SMALL(IF(COUNTIF(Sheet1!$A$1:$A$5000,Sheet2!$A$1:$A$5000),Sheet2!$A$1:$A$5000),ROW(1:1)),"")

Being an array formula, copy and paste into the formula bar then hit Ctrl-Shift-Enter instead of Enter or Tab to leave the edit mode.

Then copy down as many rows as desired. This will create a list of ID'd that are in both lists. This does assume that ID is a number and not text.

Then with that list we use vlookup:

=IF(A2<>"",VLOOKUP(A2,Sheet1!A:B,2,FALSE),"")

This will then return the value from Sheet 1 that matches.

enter image description here

Wednesday, September 29, 2021
 
v1n_vampire
answered 1 Month ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :
 
Share