Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试从只有一行和一列的数据库表创建一个 PHP 变量。所以基本上,我正在尝试使用数据库在多个页面中传递信息。这可能吗?我有一个名为的表name,其上的一列也称为name. 我只有一行,我想选择那个唯一字段的值并为其分配一个变量。我该怎么做呢?谢谢!
name
编辑:我试过了:
$name = mysql_query("SELECT * FROM name ORDER BY RAND() LIMIT 0,1"); var_dump($name);
但它返回null。
null
$result = mysql_query("SELECT * FROM lv1 ORDER BY RAND() LIMIT 0,1"); //You get only 1 row $name = ($result && mysqli_num_rows($result) == 1) ? mysql_fetch_assoc($result) : null ; var_dump($name) ;