Skip to main content

is Is there any better code (MySql or PHP) where i canway to fetch two tabletables in one statement or query?

theThe 'Do' method is for prepared statementstatements and it returns (by fetchall()), i. I am also using two statement which is looping, is statements. Is there any better code (Sql) where i canway to fetch two tabletables in one statement or query? if no then If not, what can iI do to makeimprove 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>
            }         
  ?>

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>
            }         
  ?>

Is there any better way to fetch two tables in one statement or query?

The 'Do' method is for prepared statements and returns (by fetchall()). I am also using two looping statements. Is there any better way to fetch two tables in one statement or query? If not, what can I do to improve this code?

// '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>
            }         
  ?>
Source Link

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>
            }         
  ?>