繁体   English   中英

如何更改mysql_result($ res,0,“ url”); 到mysqli

[英]how to change mysql_result($res, 0, “url”); to mysqli

我不知道如何像过去一样使用mysqli_result。

这个可以吗? 怎么正确?

$res = mysqli_query($con,"SELECT `id`,`usrid`,`url` FROM site WHERE state = 'popup' AND creditsp >= 1 AND (cth < cph || cph=0) order by rand() limit 1");
$urll = mysqli_result($res, 0, "url");
$ownerid = mysqli_result($res, 0, "usrid");
$siteidd = mysqli_result($res, 0, "id");

PHP 5.4现在支持函数数组解引用: http : //php.net/manual/en/migration54.new-features.php

因此,为了从sql获取结果,您需要使用mysqli_fetch_assoc()函数。

用法可以在这里找到: http : //php.net/manual/en/mysqli-result.fetch-assoc.php http://www.w3schools.com/php/func_mysqli_fetch_assoc.asp

________小例子________

假设我们有一个数据库:

ID名称年龄职业
1. William 11学生
2. Uname 14学生
3. Yem 22老师

$query = "SELECT * FROM persons";
$res = mysqli_query($connection, $query);
while($row = mysqli_fetch_assoc($res));  \\returns an associative array to the row variable. You can use foreach loop as well to loop throgh the various data items.
{
echo $row["Id"] . "<br>";
echo $row["Name"] . "<br>";
echo $row["Age"] . "<br>";
echo $row["Occupation"] . "<br>";
}

在结果上使用fetch_assoc

$row = $res->fetch_assoc();
$urll = $row['url'];
$ownerid = $row['usrid'];
$siteidd = $row['id'];

如果有多个行,则:

while ($row = $res->fetch_assoc()) {
    // process $row
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM