1

目前,当我在 php 中创建它时,我的预输入看起来像这样

    echo '<input type="text" style="margin: 0 auto;" data-provide="typeahead" data-items="4" data-source="[,';
while ( $rowresult = mysql_fetch_assoc($titlequery) ) {
      echo '{value:&quot;'.htmlspecialchars($rowresult['title']).'&quot;'."},";
}
      echo ']">';

它输出如下:

  <input type="text" style="margin: 0 auto;" data-provide="typeahead" data-items="4" data-source="[,{value:&quot;2010-11 Graf Intern&quot;},{value:&quot;2nd Year Finance Explorer, Mizani &amp; L'Oreal Technique&quot;},{value:&quot;A&amp;R Intern&quot;},{value:&quot;Account Executive&quot;},{value:&quot;Account Manager&quot;},{value:&quot;Account Service Representative&quot;},{value:&quot;Account Strategist&quot;},{value:&quot;Accountant&quot;},{value:&quot;Accounting Intern&quot;},{value:&quot;Accounting Intern/Analyst&quot;},{value:&quot;Accounts payable&quot;},{value:&quot;Acquisition Marketing Intern&quot;},{value:&quot;Acquisitions Associate&quot;},{value:&quot;Acting Manager&quot;},{value:&quot;Acting Software Manager&quot;},{value:&quot;Administrator&quot;},{value:&quot;Admissions Ambassador&quot;},]">

不幸的是,它只显示了它能够找到的每个值的第一个字符(值是引导程序的默认值。)

编辑:

问题围绕格式化结果展开,实际上,发生的事情是 Javascript 试图引用一个不存在的数组,因此它采用了元素 [0],它是它的第一个字符。

4

1 回答 1

1

尝试使用此解决方案:

<?
$chars = array(":", "'", "?", '"', "/");
while ( $rowresult = mysql_fetch_assoc($titlequery) ) {
      $Str = $rowresult['title'];
      $Data[] = str_replace($vowels, "", $Str);
}
if(isset($Data)): ?>    
<input type="text" style="margin: 0 auto;" data-provide="typeahead" data-items="4" data-source="[<?= implode(',', $Data) ?>]">
<?php endif; ?>
于 2012-10-14T19:43:24.620 回答