2011-10-30 1 views
1

스마트 제안 인 jquery 플러그인을 구입했으며 어레이가 아닌 데이터로 json 배열을 전달하려고합니다.스마트에 json 데이터를 전달하면 jquery 플러그인을 추천합니다

:

 

    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.'), 
           ); 
    ?> 

이 배열 내가 JSON로 전달하고자하는 'search_multiple.php'파일에 전달된다

현재 데이터 파일 '샘플 data.php'는 같다

 

    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(); 
    ?> 

json 데이터를 'search_multiple.php'파일로 전달하는 방법을 알고 싶습니다. 예 :

<?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의 코드가 아닌

감사 할 수

Kabeer 나는 데이터베이스라는 테스트 및 테이블 필드 (사용자 이름, 이메일, profile_picture), 나는에 사용자 이름을 찾고있어 사용자에게 전화했는데

+0

플러그인 비용을 지불 했으므로 명확한 문서가 있어야합니다. 그것을 찾아보십시오. –

+0

나는 설명서가 실제로이 웹 사이트 http://jamesskidmore.com/scripts/smartsuggest/의 복사본 일 뿐이며 아마도 대답을 담고 있을지 모르지만 이해할 수 없다. 나는 여러 해 동안 닦았다. – kabeerv

+0

[ json 데이터를 스마트 추천 플러그인에 입력] (http://stackoverflow.com/questions/7947644/entering-json-data-into-smart-suggest-plugin) – phihag

답변

4
$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']; 
} 

이메일과 이미지가 있어야합니다 (페이스 북 검색과 유사). 이 배열은 데이터베이스에서 자동으로 원하는 배열을 생성합니다. 사용자 이름을 검색하고 필요에 맞게 변경합니다.

관련 문제