简体   繁体   中英

Create and compare array for results

Learning curve question. I have searched and the answers elude me. How can I take a basic result such as $row->product_id which returns a total of $limit items and turn it into an array that can then be used in another query to get more results.

    $db->setQuery( $query );
    $rows = $db->loadObjectList();  
foreach($rows as $row){
        echo '<div>' . $row->product_id . '</a></div>';
        }

This gets me the results to echo but I need to use them again in another query.

$query="select my_colum from my_table where myItem_Array_results LIMIT 

Please help.

What exactly are you trying to achieve? Do you want to use results of a SELECT in another query?
Than you should do the whole operation in MySQL. Read about JOINs . Not only is it more clear and logical, but also much faster.

SELECT `id`, `name` FROM `products`
LEFT JOIN `my_table` ON `my_table`.`my_column` = `products`.`id`

My php is rusty but try something like this:

    $db->setQuery( $query );
    $product_ids = array();
    $rows = $db->loadObjectList();  
    foreach($rows as $row){
        $product_ids[] = $row->product_id;
        echo '<div>' . $row->product_id . '</a></div>';
    }

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