Possible Duplicate:
Assign click handlers in for loop
I am requesting tweets from twitter and i save them into two arrays. one array has tweets from news channels and the other one has tweets from users who posted for the same tweet of the first array(news_array).
As you can see am checking the text from the user_tweeets array against the text of the first array and output all those users who tweet for that news.
the problem is that each time an entry is outputted the name of the news_user is outputted and the text. I don't want it to show these elements every time but only the profile image of the user and only once the text,profile img and name of the channel. How can i do that?
Here is a fiddle ---jsfiddle
function geo(news_array, user_tweets) {
console.log(news_array);
console.log(user_tweets);
for (var i = 0; i < news_array.length; i++) {
var news_date = news_array[i].news_date;
var news_profile_img = news_array[i].news_profile_img;
var news_text = news_array[i].news_text;
var news_url = news_array[i].news_url;
var news_user = news_array[i].news_user;
second(news_user, news_date, news_profile_img, news_text, news_url);
}
function second(news_user, news_date, news_profile_img, news_text, news_url) {
for (var x = 0; x < news_array.length; x++) {
var user = user_tweets[x].user;
var date = user_tweets[x].date;
var profile_img = user_tweets[x].user_profile_img;
var text = user_tweets[x].text;
var url = user_tweets[x].url;
if (text.indexOf(news_text.substr(15, 20)) > -1) {
geocode(user, date, profile_img, text, url, news_user, news_date, news_profile_img, news_text, news_url);
}
}
function geocode(user, date, profile_img, text, url, news_user, news_date, news_profile_img, news_text, news_url) {
$('#news-tweets').css({
'overflow-y': 'scroll',
'overflow-x': 'hidden'
});
$('#news-tweets').append('<table class="news" width="402" border="0">\
<tr>\
<td colspan="5" class="user">' + news_user + '(' + news_date + ')</td>\
</tr>\
<tr>\
<td colspan="5" rowspan="1" class="user">' + news_text + '</td></tr><tr><td width="59" valign="top"><a href=' + profile_img + ' target="_blank">\
<img src=' + profile_img + ' width="55" height="50"/></a></td>\
</tr>\
</table>');
}
}
}