is there any reason why this wouldnt work? because i cant get it to work?
PHP Code:
function getAttrVals($sql){
$result = $db_myDB->query($sql);
while ($row = $result->fetch_object() ){
$html .= "<option value='". $row->id ."'>". $row->name ."</option>";
}
$result->close();
return $html;
}
Code:
<select>
<?php echo getAttrVals("SELECT * FROM products"); ?>
</select>
<select>
<?php echo getAttrVals("SELECT * FROM products2"); ?>
</select>
there is a db table called products and products 2, and there are columns call id and name.
i init the connection like so
PHP Code:
$db["myDB"]["host"] = "localhost";
$db["myDB"]["user"] = "root";
$db["myDB"]["pass"] = "xxxxxxxx";
$db["myDB"]["db"] = "myDB";
$db_myDB = new mysqli($db["myDB"]["host"],$db["myDB"]["user"],$db["myDB"]["pass"],$db["myDB"]["db"]);
for some reason it does not return anything when i run the page.