mike182uk
03-04-2010, 02:11 PM
is there any reason why this wouldnt work? because i cant get it to work?
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;
}
<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
$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.
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;
}
<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
$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.