我需要同一行中两列(cnt
、link
)的值:
$st = $db->query("select cnt, link from rolls where def = 1 limit 1");
$str = $st->fetch()['cnt'];
$link = $st->fetch()['link'];
echo $str; // this works
echo $link; // doesn't work - nothing is echoed
如何获取这两个值?
最佳答案
您可以像这样使用 fetch_assoc() :
$st = $db->query("select cnt, link from rolls where def = 1 limit 1");
$str = $st->fetch_assoc();
echo $str['cnt'].' '.$str['link '];
关于php - 获取同一行中两列的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59692231/