After three-table join queries ~~~ Array problems ~~ A little long ~~ Thank you for reading and replying ~~ Okay ~~ Directly in the topic mission_need table is the task table, the primary key misneed_idoffer_need table is the bidding table, the primary key offneed_id, the task id field misneed_id, and the associated query after three tables are published ~~~ Array problems ~~
A little long ~~ Thank you for reading and replying ~~ Okay ~~ Direct topic
The mission_need table is a task table and the primary key is misneed_id.
The offer_need table is a bidding table, with the primary key offneed_id, the task id field misneed_id, and the user id field offneed_user
The userinfo table is the user information table and the primary key user_id
Example:
Now we want to retrieve the task information under this task with misneed_id = 5 + all bids under this task + the user information for each bid
The SQL statements I wrote are as follows ~~~
SELECT *
FROM mission_need
Left join offer_need ON mission_need.misneed_id = offer_need.offneed_misid
JOIN userinfo ON offer_need.offneed_user = userinfo. user_id where mission_need.misneed_id = 5
Part of the code is as follows:
require('config.php');
require('conn.php');
$misneed_id=$_GET['id'];
$sql="SELECT *
FROM mission_need
LEFT JOIN offer_need ON mission_need.misneed_id = offer_need.offneed_misid
JOIN userinfo ON offer_need.offneed_user = userinfo.user_id where mission_need.misneed_id='$misneed_id'";
$query=mysql_query($sql);
$result=mysql_fetch_array($query);
print_r($result);
$smarty->display('need_view.html');
?>
Normally, two rows of records are retrieved in my database...
But the output array is like this.
Array ([0] => 1 [misneed_id] => 1 [1] => test [misneed_title] => test [2] => test [misneed_text] => test [3] => 5 [misneed_user] => 5 [4] => 4444 [misneed_price] => 4444 [5] => 0 [misneed_status] => 0 [6] => 0 [misneed_moneystatus] => 0 [7] => 20130119170332 [misneed_time] => 20130119170332 [8] => 20130102122522 [misneed_deadline] => 20130102122522 [9] => 1 [misneed_classid] => 1 [10] =>. /upload_file/5/130119050132.jpg [misneed_file] =>. /upload_file/5/130119050132.jpg [11] => 1 [offneed_id] => 1 [12] => offer test [offneed_text] => offer test [13] => 50 [offneed_price] => 50 [14] => 20130120211950 [offneed_time] => 20130120211950 [15] => 3 [offneed_round] => 3 [16] => 0 [offneed_status] => 0 [17] => 5 [offneed_user] => 5 [18] => 1 [offneed_misid] => 1 [19] => 5 [user_id] => 5 [20] => pingtai [user_name] => pingtai [21] => Users [user_pwd] => Users [22] => 1 [user_power] => 1 [23] => 555@qq.com [user_email] => 555@qq.com [24] => 2147483647 [user_phone] => 2147483647)
Here is obviously only one record ~~ Question
------ Solution --------------------
Run $ result = mysql_fetch_array ($ query) once );
Read only one record
------ Solution --------------------
require('config.php');
require('conn.php');
$misneed_id=$_GET['id'];
$sql="SELECT *
FROM mission_need
LEFT JOIN offer_need ON mission_need.misneed_id = offer_need.offneed_misid
JOIN userinfo ON offer_need.offneed_user = userinfo.user_id where mission_need.misneed_id='$misneed_id'";