如何“附加”使用 URL 的函数变量以及有关数组的问题

发布于 2024-11-17 00:40:47 字数 1102 浏览 0 评论 0原文

第一个问题是如何使用 URL 运行函数,我有以下函数:

function do_curl($start_index,$stop_index){

    // Do query here to get all pages with ids between start index and stop index

    $query = "SELECT * FROM xxx WHERE xxx >= $start_index and xxx <= $stop_index";

现在,当我尝试执行curl.php?start_index=0&stop_index=2 时,这不起作用,但是当我删除函数和 WHERE 时idnum = 1 它正在工作。

现在第二个问题是如何将行中的所有字段“编译”为数组?我有当前的代码:

    $query = "SELECT * FROM fanpages";
    $result = mysql_query($query) or die(mysql_error());
    while ($row = mysql_fetch_array($result))
{
    $fanpages_query = '\'http://graph.facebook.com/'.$row['page_id'].'\', ';
    echo $fanpages_query;    
}


$fanpages = array($fanpages_query);
$fanpages_count = count($fanpages);
echo $fanpages_count;

echo $fanpages_query;返回

'http://graph.facebook.com/AAAAAA', 'http://graph.facebook.com/BBBBBBB', 'http://graph.facebook.com/CCCCCCCC',

(我不知道如何以不同的方式执行此操作,而且当我以这种方式执行此操作时,我无法删除将返回 PHP 错误的最后一个逗号。)

echo $fanpages_count;返回 1,就像你可以看到的那样,我那里有 3。

预先感谢各位!

The first question is how to run a function using the URL, I have the following function:

function do_curl($start_index,$stop_index){

    // Do query here to get all pages with ids between start index and stop index

    $query = "SELECT * FROM xxx WHERE xxx >= $start_index and xxx <= $stop_index";

Now when I'm trying to do curl.php?start_index=0&stop_index=2 this is not working but when i delete the function and WHERE idnum = 1 it is working.

Now the second question is how 'compile' all the fields from the rows to arrays? I have the current code:

    $query = "SELECT * FROM fanpages";
    $result = mysql_query($query) or die(mysql_error());
    while ($row = mysql_fetch_array($result))
{
    $fanpages_query = '\'http://graph.facebook.com/'.$row['page_id'].'\', ';
    echo $fanpages_query;    
}


$fanpages = array($fanpages_query);
$fanpages_count = count($fanpages);
echo $fanpages_count;

echo $fanpages_query; returning

'http://graph.facebook.com/AAAAAA', 'http://graph.facebook.com/BBBBBBB', 'http://graph.facebook.com/CCCCCCCC',

(I don't have an idea how to do it in a different way, also when im doing it in such a way i can't delete the final comma which will return PHP-error.)

echo $fanpages_count; returns 1 and like you can see i have 3 there.

Thanks in advance guys!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

惜醉颜 2024-11-24 00:40:47

进行函数调用来执行查询

function do_curl($start_index, $stop_index){
    ...
}

$fanpages = do_curl($_GET['start_index'], $_GET['stop_index']);

对于第二个问题,您可以使用数组和 implode 函数插入逗号:

while ($row = mysql_fetch_array($result))
{
    $fanpages_query[] = 'http://graph.facebook.com/'.$row['page_id'];  
}
return $fanpages_query;

然后使用 implode 打印它们:

echo implode(',', $fanpages);

整个代码:

function do_curl($start_index = 0, $stop_index = null) {

    $queryIfThereIsNoStartIndex = '';
    $queryIFThereIsNoStopIndex = '';
    $queryIfBothStartAndStopIndexAreMissing = '';

    $result = mysql_query($query) or die(mysql_error());
    while ($row = mysql_fetch_array($result))
    {
        $fanpages_query[] = 'http://graph.facebook.com/'.$row['page_id'];  
    }
    return $fanpages_query;
}

$fanpages = do_curl($_GET['start_index'], $_GET['stop_index']);
$fanpages_count = count($fanpages);
echo implode(',', $fanpages);

并且您应该完全使用 mysql_escape_string 用于转义添加到查询中的值。

Do a function call to do the query

function do_curl($start_index, $stop_index){
    ...
}

$fanpages = do_curl($_GET['start_index'], $_GET['stop_index']);

For your second question, you can use arrays and the implode function to insert commas:

while ($row = mysql_fetch_array($result))
{
    $fanpages_query[] = 'http://graph.facebook.com/'.$row['page_id'];  
}
return $fanpages_query;

Then use implode to print them out:

echo implode(',', $fanpages);

The whole code:

function do_curl($start_index = 0, $stop_index = null) {

    $queryIfThereIsNoStartIndex = '';
    $queryIFThereIsNoStopIndex = '';
    $queryIfBothStartAndStopIndexAreMissing = '';

    $result = mysql_query($query) or die(mysql_error());
    while ($row = mysql_fetch_array($result))
    {
        $fanpages_query[] = 'http://graph.facebook.com/'.$row['page_id'];  
    }
    return $fanpages_query;
}

$fanpages = do_curl($_GET['start_index'], $_GET['stop_index']);
$fanpages_count = count($fanpages);
echo implode(',', $fanpages);

And you should totally use mysql_escape_string for escaping the values you add to the query.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文