JSON and Php problem
My mind got stuck when i try to develope this: i have a table in my database called "article" whit two column, "name" and "price". How can i extract all rows from my table and echo all column in JSON? i really can't understand how to convert result in JSON. My mind it's stuck like never before. i need to echo something like this:



{"items": {

"items":[

{"name": "firstitemname",

"price": "5"

},

{"name": "secondone",

"years": "3"

}],

}}



Please help me fixing my fully wrong code!

20th Jul 2011 at 12:47 AM   1387 Views

Is that , name & years pair is from another table or same table ? You need to do use PHP's json_encode() function to make JSON representation of u'r data.

What i feel, from u'r given example.. u need to convert each pair of data(name, price or name,year) to JSON then insert them to the "items" array...

Ref: json_encode() : http://php.net/manual/en/function.json-encode.php

Give me u'e table structure so that i can u tell u some thing more about it.
20th Jul 2011 at 8:44 AM  

i need to create a list in a "grid" style, so there will be some. Each "info box" will have information taken from JSON. How to do so?

PHP file echo in JSON 2 elements for item and depending by the week, a different quantity of element. How i can create the right number of "info box" ( based of the number of json items ) and how to add the name and price of them? This is the HTML code for the "info-box".
<div class="item">
    <
span id="itemname">*itemname*</span>
<
div id="price" class="price">*price*</div>
        </
div

how i should create box (whit Jquery) and add information received from JSON? Thanks!
20th Jul 2011 at 3:02 PM  

Hey Matteo, I really can't understand what u wanted to do.. but,

if u want to parse JSON elements then u can use JQuery's parseJSON() and one more thing which u wanted know how to create right number of info box based on number of JSON items.. for this, u can use JQuery's $.each()

Ref:
jQuery.each(): http://api.jquery.com/jQuery.each/
jQuery.parseJSON: http://api.jquery.com/jQuery.parseJSON/

If u give me u'r table structure & HTML data presentation layout, then i can more exactly tell u how to do that...
20th Jul 2011 at 7:36 PM