Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/84.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 sql使用回调_Php_Sql_Callback - Fatal编程技术网

完成-php sql使用回调

完成-php sql使用回调,php,sql,callback,Php,Sql,Callback,编辑: 问题如下: $pageTitle不能在函数外部使用 以下是我到目前为止得到的信息: function getMetaData($table, $rows){ echo $table; echo $rows; $selectTitle = "select * from $table"; $getTitle = mysql_query($selectTitle); while ($showTitle = mysql_fetch_assoc($g

编辑:

问题如下:

$pageTitle不能在函数外部使用

以下是我到目前为止得到的信息:

function getMetaData($table, $rows){
    echo $table;
    echo $rows;
    $selectTitle =  "select * from $table";
    $getTitle    = mysql_query($selectTitle);
    while ($showTitle = mysql_fetch_assoc($getTitle)){
        $pageTitle = $showTitle[$rows];
    }
}

getMetaData('metadata', 'Pagetitle');
我的输出

<?php echo $pageTitle ?>
->这是未定义的

谢谢

试试mysql\u free\u

mysql_free_result将释放与结果关联的所有内存

根据您的编辑,请尝试以下操作:

$pageTitle = getMetaData('metadata', 'Pagetitle');
echo $pageTitle;
您应该首先初始化变量$pageTitle,如下所示:

function getMetaData($table, $rows){
    echo $table;
    echo $rows;
    $selectTitle =  "select * from $table";
    $getTitle    = mysql_query($selectTitle);
    $pageTitle='';
    while ($showTitle = mysql_fetch_assoc($getTitle)){
        $pageTitle = $showTitle[$rows];
    }
    return $pageTitle; // returning the variable will work here
}
echo getMetaData('metadata', 'Pagetitle');

函数既不返回任何值,也不打印任何值。根据您的编辑使用


在函数开头和使用变量之前

当他们正确地回应时,他们是不高兴的。?是的,这只是为了测试这项工作:$pageTitle=$showTitle['pageTitle'];在while循环中?你没有返回任何value@DevZer0你能解释一下吗?也不行;如果没有回调,它可以正常工作,所以我认为这不是因为初始化了变量。上面的操作将正常工作,您需要检查数据库表。您的数据库表中是否有任何数据,您还需要在此处使用LIMIT。@Christopha,您期望的是什么?如果没有返回值,您期望回调或它如何工作?有什么奇迹发生了吗?我想这里的每个人都在玩猜谜游戏。在OP的评论之后,你可能是赢家。让我们等待OP的代码。我没有收到回调,但我注意到了一个范围问题,我想我现在可以解决这个问题了。是的,这是正确的!来自javascript,我忘记了这些东西,谢谢!
function getMetaData($table, $rows){
    echo $table;
    echo $rows;
    $selectTitle =  "select * from $table";
    $getTitle    = mysql_query($selectTitle);
    $pageTitle='';
    while ($showTitle = mysql_fetch_assoc($getTitle)){
        $pageTitle = $showTitle[$rows];
    }
    return $pageTitle; // returning the variable will work here
}
echo getMetaData('metadata', 'Pagetitle');
global $pageTitle;