How to fetch data values from 2 tables at a time?

I have to access all values from two tables by using query.

I have used the below code. But it displays the second data table values only.

 

$aRules = $GLOBALS['MySQL']->getAll("SELECT `me_art_simple`.`id` , `me_art_simple`.`Title`,`me_art_conversation`.`id` , `me_art_conversation`.`Title` FROM `me_art_simple` , `me_art_conversation` where `me_art_simple`.`OwnerId` = `me_art_conversation`.`OwnerId`");

 

         $aVars = array (

'bx_repeat:items' => $aRules,

 

);

        echo $this->_oTemplate->parseHtmlByName('all_article', $aVars);

 

Then here I have to check the 'OwnerId' must be the LoggedID.

Anyone can help me ASAP.

Thanks in Advance.

Quote · 31 Aug 2013

You have the same field names in both tables, therefore you have to use aliases for one of the table. See below for revised query. 

$aRules = $GLOBALS['MySQL']->getAll("SELECT `me_art_simple`.`id` , `me_art_simple`.`Title`,`me_art_conversation`.`id` as `conv_id`, `me_art_conversation`.`Title` as `ConvTitle` FROM `me_art_simple` , `me_art_conversation` where `me_art_simple`.`OwnerId` = `me_art_conversation`.`OwnerId`");

Paypal email is jeromemingo@gmail.com - http://www.boonex.com/market/posts/modzzz
Quote · 31 Aug 2013

Thanks for reply Modzzz.

I have used the query now which one is given by you.

But now it displays all the value of First Table only Frown

Quote · 31 Aug 2013

Paste the content of all_article.html so we can see what is happening in there. 

Paypal email is jeromemingo@gmail.com - http://www.boonex.com/market/posts/modzzz
Quote · 31 Aug 2013

Herewith I have paste the content all_article.html

 

<div style="text-align:center;">
    <bx_repeat:items>
    <table width="700px">
        <div id="__id__" style="text-align: center;  width: 536px;">

             <input id="__id__" type="checkbox" class="art_check" name="check" value="__id__"/>

      </div>
        <div id="__Title__" style="text-align: center;  width: 536px"><a href="m/lessons/article">__Title__</a></div>
        <tr><th><img src="./modules/boonex/ads/templates/base/images/no-image-thumb.png" style="width: 100px; height: 100px"> Created by <a href='__OwnerName__'>  __OwnerName__</a></th></tr><tr><th>

       <a href='__OwnerName__'>INVITE</a></td></th>
        </table>
   </bx_repeat:items>
</div>

Quote · 2 Sep 2013

Your logic is wrong. If each table has different Titles etc. that you need to display, you cannot join them in the manner that you did. You will most likely have to use two different queries and then concatenate the output. See example below :

 

$aRules = $GLOBALS['MySQL']->getAll("SELECT `id` , `Title`, `OwnerName` FROM `me_art_simple`");
 
$aVars = array (
     'bx_repeat:items' => $aRules 
);

$sOutputA = $this->_oTemplate->parseHtmlByName('all_article', $aVars);


$aRules = $GLOBALS['MySQL']->getAll("SELECT `id` , `Title`, `OwnerName` FROM `me_art_conversation`");
 
$aVars = array (
     'bx_repeat:items' => $aRules 
);

$sOutputB = $this->_oTemplate->parseHtmlByName('all_article', $aVars);


echo $sOutputA . $sOutputB;

Paypal email is jeromemingo@gmail.com - http://www.boonex.com/market/posts/modzzz
Quote · 2 Sep 2013

Thanks Modzzz Laughing

Quote · 2 Sep 2013
 
 
Below is the legacy version of the Boonex site, maintained for Dolphin.Pro 7.x support.
The new Dolphin solution is powered by UNA Community Management System.