目前,当我在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:"'.htmlspecialchars($rowresult['title']).'"'."},";
}
echo ']">';
输出如下:
<input type="text" style="margin: 0 auto;" data-provide="typeahead" data-items="4" data-source="[,{value:"2010-11 Graf Intern"},{value:"2nd Year Finance Explorer, Mizani & L'Oreal Technique"},{value:"A&R Intern"},{value:"Account Executive"},{value:"Account Manager"},{value:"Account Service Representative"},{value:"Account Strategist"},{value:"Accountant"},{value:"Accounting Intern"},{value:"Accounting Intern/Analyst"},{value:"Accounts payable"},{value:"Acquisition Marketing Intern"},{value:"Acquisitions Associate"},{value:"Acting Manager"},{value:"Acting Software Manager"},{value:"Administrator"},{value:"Admissions Ambassador"},]">
不幸的是,它只显示了它能够找到的每个值的第一个字符(值是bootstrap的默认值。)
编辑:
问题围绕着格式化结果,实际上,正在发生的事情是Javascript试图引用一个不存在的数组,所以它采用了元素[0],它是第一个字符。
答案 0 :(得分: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; ?>