PHP 变量 - 乘以页面 [英] PHP Variable - Multiply pages
问题描述
我有一个functions.php 页面,我已经包含在我所有其他的php 页面中.我想要的是我的functions.php页面中的一个函数,我可以在所有其他页面中使用.
I have a functions.php page, I have included in ALL my other php pages. What I want is a function in my functions.php page, I can use in all the other pages.
我已经试过了:
function getSetting()
{
$r=mysql_query("SELECT * FROM settings");
if(mysql_num_rows($r) == 0)
return false;
else
$sdata=mysql_fetch_assoc($r);
return $sdata;
}
我想要的东西,我想从下图中名称旁边的行中获取数据:http://awesomescreenshot.com/0bci8x472
The thing I want to, I want to get the data from the row next to the name in the following picture: http://awesomescreenshot.com/0bci8x472
示例:
如果我写$sdata['sitename'],我希望它输出ptcify"
If I write $sdata['sitename'], I want it to output "ptcify"
谢谢!
推荐答案
尝试将 mysql_fetch_array() 与 MYSQL_ASSOC 结合使用,如本链接中所述http://www.php.net/manual/en/function.mysql-fetch-array.php.
Try using mysql_fetch_array() with MYSQL_ASSOC as documented at this link http://www.php.net/manual/en/function.mysql-fetch-array.php.
你可以做很多事情来进一步改进你的代码实现,即 OOP,使用更好的数据库抽象库(甚至切换到 PHP_MYSQL 的 PDO insted 是一种改进),但这应该直接起作用.
There are a lot of things you could do to further improve your code implementation i.e OOP, using better database abstraction libraries(even switching to PDO insted of PHP_MYSQL is an improvement), but this should work straight of the bat.
这篇关于PHP 变量 - 乘以页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!