简体   繁体   English

如何通过参数将多字符串变量传递给php

[英]How do I pass a multistring variable into php through a parameter

How do I send in a "multi"-string variable(looking like this: 1,2.3,4) into a php through a parameter which goes through an url. 我如何通过一个通过URL的参数将“多”字符串变量(如下所示:1,2.3,4)发送到php中。

Lets say some of the php that is connected to the mysql server looks something like this 可以说连接到mysql服务器的一些php看起来像这样

`$id_ = $_GET['id'];`
`$q=mysql_query("SELECT * FROM brain WHERE braincell_id in ('$id_');`

And the variable that goes into it is: id = 1,2,3,4 而其中的变量是:id = 1,2,3,4

How can I make this work? 我该如何进行这项工作?

What I am using currently and that does work: 我目前正在使用的并且确实有效:

$q=mysql_query("SELECT * FROM brain WHERE braincell_id in ("$_GET['id']");

EDIT. 编辑。 Sorry it's me being stupid, it is way to late for me to be doing this stuff..... I missed a parentheses please remove this post. 对不起,这是我的愚蠢,这对我来说是迟到的事情.....我错过了一个括号,请删除这篇文章。

Pass $q , your result resource. 传递$q ,您的结果资源。 It references all the data returned from MySQL, and you can use the usual mysql_* functions on it (eg. mysql_fetch_array() ). 它引用了从MySQL返回的所有数据,您可以在其上使用常规的mysql_*函数(例如mysql_fetch_array() )。

Alternatively, call mysql_fetch_array() (or similar) and pass the resultant array to your function. 或者,调用mysql_fetch_array() (或类似方法)并将结果数组传递给函数。

The only solution that I know that will work out of the box is to pass each element of array as an separate parameter. 我知道可以使用的唯一解决方案是将数组的每个元素作为单独的参数传递。

Here is my example: 这是我的示例:

get.php: get.php:

    $arr = $_GET['id'];

    echo '<ul>';
    foreach($arr as $id)
    {
        echo "<li>{$id}</li>";
    }
    echo '</ul>';

URL: 网址:

get.php?id[]=1&id[]=2&id[]=3

Also you can pass key for each element: 您还可以为每个元素传递密钥:

get.php?id[0]=1&id[1]=2&id[2]=3

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM