jquery - Improve PHP Array to use on AJAX -
I have created a PHP file to populate the page using AJAX, but I can not find a solution to my problem Could. / P>
Here my PHP and its output are:
$ result = mysql_query ("IDEec, product, picture select from order 1 by IDEEC"); $ Products = array (); While ($ product = mysql_fetch_array ($ result, MYSQL_ASSOC)) {$ products [] = ($ product); } $ Json = json_encode ($ product); $ Output = release ($ _GET ['callback'])? "{$ _GET ['callback']} ($ JSN)": $ json; $ Output echo; It will print:
[{"id": "5", "Product": "Product 5", "Image": "Image 5. "Junk": "Image": "3", "Product": "Product": "Product 4", "Image": "Picture 4.jpg"}, "Junk" Product ":" Image ":" Picture ":" Picture ":" "" "," 2 "," Product ":" Product 2 "," Image ":" Image 2. JPG "}, {" id ":" 1 "," Product ":" Product1 "," picture ":" picture1.jpg "}] I have a field on this output" In_Stock "so that any other query can be output like this: " "[" id "]" "" "" "" ":" Product ":" "Product": "Product 3", "Product": "Product 4", "Picture": "Picture 4.JPG", "In_Stock": "No"}, {"id": "3", "Product" , "" Picture ":" photo 2 "," product ":" product 2 "," picture ":" picture 2. JPG "," In_Stock ":" Picture 3. {"Id": "1", "Product": "Product 1", "Picture": "Picture 1", "Picture". My question is: Is it possible to use the value of the array (in the first place) to search in another table: jpg "," in_stock ":" no "}]
Add this value to the product array and keep the same "layout" on the above output?
Edit: These are my tables:
TABLE1 ID product photo and another one
TABLE2 ID user product_id in_stock The same product can have different shares depending on the user ...
Yes, you can do another query, but this is probably the first query Need to change, which can include all the data you need, something that looks like Give:
mysql_query ("Select Table 1.id, table1.product, table1.picture, Table 2 to Table 1, Leave Table 2 (Table 1.id = table2.product_id And table2.user = ".interval ($ _ session ['user'])") by order 1.id DESC table; Edit: The user added the session according to your comment. I used intval because I think you are using an integer for the user's ID, and I do not know how the value of $ _SESSION was set - if it is from user input Then it should be As a side note, mysql_query is deprecated, you should look into the mysqli and the prepared statements.
Comments
Post a Comment