如何使用PHP从我的数据库中获取特定值 [英] How to get a specific value from my database with PHP
问题描述
我觉得这是一个易于解决的问题,但我找不到答案.我正在尝试从数据库中获取特定值,然后将其打印到屏幕上,但是我不断收到以下错误:
I have the feeling this is an easy to fix problem, but I can't find the answer. I'm trying to get a specific value from my database and then print it to the screen but I keep getting the following error:
Object of class mysqli_result could not be converted to string
我很确定这是因为我要的是整行而不是值.我只是不确定如何解决它,我已经尝试了一些选项,但是没有任何效果.我的代码:
I'm pretty sure it's because i'm requesting an entire row instead of a value. I'm just not sure how to fix it, i've tried a few options but nothing works. My code:
<?php
$host = 'localhost';
$user = 'root';
$pass = '';
$db = 'mydatabase';
$connection = new mysqli ($host, $user, $pass, $db) or die ("Databse connection failed");
$sql = "SELECT waitlist_text FROM texts";
$waitlist_text = $connection->query($sql);
echo $waitlist_text
?>
数据库表称为文本",具有两列:"id","waitlist_text".我想要ID为1的waitlist_text列下的文本thats
The database table is called 'texts' and has 2 columns: 'id' 'waitlist_text'. I would like the text thats under column waitlist_text on id 1
推荐答案
<?php
$host = 'localhost';
$user = 'root';
$pass = '';
$db = 'mydatabase';
$connection = new mysqli ($host, $user, $pass, $db) or die ("Databse connection failed");
$sql = "SELECT waitlist_text FROM texts";
$waitlist_text = $connection->query($sql);
while($row = $waitlist_text->fetch_assoc()) {
echo $row["waitlist_text"];
}
?>
这篇关于如何使用PHP从我的数据库中获取特定值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!