- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我购买了名为 smart suggest 的 jquery 插件,并且希望传递 json 数组作为数据而不是数组。
当前数据文件“sample-data.php”如下所示:
array('image' => 'assets/images/fruits/apple.jpg', 'description' => 'One of America\'s favorite fruits.'), 'Avocado' => array('image' => 'assets/images/fruits/avocado.jpg', 'description' => 'The avocado is a dense, evergreen tree, shedding many leaves in early spring.'), 'Banana' => array('image' => 'assets/images/fruits/banana.jpg', 'description' => 'Bananas are fast-growing herbaceous perennials arising from underground rhizomes.'), 'Gooseberry' => array('image' => 'assets/images/fruits/gooseberry.jpg', 'description' => 'Gooseberries are deciduous shrubs.'), 'Grape' => array('image' => 'assets/images/fruits/grape.jpg', 'description' => 'Grapes come in large clusters.'), 'Jackfruit' => array('image' => 'assets/images/fruits/jackfruit.jpg', 'description' => 'The jackfruit tree is handsome and stately.'), 'Mango' => array('image' => 'assets/images/fruits/mango.jpg', 'description' => 'Mango trees make handsome landscape specimens and shade trees.'), 'Papaya' => array('image' => 'assets/images/fruits/papaya.jpg', 'description' => 'The papaya is a short-lived, fast-growing, woody, large herb to 10 or 12 feet in height. It is also regarded by some as being delicious.'), 'Peach' => array('image' => 'assets/images/fruits/peach.jpg', 'description' => 'These are great in the summertime.'), 'Pear' => array('image' => 'assets/images/fruits/pear.jpg', 'description' => 'Pears are delicious fruits.'), 'Pineapple' => array('image' => 'assets/images/fruits/pineapple.jpg', 'description' => 'The pineapple plant is a herbaceous perennial, 2-1/2 to 5 ft.'), 'Rose Apple' => array('image' => 'assets/images/fruits/rose_apple.jpg', 'description' => 'The rose apple is a highly decorative evergreen large shrub.'), 'Tamarind' => array('image' => 'assets/images/fruits/tamarind.jpg', 'description' => 'The bright green, pinnate foliage is dense and feathery in appearance.'), 'White Sapote' => array('image' => 'assets/images/fruits/white_sapote.jpg', 'description' => 'The white sapote forms a medium to very large evergreen tree.'), ); $vegetables = array( 'Alfalfa' => array('image' => 'assets/images/fruits/alfalfa.jpg', 'description' => 'One cup of raw, sprouted alfalfa seeds, contains 1.32 grams of protein.'), 'Artichoke' => array('image' => 'assets/images/fruits/artichoke.jpg', 'description' => 'One medium artichoke cooked with no added salt has 3.47 grams protein.'), 'Asparagus' => array('image' => 'assets/images/fruits/asparagus.jpg', 'description' => 'Half cup (about 6 spears) cooked with no added salt contains 2.16 grams of protein.'), 'Broccoli' => array('image' => 'assets/images/fruits/broccoli.jpg', 'description' => 'Half cup of broccoli, cooked with no added salt contains 1.86 grams protein.'), 'Carrots' => array('image' => 'assets/images/fruits/carrots.jpg', 'description' => 'Half cup cooked with no added salt contains 0.59 grams protein.'), 'Celery' => array('image' => 'assets/images/fruits/celery.jpg', 'description' => 'One cup of celery, cooked, boiled, drained with no added salt has 1.25 grams protein.'), 'Corn' => array('image' => 'assets/images/fruits/corn.jpg', 'description' => 'One large ear of yellow corn, cooked with no salt contains 4.02 grams protein.'), 'Green Pepper' => array('image' => 'assets/images/fruits/green_pepper.jpg', 'description' => 'One small raw pepper contains 0.64 grams protein.'), 'Mushroom' => array('image' => 'assets/images/fruits/mushroom.jpg', 'description' => 'Half a cup of raw mushrooms contains 1.08 grams of protein.'), 'Onion' => array('image' => 'assets/images/fruits/onion.jpg', 'description' => 'One small onion cooked without salt contains 0.82 grams protein.'), 'Potato' => array('image' => 'assets/images/fruits/potato.jpg', 'description' => 'One medium baked potato without salt contains 4.33 grams of protein.'), 'Spinach' => array('image' => 'assets/images/fruits/spinach.jpg', 'description' => 'One cup of raw spinach contains 0.86 grams of protein.'), 'Squash' => array('image' => 'assets/images/fruits/squash.jpg', 'description' => 'One cup of sliced summer squash, boiled with no added salt contains 1.87 grams of protein.'), ); ?>
this array is passed into the 'search_multiple.php' file which I would like to pass in as JSON:
array(), 'vegetables' => array()); foreach ($fruits as $name => $data) { if (stripos($name, $q) !== false) { $results['fruits'][$name] = $data; } } foreach ($vegetables as $name => $data) { if (stripos($name, $q) !== false) { $results['vegetables'][$name] = $data; } } /* Get the data into a format that Smart Suggest will read (see documentation). */ $final_fruits = array('header' => array(), 'data' => array()); $final_fruits['header'] = array( 'title' => 'Fruits', # Appears at the top of this category 'num' => count($results['fruits']), # Displayed as the total number of results. 'limit' => 5 # An arbitrary number that you want to limit the results to. ); foreach ($results['fruits'] as $name => $data) { $final_fruits['data'][] = array( 'primary' => $name, # Title of result row 'secondary' => $data['description'], # Description below title on result row 'image' => $data['image'], # Optional URL of 40x40px image 'onclick' => 'alert(\'You clicked on the '.$name.' fruit!\');', # JavaScript to call when this result is clicked on 'fill_text' => strtolower($name) # Used for "auto-complete fill style" example ); } $final_vegetables = array('header' => array(), 'data' => array()); $final_vegetables['header'] = array( 'title' => 'Vegetables', # Appears at the top of this category 'num' => count($results['vegetables']), # Displayed as the total number of results. 'limit' => 5 # An arbitrary number that you want to limit the results to. ); foreach ($results['vegetables'] as $name => $data) { $final_vegetables['data'][] = array( 'primary' => $name, # Title of result row 'secondary' => $data['description'], # Description below title on result row 'image' => $data['image'], # Optional URL of 40x40px image 'onclick' => 'alert(\'You clicked on the '.$name.' vegetable!\');', # JavaScript to call when this result is clicked on 'fill_text' => strtolower($name) # Used for "auto-complete fill style" example ); } /* Output JSON */ $final = array($final_fruits, $final_vegetables); header('Content-type: application/json'); echo json_encode($final); die(); ?>
I would like to know how to pass json data into the 'search_multiple.php' file. For example:
<?php
$fruits = '{
"Apple":{"image":"assets/images/fruits/apple.jpg","description":"One of America\'s favorite fruits."},
"Avocado":{"image":"assets/images/fruits/avocado.jpg","description":"The avocado is a dense, evergreen tree, shedding many leaves in early spring."}
"Banana":{"image":"assets/images/fruits/banana.jpg","description":"Bananas are fast-growing herbaceous perennials arising from underground rhizomes."},
"Gooseberry":{"image":"assets/images/fruits/gooseberry.jpg","description":"Gooseberries are deciduous shrubs."}
"Grape":{"image":"assets/images/fruits/grape.jpg","description":"Grapes come in large clusters."},
"Jackfruit":{"image":"assets/images/fruits/jackfruit.jpg","description":"The jackfruit tree is handsome and stately."}
"Mango":{"image":"assets/images/fruits/mango.jpg","description":"Mango trees make handsome landscape specimens and shade trees."},
"Papaya":{"image":"assets/images/fruits/papaya.jpg","description":"The papaya is a short-lived, fast-growing, woody, large herb to 10 or 12 feet in height. It is also regarded by some as being delicious."}
"Peach":{"image":"assets/images/fruits/peach.jpg","description":"These are great in the summertime."},
"Pear":{"image":"assets/images/fruits/pear.jpg","description":"Pears are delicious fruits."},
"Pineapple":{"image":"assets/images/fruits/pineapple.jpg","description":"The pineapple plant is a herbaceous perennial, 2-1/2 to 5 ft."}
"Rose Apple":{"image":"assets/images/fruits/rose_apple.jpg","description":"The rose apple is a highly decorative evergreen large shrub."},
"Tamarind":{"image":"assets/images/fruits/tamarind.jpg","description":"The bright green, pinnate foliage is dense and feathery in appearance."}
"White Sapote":{"image":"assets/images/fruits/white_sapote.jpg","description":"One cup of sliced summer squash, boiled with no added salt contains 1.87 grams of protein."},
}';
$vegetables = '{
"Alfalfa":{"image":"assets/images/fruits/apple.jpg","description":"One of America\'s favorite fruits."},
"Artichoke":{"image":"assets/images/fruits/avocado.jpg","description":"The avocado is a dense, evergreen tree, shedding many leaves in early spring."}
"Asparagus":{"image":"assets/images/fruits/banana.jpg","description":"Bananas are fast-growing herbaceous perennials arising from underground rhizomes."},
"Broccoli":{"image":"assets/images/fruits/gooseberry.jpg","description":"Gooseberries are deciduous shrubs."}
"Carrots":{"image":"assets/images/fruits/grape.jpg","description":"Grapes come in large clusters."},
"Celery":{"image":"assets/images/fruits/jackfruit.jpg","description":"The jackfruit tree is handsome and stately."}
"Corn":{"image":"assets/images/fruits/mango.jpg","description":"Mango trees make handsome landscape specimens and shade trees."},
"Green Pepper":{"image":"assets/images/fruits/papaya.jpg","description":"The papaya is a short-lived, fast-growing, woody, large herb to 10 or 12 feet in height. It is also regarded by some as being delicious."}
"Mushroom":{"image":"assets/images/fruits/peach.jpg","description":"These are great in the summertime."},
"Onion":{"image":"assets/images/fruits/pear.jpg","description":"Pears are delicious fruits."},
"Potato":{"image":"assets/images/fruits/pineapple.jpg","description":"The pineapple plant is a herbaceous perennial, 2-1/2 to 5 ft."}
"Spinach":{"image":"assets/images/fruits/rose_apple.jpg","description":"The rose apple is a highly decorative evergreen large shrub."},
"Squash":{"image":"assets/images/fruits/tamarind.jpg","description":"The bright green, pinnate foliage is dense and feathery in appearance."}
}';
?>
请帮帮我!!我无法使用 PHP 编码
谢谢
卡比尔
最佳答案
$dp=mysql_select_db('test');
mysql_query('SET NAMES UTF8');
$sql = mysql_query('select * from users');
while($res = mysql_fetch_assoc($sql)){
$users[$res['username']] = array();
$users[$res['username']]['image'] = $res['profile_picture'];
$users[$res['username']]['email'] = $res['email'];
}
我有一个名为 test 的数据库和一个名为 users 的表,其中包含字段(用户名、电子邮件、个人资料图片),我正在搜索用户名以包含电子邮件和图像(看起来像 facebook 搜索)。该数组会自动从数据库中为您生成您想要的数组,只需搜索用户名,然后更改它以满足您的需要。
关于php - 将 json 数据传递到 smart suggest jquery 插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7946753/
我在 JavaScript 文件中运行 PHP,例如...... var = '';). 我需要使用 JavaScript 来扫描字符串中的 PHP 定界符(打开和关闭 PHP 的 )。 我已经知道使
我希望能够做这样的事情: php --determine-oldest-supported-php-version test.php 并得到这个输出: 7.2 也就是说,php 二进制检查 test.
我正在开发一个目前不使用任何框架的大型 php 站点。我的大问题是,随着时间的推移慢慢尝试将框架融入应用程序是否可取,例如在创建的新部件和更新的旧部件中? 比如所有的页面都是直接通过url服务的,有几
下面是我的源代码,我想在同一页面顶部的另一个 php 脚本中使用位于底部 php 脚本的变量 $r1。我需要一个简单的解决方案来解决这个问题。我想在代码中存在的更新查询中使用该变量。 $name)
我正在制作一个网站,根据不同的情况进行大量 PHP 重定向。就像这样...... header("Location: somesite.com/redirectedpage.php"); 为了安全起见
我有一个旧网站,我的 php 标签从 因为短标签已经显示出安全问题,并且在未来的版本中将不被支持。 关于php - 如何避免在 php 文件中写入
我有一个用 PHP 编写的配置文件,如下所示, 所以我想用PHP开发一个接口(interface),它可以编辑文件值,如$WEBPATH , $ACCOUNTPATH和 const值(value)观
我试图制作一个登录页面来学习基本的PHP,首先我希望我的独立PHP文件存储HTML文件的输入(带有表单),但是当我按下按钮时(触发POST到PHP脚本) )我一直收到令人不愉快的错误。 我已经搜索了S
我正在寻找一种让 PHP 以一种形式打印任意数组的方法,我可以将该数组作为赋值包含在我的(测试)代码中。 print_r 产生例如: Array ( [0] => qsr-part:1285 [1]
这个问题已经有答案了: 已关闭11 年前。 Possible Duplicate: What is the max key size for an array in PHP? 正如标题所说,我想知道
我正在寻找一种让 PHP 以一种形式打印任意数组的方法,我可以将该数组作为赋值包含在我的(测试)代码中。 print_r 产生例如: Array ( [0] => qsr-part:1285 [1]
关闭。这个问题需要多问focused 。目前不接受答案。 想要改进此问题吗?更新问题,使其仅关注一个问题 editing this post . 已关闭 9 年前。 Improve this ques
我在 MySQL 数据库中有一个表,其中存储餐厅在每个工作日和时段提供的菜单。 表结构如下: i_type i_name i_cost i_day i_start i_
我有两页。 test1.php 和 test2.php。 我想做的就是在 test1.php 上点击提交,并将 test2.php 显示在 div 中。这实际上工作正常,但我需要向 test2.php
我得到了这个代码。我想通过textarea更新mysql。我在textarea中回显我的MySQL,但我不知道如何更新它,我应该把所有东西都放进去吗,因为_GET模式没有给我任何东西,我也尝试_GET
首先,我是 php 的新手,所以我仍在努力学习。我在 Wordpress 上创建了一个表单,我想将值插入一个表(data_test 表,我已经管理了),然后从 data_test 表中获取所有列(id
我有以下函数可以清理用户或网址的输入: function SanitizeString($var) { $var=stripslashes($var); $va
我有一个 html 页面,它使用 php 文件查询数据库,然后让用户登录,否则拒绝访问。我遇到的问题是它只是重定向到 php 文件的 url,并且从不对发生的事情提供反馈。这是我第一次使用 html、
我有一个页面充满了指向 pdf 的链接,我想跟踪哪些链接被单击。我以为我可以做如下的事情,但遇到了问题: query($sql); if($result){
我正在使用 从外部文本文件加载 HTML/PHP 代码 $f = fopen($filename, "r"); while ($line = fgets($f, 4096)) { print $l
我是一名优秀的程序员,十分优秀!