Database TABLE-join Question

From: Date: Tue, 10 Oct 2000 10:19:13 +0000
Subject: Database TABLE-join Question
Groups: php.db 
Request: Send a blank email to php-db+get-3464@lists.php.net to get a copy of this message
People I've got another question. I'm creating a photogallery and a description of the fields in the a database with corresponding photos. In this case minerals... I've got three tables (see at botom of mail description of tables). I use the following script but it doesn't work. I get error and when photo is available the script-part for nonavailable is executed. I can't get it to work. Maybe you all can help (again)? Thanks in advance.. Bart <!-- END:PHP-SCRIPT --> <?php require ('/home/mineralen/phplib/cnx.inc'); /*just the db login/select-script*/ $naam_nl = $link; $result = mysql_query ("SELECT * FROM min_data WHERE ID LIKE '$naam_nl'"); if ($row = mysql_fetch_array($result)) { do { echo (" /* Display fields from min_data-database(this goes all well) */ "); /* Here ($result_foto) I want to look up the 'min_ID' from db-min_data in the foto_ID-database and the corresponding foto_ID in the min_foto-database and than display the fields from min_foto-database. Here I get an MySQL-error: Warning: 0 is not a MySQL result index in /www/mineralen/html/galerij/a_min_det.php3 on line 113 The below scripted else {/* Dipslay if goes wrong */} is executed together with the MySQL-error. How do I use the arrays ($result_foto["every-table, every-field"] ??). Normally I use $row["fieldname"], but does this work with a join-query with different tables? Is my query OK?? */ $result_foto = mysql_query ("SELECT bestand, omschrijving, vindplaats, fotograaf FROM min_foto, min_data, foto_ID WHERE foto_ID.foto_ID=" . $naam_nl . " AND min_foto.bestand=foto_ID.foto_ID"); if ($row_foto = mysql_fetch_array($result_foto)) { do { echo ("<table align='center'border='1'><tr><td>\n <table><tr><td bgcolor='#FFFFFF' Align='center' valign='middle'>\n <img border='0' src='images/" . $row_foto["bestand"] . ".jpg' align='center' valign='middle'>\n </td></tr></table></td></tr></table><p>\n"); } while ($row_foto = mysql_fetch_array($result_foto)); } else { echo (" /* Dipslay if goes wrong */ "); } echo ("</td>\n"); } while ($row = mysql_fetch_array($result)); } else { print ("<font face='Verdana' size='3' color='#E1AE00'><b>Sorry, de door u opgevraagde gegevens zijn niet beschikbaar. Mail de volgende foutcode naar de beheerder van mineralen.com</b></font> <font face='Verdana' size='4' color='#FFFFFF'><b>Foutcode MCGAL1036</b></font>"); } ?> <!-- END:PHP-SCRIPT --> ==================================== <!-- BEGIN:DESCRIBE TABLES IN DB --> mysql> show tables; +---------------------+ | Tables in mineralen | +---------------------+ | foto_ID | | min_data | | min_foto | +---------------------+ 4 rows in set (0.00 sec) mysql> describe foto_ID; +-----------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-----------+--------------+------+-----+---------+-------+ | foto_ID | varchar(5) | | PRI | | | | foto_naam | varchar(255) | YES | | NULL | | | min_ID | varchar(5) | YES | | NULL | | | min_naam | varchar(255) | YES | | NULL | | +-----------+--------------+------+-----+---------+-------+ 4 rows in set (0.00 sec) mysql> describe min_foto; +--------------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +--------------+--------------+------+-----+---------+-------+ | bestand | varchar(5) | | PRI | | | | omschrijving | varchar(255) | YES | | NULL | | | vindplaats | varchar(255) | YES | | NULL | | | fotograaf | varchar(255) | YES | | NULL | | +--------------+--------------+------+-----+---------+-------+ 4 rows in set (0.00 sec) mysql> describe min_data; +----------------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +----------------+--------------+------+-----+---------+-------+ | ID | varchar(5) | YES | | NULL | | | naam_nl | varchar(50) | | PRI | | | | naam_du | varchar(50) | YES | | NULL | | | synoniem | varchar(255) | YES | | NULL | | | formule | varchar(150) | YES | | NULL | | | hardheid | varchar(10) | YES | | NULL | | | kleur | varchar(100) | YES | | NULL | | | kleur_streep | varchar(50) | YES | | NULL | | | kristalstelsel | varchar(30) | YES | | NULL | | | kristalvorm | varchar(255) | YES | | NULL | | | dichtheid | varchar(10) | YES | | NULL | | | glans | varchar(50) | YES | | NULL | | | splijtbaar | varchar(255) | YES | | NULL | | | breukvlak | varchar(150) | YES | | NULL | | | taaiheid | varchar(100) | YES | | NULL | | | voorkomen | text | YES | | NULL | | | syst_1 | varchar(10) | YES | | NULL | | | syst_2 | varchar(50) | YES | | NULL | | | syst_3 | varchar(50) | YES | | NULL | | | aggregaat | text | YES | | NULL | | | vindplaats | text | YES | | NULL | | | min_vergelijk | text | YES | | NULL | | +----------------+--------------+------+-----+---------+-------+ 22 rows in set (0.00 sec) <!-- END:DESCRIBE TABLES IN DB -->

« previous php.db (#3464) next »