gpt4 book ai didi

php - PHP 中的 VB if 语句

转载 作者:行者123 更新时间:2023-11-29 02:34:15 26 4
gpt4 key购买 nike

我需要帮助将以下 Visual Basic 语句转换为 PHP 等效语句:

If Not IsNumeric(siteid) Then

dr = GetDataReader("SELECT siteid FROM nwsite WITH (NOLOCK) WHERE mac_address = '" & siteid & "'")

If Not dr.HasRows Then

Response.Write(sep & siteid & "=" & siteid)

sep = ","

End If

If Not dr Is Nothing Then

dr.Close()

End If

End If

我最需要有关 If 语句的帮助。

谢谢

最佳答案

参见 here for the docs you need to check , 还有 here

看起来像你also need to learn how to use mySQL in PHP

代码相对简单,在其最简单的步骤中 - 几乎是一行一行地帮助您了解向 PHP 的转换(有更好的实现):

$siteid = 1; // where 1 is the value of siteid, PHP vars are prefixed with '$'


// you also could do
// if(!isset($siteid){
// if(!$siteid){

if(!is_numeric($siteid){
// there is no site ID, so get it from the DB

// Make a MySQL Connection
mysql_connect("localhost", "user", "password") or die(mysql_error());
mysql_select_db("dbname") or die(mysql_error());

// Run your query
$result = mysql_query("SELECT siteid FROM nwsite WITH (NOLOCK) WHERE mac_address = ".$siteid)
or die(mysql_error());

if(mysql_num_rows($result)>0){
// rows returned
//assuming only one row is returned, with your siteid value
$row = mysql_fetch_array( $result );
$siteid=$row['siteid'];
}else{
// no rows returned
// do something
}

}else{
// $siteid is already a valid value
}

关于php - PHP 中的 VB if 语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7805692/

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