0

我想知道是否可以在没有太多参数和字符串的情况下执行以下脚本...我认为可以删除很多内容...也许只有一个查询?

谢谢!

<?php
include("sqlvar.php");

$connection = new mysqli($host, $user, $pw, $db);
$marginidb = $connection->query("SELECT valore FROM DATIVENDITA WHERE parametro = 'margine'");
while($margine = $marginidb->fetch_object()) {
        $valoremargine = $margine->valore;
}
$connection->close();

echo $valoremargine;

$connection = new mysqli($host, $user, $pw, $db);
$ivadb = $connection->query("SELECT valore FROM DATIVENDITA WHERE parametro = 'iva'");
while($iva = $ivadb->fetch_object()) {
        $valoreiva = $iva->valore;
}
$connection->close();

echo $valoreiva;
?>
4

2 回答 2

1
<?php
include("sqlvar.php");

$connection = new mysqli($host, $user, $pw, $db);

$marginidb = $connection->query("SELECT valore FROM DATIVENDITA WHERE parametro = 'margine' limit 1");
$margine = $marginidb->fetch_object();
echo $margine->valore;

$ivadb = $connection->query("SELECT valore FROM DATIVENDITA WHERE parametro = 'iva' limit 1");
$iva = $ivadb->fetch_object();
echo $iva->valore;

$connection->close();

?>
于 2013-02-05T17:07:50.217 回答
1

这是我认为您要的内容:

<?php
include("sqlvar.php");
$result = array();
$connection = new mysqli($host, $user, $pw, $db);
$marginidb = $connection->query("SELECT valore FROM DATIVENDITA WHERE parametro = 'margine' OR parametro = 'iva'");
while($margine = $marginidb->fetch_object()) {
        array_push($result, $margine->valore);
}
$connection->close();
print_r($result);
?>

它的作用是将结果存储为一个数组,以便访问您将使用的第一个结果$result[0],第二个将是$result[1]. 您可以使用循环遍历这些结果foreach

于 2013-02-05T17:10:34.250 回答