Gossamer Forum
Home : General : Databases and SQL :

take next repeated field in a relational query

Quote Reply
take next repeated field in a relational query
Hello,

I created a relational query using php. I handled results using mysql_fetch_array(). The problem is that it returns two fields with the same name, and I need to get de second field data. However, I'm only able to get the first one.

This is the code:

$apa_query = "SELECT * ".
"FROM $apa_tables[photos], apa_albums ".
"WHERE $apa_tables[photos].filename LIKE '%$apa_search_query%' AND $apa_tables[photos].filename NOT LIKE '$apa_options[thumb_prefix]' AND apa_albums.ID = apa_photos.album_ID
".
"ORDER BY filename ".
"LIMIT $apa_offset,$apa_photo_per_page";
$apa_result = apa_mysql_query($apa_query,__FILE__,__LINE__);



while($apa_row = mysql_fetch_array($apa_result))
{
print("<tr>\n");
print("<td class=\"common\" align=\"center\">\n");
$apa_param = $apa_param = "apa_album_ID=".$apa_row[album_ID]."&amp;apa_photo_ID=".$apa_row[ID]."&amp;apa_page=1";
$apa_decoded_filename = rawurldecode($apa_row[filename]);
$apa_decoded_thumb = rawurldecode($apa_row[path]);



apa_print_link("photo",$apa_param,"<img src=\"".$apa_module_basedir."albums/".$apa_row[path]."/$apa_options[thumb_prefix]$apa_decoded_filename\" border=\"0\" alt=\"$apa_decoded_filename\">",0);


There is another field in the other table also named ID, but as I said I can't get the data of this one.

Please, what should I change in order to get it working?

Thanks a lot,

Narcís
Quote Reply
Re: [narcis] take next repeated field in a relational query In reply to
Why don't you use mysql_fetch_row instead of mysql_fetch_array? Then you could reference your results by order in the array, rather than column name (e.g. $apa_row[0], $apa_row[1], ...). Is there a reason that wouldn't work?

Fractured Atlas :: Liberate the Artist
Services: Healthcare, Fiscal Sponsorship, Marketing, Education, The Emerging Artists Fund
Quote Reply
Re: [hennagaijin] take next repeated field in a relational query In reply to
Hello,

Thanks a lot!, it worked fine. The only reason is that the script I was modifying used mysql_fetch_array, so I wanted to keep it, but I replaced it for mysql_fetch_row and everything works perfect.

Thanks a lot!

NArcís