gpt4 book ai didi

php/mysql elseif 挑战

转载 作者:行者123 更新时间:2023-11-30 22:54:19 24 4
gpt4 key购买 nike

我正在尝试两个不同的查询,它们都可以单独正常工作,但我想要一种情况,其中一个将落在 PHP 的 elseif 语句中,或者如果有人有更好的解决方案。下面是第一个和第二个声明。

第一句话

$retvval = mysql_query( $sqql);
$sqql = "SELECT `autoID`, `Name of Doctor`, `Email`, `Hospital of Practise`, `State`,
`Specialization`, `Professional Organization`, `webpage` FROM `doctor_locator`
WHERE state = '$states' AND `name of doctor` LIKE 'Dr%'";
$retvval = mysql_query( $sqql);
if(! $retvval )
{
die('Could not get data: ' . mysql_error());
}

while($row = mysql_fetch_array($retvval))
{
echo "{$row['autoID']}. "."Name of Doctor: <a href = \"{$row['webpage']}\">{$row['Name of Doctor']} </a><br>"
."Email: {$row['Email']} <br>". "Hospital of Practise: {$row['Hospital of Practise']}
<br>". "State: {$row['State']} <br>" . "Specialization: {$row['Specialization']} <br> ";
}

第二个声明

$retval = mysql_query( $sql);
$sql = "SELECT `autoID`, `Name of Doctor`, `Email`, `Hospital of Practise`, `State`,
`Specialization`, `Professional Organization`, `webpage` FROM `doctor_locator`
WHERE state = '$states' AND specialization = '$specialize' ";
$retval = mysql_query( $sql);
if(! $retval )
{
die('Could not get data: ' . mysql_error());
}

while($row = mysql_fetch_array($retval))
{
echo "{$row['autoID']}. "."Name of Doctor: <a href = \"{$row['webpage']}">{$row['Name of Doctor']} </a><br>"."Email: {$row['Email']} <br>". "Hospital of Practise:{$row['Hospital of Practise']}<br>". "State: {$row['State']} <br>" . "Specialization: {$row['Specialization']} <br> ";
}

最佳答案

这可以通过 PDO 来完成:

/* Create new connection http://php.net/manual/en/pdo.construct.php */
$pdo = new Pdo($connectionString, $user, $pass);
/* Prepare the first query */
$statement = $pdo->prepare($sqql);
/* Without actually executing it, check if there is any error */
if ($statement->errorCode()) {
/* If so, then prepare the second statement */
$statement = $pdo->prepare($sql);
}

/* Execute it. It will be the first, if it was valid or the second, if the first was not valid. */
$statement->execute();

关于php/mysql elseif 挑战,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27060872/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com