Tutorials

Data Joins Unions

by Barry Andrew on Jun 30, 2008 5:59:59 PM

Sample Application

Beetsem-Daley wants an input screen, similar to his original spreadsheet, where he can view and edit the subjects chosen by each pupil. Pupils will be listed in alphabetical order within their houses. Checkboxes will be used to indicate pupils' choices.

+------------+----------------+--------------------------------------------------------------+
|   House    |      Pupil     |       Biol Chem Comp Econ Engl Geog Germ Hist Math Phys      |
|  Jardine   |                |                                                              |
|            | Anne Bailey    |       [X]  [ ]  [ ]  [ ]  [ ]  [ ]  [X]  [X]  [ ]  [X]       |
|            | John Patterson |       [ ]  [ ]  [ ]  [ ]  [ ]  [X]  [X]  [ ]  [ ]  [ ]       |
|            | John Tully     |       [X]  [ ]  [ ]  [ ]  [X]  [ ]  [ ]  [X]  [X]  [ ]       |
|            | Mary Sheldon   |       [ ]  [X]  [ ]  [X]  [X]  [ ]  [ ]  [X]  [ ]  [ ]       |
|            | Michael Grove  |       [ ]  [ ]  [ ]  [X]  [X]  [ ]  [ ]  [ ]  [ ]  [X]       |
|            | Peter Appleby  |       [X]  [ ]  [ ]  [X]  [ ]  [ ]  [X]  [ ]  [X]  [ ]       |
+------------+----------------+--------------------------------------------------------------+

The sample code

Hopefully I'll be back with a look at some more advanced queries

Comments

Very useful!
My php for dummies was useless for joins - many thanks!

1. Tom Butterworth on Jul 1, 2008 6:20:06 PM

Barand, could you extend the tutorial to include how to loop the results of the query. I find that when I use a Join , the query will return the first result and then stop. It will not run thru both tables and list all the results. When the 1st match is found, the query then doesnt look thru for other matches which seems to mean that the if stmt following the result is not running correctly .

Ex: $sql11 = "SELECT * FROM `TabA`
INNER JOIN
`TabB` USING (Sid)
WHERE TabA.Eid = $group AND TabA.Month = $month AND TabA.Year = $year ORDER BY TabB.Name asc" ;

$result11 = mysql_query($sql11);
if($myrow11 = mysql_fetch_array($result11))
{ do whatever}
while($myrow11 = mysql_fetch_array($result11);

Thanks !

2. swatisonee on Jul 3, 2008 4:07:11 AM

swatisonee: You'd do it like with all other query results:

3. Daniel Egeberg on Jul 3, 2008 5:45:05 AM

Thanks Daniel but I'm afraid I still fail to run thru the loop. I will post on the help forum the code as it runs without using Join and then the one I am working on to replace it using Joins as it is too long to post as a tute. comment.

4. swatisonee on Jul 4, 2008 4:38:28 AM
Login or register to post a comment.