hope my title is clear. I am trying to retrieve results from two tables. So I want everything (hence *) from the table called 'albums'. and I want only all matching (with album_id) results from table 'contributors'.
$result = mysql_query("SELECT * FROM albums LEFT JOIN contributors ON albums.album_id =
contributors.album_id ORDER BY albums.datum DESC; ") or die(mysql_error());
$aantal_rijen = mysql_num_rows($result);
if ($aantal_rijen > 0) {
for ($i = 0; $i < $aantal_rijen; $i++){
$contributors[] = mysql_result($result, $i, 'contributors');}
but i get a list of similar errors:
contributor not found in MySQL result index ...
Joining of two tables is totally new to my, and maybe it's not the way to go, but maybe it's just a plain simple error in this code, anyway, I'm stuck here,
all help is welcome thx S
http://php.net/manual/en/function.mysql-result.php
FIELD
The name or offset of the field being retrieved.
It can be the field's offset, the field's name, or the field's table dot field name (tablename.fieldname). If the column name has been aliased ('select foo as bar from...'), use the alias instead of the column name. If undefined, the first field is retrieved.
You're just using the table name contributors, so either you need to specify a single field or limit your select to only the fields you want
$contributors[] = mysql_result($result, $i, 'contributors.name');
OR
$result = mysql_query("
SELECT contributors.*
FROM albums
LEFT JOIN contributors ON albums.album_id = contributors.album_id
ORDER BY albums.datum DESC;
") or die(mysql_error());