| | |
Join 3 tables
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: May 2009
Posts: 10
Reputation:
Solved Threads: 0
Hi everybody,
I want to join 3 tables and gain same data from these tables.
1.table:
usr - user information
usr_id
2.table:
res- results
res_usr_id
res_exc_id
res_result
3.table:
exc- excercises
exc_id
exc_excercise_name
Now I want print all results from one user and all excercises from one user.Can somebody help me?I don't know how to write this sql query...
Thanks
I want to join 3 tables and gain same data from these tables.
1.table:
usr - user information
usr_id
2.table:
res- results
res_usr_id
res_exc_id
res_result
3.table:
exc- excercises
exc_id
exc_excercise_name
Now I want print all results from one user and all excercises from one user.Can somebody help me?I don't know how to write this sql query...
Thanks
•
•
Join Date: Jun 2009
Posts: 21
Reputation:
Solved Threads: 3
•
•
•
•
Hi everybody,
I want to join 3 tables and gain same data from these tables.
1.table:
usr - user information
usr_id
2.table:
res- results
res_usr_id
res_exc_id
res_result
3.table:
exc- excercises
exc_id
exc_excercise_name
Now I want print all results from one user and all excercises from one user.Can somebody help me?I don't know how to write this sql query...
Thanks
php Syntax (Toggle Plain Text)
<?php $query = "select * from usr inner join res on usr.usr_id = res.res_usr_id inner join exc on res.res_exc_id = exc.exc_id"; ?>
Last edited by Baldy76; Jun 8th, 2009 at 12:01 am.
•
•
Join Date: Jun 2009
Posts: 68
Reputation:
Solved Threads: 10
if a user doesn't have results, that will be empty field in the results:
users , excercises , and res_result is the 3 table (you did not give these details)
users , excercises , and res_result is the 3 table (you did not give these details)
<?php $uid=1; $sql="SELECT users.usr_id, users.usr, excercises.exc, excercises.exc_excercise_name, results.res, results.res_result FROM excercises RIGHT JOIN (results RIGHT JOIN users ON results.res_usr_id = users.usr_id) ON excercises.exc_id = results.res_exc_id WHERE (((users.usr_id)='$uid'))"; /* fetch here */ ?>
Last edited by djjjozsi; Jun 8th, 2009 at 4:45 am. Reason: forget the BBcode
•
•
Join Date: Oct 2007
Posts: 78
Reputation:
Solved Threads: 5
this seems to very complex
here is the simple solution:
i hope it works.
here is the simple solution:
php Syntax (Toggle Plain Text)
$sql="SELECT * FROM user as a, resutls as b,excercises as c where a.usr_id= b.res_usr_id and b.res_exc_id=c.exc_id";
i hope it works.
Last edited by peter_budo; Jun 8th, 2009 at 10:35 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
•
•
Join Date: May 2009
Posts: 10
Reputation:
Solved Threads: 0
Ok, my code, which doesn't work.
I want print ALL excercises and ALL his results from this excercises, which makes the schoolar in fixed time, when I click on his name on other search page. When he didn't make any excercises, his result list will be blank.
php Syntax (Toggle Plain Text)
//this only for time, which I want to print <?php $query="SELECT res_time FROM res"; $result = mysql_query($query); $dbf = mysql_fetch_assoc($result); ?> <div class="main"> <table cellspacing="20"> <tr> <th></th> <th></th> <th>Count of good excercises</th> <th>Count of bad excercises</th> <th>Success</th> </tr> <tr><td><?php echo $dbf['res_time']; ?></td></tr> <?php $query1="SELECT exc_excercise_name, res_result, usr_id FROM exc, res, usr WHERE res_exc_id = exc_id AND res_usr_id = usr_id"; $result1 = mysql_query($query1); while (list($exc_excercise_name,$res_result) = mysql_fetch_row($result1)) { echo "<tr>", "<td>", "</td>", "<td>", $exc_excercise_name,"</td>", "<td>", "</td>", "<td>", "</td>", "<td>", $res_result, "</td>", "</tr>"; } @mysql_close($connect); ?> </table>
I want print ALL excercises and ALL his results from this excercises, which makes the schoolar in fixed time, when I click on his name on other search page. When he didn't make any excercises, his result list will be blank.
Last edited by peter_budo; Jun 8th, 2009 at 10:36 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
![]() |
Similar Threads
- Join Two tables as outer join (C#)
- join 2 tables with no common fields (MySQL)
- join 2 tables with no common fields (PHP)
- Join two tables in sqldatasource (ASP.NET)
- Problem using JOIN with six tables (MS SQL)
- Join multiple tables (VB.NET)
- Join 3 tables (MS SQL)
Other Threads in the PHP Forum
- Previous Thread: search
- Next Thread: Echo a link with an onclick attribute?
Views: 418 | Replies: 9
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array beginner binary broken cakephp checkbox class cms code cron curl database date datepart directory display download dynamic echo email error file files folder form forms function functions google href htaccess html image include insert integration ip java javascript joomla jquery limit link list login loop mail menu methods mlm mod_rewrite multiple mysql oop parse password paypal pdf php problem query radio random recursion regex remote script search select seo server sessions sms soap source space speed sql structure syntax system table tutorial update updates upload url validation validator variable video web webdesign xml youtube





) 