php - Two DB::getIntance() running on the same page -


hi want know if possible have different queries db::getinstance() value in query @ same time on same page? , practice do? if not can show me best practice?

i have update page (update.php) on update page have querying part id in database.

this works fine.

$id = $_get['id'];    $agent = db::getinstance()->get('agent', array('id', '=', $id)); 

below of update.php page drop down field querying part of table data. instance director table user belong.

but not work.

            $directors = $dbh->query("select * directors");                echo "<select name='director' id='director'>                     <option value=''>".$agent->results()[0]->agent_name."</option>";               foreach($directors->results() $director){                 echo "<option value='$director->name'>".$director->name."</option>";              }               echo "</select>"; 

thank you

although it's impossible answer question directly, there directions

  1. don't use getinstance() method. makes no sense nowadays.
  2. don't use get() method. never had sense @ all.

if want singleton approach, create wrapper being pdo instance. may find example here.

and able run number of queries of type:

$sql   = 'select * agent id = ?'; $agent = db::prepare($sql)->execute([$_get['id']])->fetch();  $directors = db::query("select * directors")->fetchall(); 

it seems mistaken in using query results

echo "<select name='director' id='director'>     <option value=''>$agent->agent_name</option>";  foreach($directors $director){    echo "<option value='$director->name'>$director->name</option>"; } echo "</select>"; 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -