如何“附加”使用 URL 的函数变量以及有关数组的问题
第一个问题是如何使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
进行函数调用来执行查询
对于第二个问题,您可以使用数组和 implode 函数插入逗号:
然后使用 implode 打印它们:
整个代码:
并且您应该完全使用 mysql_escape_string 用于转义添加到查询中的值。
Do a function call to do the query
For your second question, you can use arrays and the implode function to insert commas:
Then use implode to print them out:
The whole code:
And you should totally use mysql_escape_string for escaping the values you add to the query.