Skip to main content
1 of 2

is there any better code (MySql or PHP) where i can fetch two table in one statement or query?

the 'Do' method is for prepared statement and it returns (by fetchall()), i am using two statement which is looping, is there any better code (Sql) where i can fetch two table in one statement or query? if no then what can i do to make this code look better. (PHP)

// 'id' is index in 'userinfo' table and 'id' in 'election' table is a child index(foreign key)
// 'ElectionId' is also the index, but it is not connected with othertable (only 'id' is linked)   

 <?php
    $call = new world();
    $get = $call->Do("SELECT Votes, Views, id FROM election WHERE ElectionId = ?", array("electionIdUknwn"));
        foreach($get as $show)
            {
                <div>"Votes is :".$show[0]</div>
                $add = $call->Do("SELECT username FROM userinfo WHERE id = ?", array($show[2]) );
                foreach($add as $display)
                {
                    <div>"Username is :".$display[0]</div>
                }
                <div>"Views are :".$show[1]</div>
            }         
  ?>