Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/91.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 根据函数获取mysql表列的值_Php_Html_Mysql - Fatal编程技术网

Php 根据函数获取mysql表列的值

Php 根据函数获取mysql表列的值,php,html,mysql,Php,Html,Mysql,我有一个函数,求你了。get_me返回页面的slug 我还有mysql表,其中包含以下数据,分别有slug列和block\u to\u echo列: ---------------------------------------- | slug | block_to_echo | ---------------------------------------- | home | <b>Welcome</b> to home! |

我有一个函数,求你了。get_me返回页面的slug

我还有mysql表,其中包含以下数据,分别有slug列和block\u to\u echo列:

----------------------------------------
|   slug    |       block_to_echo      |
----------------------------------------
| home      |  <b>Welcome</b> to home! |
| about     |  You're in about page!   |
| services  |  Services, <i>yes</i>!   |
----------------------------------------
现在,根据get_me,我想得到block_to_echo的值,是的,echo它

例如,如果get_me返回服务,我想回显服务,是的

已经定义了get_me的功能。我只需要知道如何根据get_me获得block_to_echo


显然,我不知道如何编写此代码,因此如果我无法提供代码,我很抱歉。

但您知道其中一些,对吗?您的意思是$typ=get\me;mysqli_查询$dbh,从表'where slug='$typ';中选择block_to_echo然后获取并打印结果?是@flaschenpost。。。。。类似这样的东西…给了我这个错误:警告:mysqli\u query期望参数1是mysqli,string打开错误报告,并通过放置error\u reportingE\u ALL确保您已成功连接到mysql数据库;在打开php标记之后。如果它无法连接,你应该会出错。。连接到数据库没有问题。我只收到mysqli_查询错误..对我发布的代码进行了更新。复制并粘贴它完全符合我的要求,只需填写数据库用户名、密码等,以匹配您的密码是的,这有效。。。谢谢你的耐心
<?php    

$database_host='database host goes here. (use localhost if on the same machine)';
$username='database username goes here';
$password='database password goes here';
$database_name='enter the name of your database here';


$database=mysqli_connect($database_host,$username,$password,$database_name)or die("Error " . mysqli_error($database));
$query='SELECT block_to_echo from table where slug='."'".get_me()."'";
$result=mysqli_query($database,$query);
if(!$result){
//Error handling code here for issue with query
}else{
   //Everything went ok
   if(mysqli_num_rows($result) < 1){
      //There are no results for the value returned from get_me();
   }else{
      //We know we have at least one row. I'll assume it will only have a single row
      $row=mysqli_fetch_assoc($result);
      echo $row['block_to_echo']; //This should print the block to echo on the screen
   }
}
?>