Jump to content

Recommended Posts

I need to pass two parameters in each() method. How can i do that ?

 

The problem is this: I have a query that returns username, id, local, offer, and so on. But i need another function because i need to get the tags for each offer. The main problem is each offer can get many tags, so for each offer i need data from two php functions.

 

script

 

first function

 

   function get_posts($db, $start, $number_of_posts) {
           //code
            	return json_encode($posts);
            }

   

output:

 

 

  string '[{"username":"Altitude software","foto_oferta":"thumb\/miniaturas\/oferta\/default_offer.jpg","actividades":"Some activities","id_oferta":77,"oferta":"Programador web" ...

second function

 

    function get_posts1($db, $start, $number_of_posts) {
           //code
            	return json_encode($posts1);
            }

 

output:

 

    string '[{"id_offer":77,"tags":["c++","JAVA"]},{"id_offer":76,"tags":["ajax","php"]},{"id_offer":75,"tags":["PHP","JAVA"]}]'

 

 

 

js

 

 

 var postHandler = function(postsJSON, postsJSON1) {
    				$.each(postsJSON, postsJSON1, function(i, post, post1) {//problem here- this didn't works. Only works something like $.each(postsJSON, function(i, post) {
    					var id = 'post-' + post.id_oferta;
    
    					$('<div></div>').addClass('post').attr('id',id)
    					.html('<div class="box_offers"><div class="rating_offer"></div><div class="post-title">' 
    							+ post.oferta + '</div>  <div class="post-box"> <a class="oferta_val bold_username">'
    							+ post1.tags+ '</a></div><a id='+id+'hide class="post-more" >Tags</a><div class="logo_offer">')
    							.appendTo($('#posts'));
    
    					$('#'+id+'hide').click(function() {
    						$('.'+id+'hidden').slideToggle('fast');
    					});
    				});	
    			};

    postHandler(<?php echo get_posts($db, 0, $_SESSION['posts_start']); ?>, <?php echo get_posts1($db, 0, $_SESSION['posts_start']); ?>);

 

Link to comment
https://forums.phpfreaks.com/topic/254629-parameters-each/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.