zero118 Posted December 18, 2008 Share Posted December 18, 2008 Greetings. I am attempting to get familiar with Object Oriented Code but I cannot seem to grasp how to merge two tables with it. Here is my code (ask if you need to see the functions but I think you can gather how they work). Basically, I want the 'cstmr' field of the `serial` database table to find the Company Name in the `customer` database table for the corresponding ID. So instead of showing "128" it shows "General Motors" (just an example, we don't have the money to bailout GM). Thanks! <?php require_once ( '../settings.php' ); $login->checkLogin ( 1 ); include ( '../lib/Pagination.php' ); $login->add_user_groups (); $pagination = new Pagination(); $pagination->start = ( @$_GET['start'] ) ? $_GET['start'] : '0'; $pagination->filePath = APPLICATION_URL . 'admin/admin_serials.php'; $pagination->select_what = '*'; $pagination->the_table = '`' . DBPREFIX . 'serial`'; $pagination->add_query = ' ORDER BY `ID` ASC'; $query = $pagination->getQuery ( TRUE ); $paginate = $pagination->paginate(); ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title><?= $login->design->get_page_title ( 'admin' ) ?></title> <?= $login->design->get_page_css () ?> <?= $login->design->get_page_js ( 'admin' ) ?> <script type="text/JavaScript"> <!-- function MM_jumpMenu(targ,selObj,restore){ //v3.0 eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'"); if (restore) selObj.selectedIndex=0; } //--> </script> </head> <body> <div id="top"> <?= $login->design->setMenu () ?> <div class="content"> <h1><?= $login->functions->Lang ( 'manage_serials' ) ?></h1> <?= $login->design->get_admin_menu () ?> <?= $login->message ?> <TABLE border="0" cellpadding="4" cellspacing="3" width="98%"> <caption><?= $login->functions->Lang ( 'manage_serials' ) ?></caption> <thead> <tr> <th width="20"> </th> <th><?= $login->functions->Lang ( 'hserial_num' ) ?></th> <th><?= $login->functions->Lang ( 'hcust' ) ?></th> <th><?= $login->functions->Lang ( 'hpart_num' ) ?></th> <th><?= $login->functions->Lang ( 'hstatus' ) ?></th> </tr> </thead> <?php $nr = 1; if ( $login->db->RecordCount ( $query ) > 0 ) { $groups = $login->db->get_results ( $query ); foreach ( $groups as $row ): $row_class = ( $nr % 2 ) ? '' : ' class="alt"'; ?> <tr<?= $row_class ?>> <td><?= $nr ?></td> <td class="lft"><?= $row->serial ?></td> <td class="lft"><?= $row->cstmr ?></td> <td class="lft"><?= $row->fvprt ?></td> <td class="lft"><?php if ( $row->status == '1' ) { echo "<img src='" . APPLICATION_URL . "images/icons/tick.gif'"; } else { echo "<img src='" . APPLICATION_URL . "images/icons/tickfail.gif'"; } ?></td> </tr> <?php $nr++; endforeach; } else { ?> <tr> <td colspan="4"><?= $login->functions->Lang ( 'no_groups' ) ?></td> </tr> <? } ?> </table> <?= $paginate ?> <div class="clear"></div> </div> <!-- FOOTER --> <?= $login->design->setFooter( ) ?> Link to comment https://forums.phpfreaks.com/topic/137593-solved-ooc-merge-2-tables-in-single-query/ Share on other sites More sharing options...
phpian Posted December 18, 2008 Share Posted December 18, 2008 i think you might be able to use something like this: <?php $pagination->select_what = DBPREFIX.'serial.*, '.DBPREFIX.'customer.customername '; $pagination->the_table = DBPREFIX . 'serial left join ' . DBPREFIX . 'customer on ' . DBPREFIX . 'serial.customerid = ' . DBPREFIX . 'customer.id '; $pagination->add_query = ' ORDER BY `ID` ASC'; ?> Link to comment https://forums.phpfreaks.com/topic/137593-solved-ooc-merge-2-tables-in-single-query/#findComment-719180 Share on other sites More sharing options...
zero118 Posted December 18, 2008 Author Share Posted December 18, 2008 Excellent! Thanks! Works like a charm. I was never good at using JOIN but this will help a lot. Link to comment https://forums.phpfreaks.com/topic/137593-solved-ooc-merge-2-tables-in-single-query/#findComment-719200 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.