0

因此,我从 sql 查询创建了一个动态链接列表。这一切都很好,但是当点击链接时,我想通过 Get/Post 变量将链接的字符串值传递到搜索栏中。我可以让这一切正常工作,但由于某种原因,只有字符串值的第一个字被发送。例如,单击“This is the Link”链接只会将“This”传递到搜索栏。我环顾四周,感觉它与 '" 位置有关。

$num=1;
                if( $row_cnt = $print->num_rows >= 1 ) {
                    while( $arr = $print->fetch_array(MYSQLI_ASSOC)) {

                        print( "<tr>\r\n" );
                        foreach( $arr as $key=>$value) {
                            /*These statements ensure author is printed on one line*/
                            if($num == 1)
                            {

                            print( "<td><a href =".$rootPath."search/master_page_search.php?key='".$value."' >".$value."</a> </td>\r\n" );
                            $num=2;

                            }
                            else
                            {
                                print( "</br><td><a href =".$rootPath."search/master_page_search.php?key=".$value." >".$value."</a><br/> </td>\r\n" );/*---These are the lines the value is being sent from It is printed correctly but $value only sends the first word in the $GET_['key']*/
                            $num=1;
                            }

                        }

                        print( "</tr>\r\n " );

然后,PHP 通过将 $_GET['key] 放入搜索栏值,将值放入搜索栏。

if(isset($_GET['key']))
{
    echo $_GET["key"];
}

链接正确显示整个字符串,但是该值仅包含一个单词值...

4

1 回答 1

0

使它起作用的另一种方法是将 $value 包围在 '' 和 "" ej 之间:

echo "<option value=" . "'$row[1]'" . ">" . $row[1] . "</option>";

                              OR

echo '<option value=' . "'$row[1]'" . '>' . $row[1] . '</option>';

这一行在选择器内部显示字符串,例如“Hello World”并发送“'$row[1]'”,注意双对“''”,在两种情况下都是相同的。

于 2013-11-03T13:31:04.547 回答