简体   繁体   中英

Retrieving column data from inner join ambiguous column name

I have this code which executes a search on about 30-40 columns using a programatically generated query on a join of 11 tables so naturally surrogate keys can show up a few times. the results of the search are then grouped by tbl_sub_model.sub_model_sk to prevent double ups in the final search results screen, and I am up to retrieving data from related tables (most one to many).

the code here is supposed to loop through the grouped results, retrieve any badge fields associated with that sub model, concatenate the badges together into one string and echo them after the make and model something like "subaru forrester xs ltd" I get make and model but nothing else at point A and nothing at point B. I'm suspecting it has something to do with the fact that I am referring to "tbl_sub_model.sub_model_sk" rather than for example "model_name". any help would be greatly appreciated.

while ($row = mysql_fetch_array($result)) {
            $badge_result_list = mysql_query("select badge from tbl_badge where sub_model_sk = {$row['tbl_sub_model.sub_model_sk']}");
            $badge_str='';
            while ($badge_result = mysql_fetch_array($badge_result_list)) {
                $badge_str.=$badge_result;
            }
            echo $row['tbl_sub_model.sub_model_sk'];  //<<<<<point B
            echo "<div class=\"top\" rel=\"{$div_count_id}\">{$row['manufacturer_name']} {$row['model_name']} {$badge_str}</div>";  //<<<<<point A
            echo "<div class=\"mid\" id=\"mid{$div_count_id}\" style=\"display: none;\">";
            echo $row['tbl_sub_model.sub_model_sk'];
            echo "</div>";

            $div_count_id++;
        }

use print_r($row); to see what rows are available in your query, then you know what key to use to get the info you want.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM