简体   繁体   English

PHP变量被切断了<option>

[英]PHP Variable being cut off in <option>

while ($row = sqlite_fetch_array($result))
{
$category = $row[0];
    echo "<option value=". $category .">". $category ."</option>\n";

} 

Ok so basically, $category is a string like : Java Network Programming, and in the 'VALUE' part it only passes through "Java", where as in the second part, it passes through the whole string? 好吧基本上,$ category是一个字符串,如:Java网络编程,在'VALUE'部分,它只通过“Java”,在第二部分,它通过整个字符串?

Any reason why, as this is kind of crucial. 任何理由,因为这是至关重要的。 I have tried : 我努力了 :

<option value=$category>

And still no luck, I just don't see why it works with one variable and not the other? 仍然没有运气,我只是不明白为什么它适用于一个变量而不是另一个?

引用你的属性,并通过htmlentities($value, ENT_QUOTES)对它们进行编码,以防它们包含内部引号。

echo "<option value='". htmlentities($category, ENT_QUOTES) ."'>". $category ."</option>\n";

It looks like a missing quotes issue to me: 对我来说,它看起来像一个缺失的引号问题:

while ($row = sqlite_fetch_array($result))
{
    $category = $row[0];
    echo '<option value="'. $category .'">'. $category ."</option>\n";
} 

您需要引用HTML属性。

echo "<option value='". $category ."'>". $category ."</option>\n";

I'm not sure why this is happening bu if you try this it should work 我不知道为什么会发生这种情况,如果你试试这应该有效

echo "<option value='". $category ."'>". $category ."</option>\n";

Just enclose the $category in '' as I've done. 就像我一样把'$ category括在''中。

Hope this helps 希望这可以帮助

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

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