richarro1234 Posted July 22, 2009 Share Posted July 22, 2009 Hey. I need some help with arrays, please. Im trying to get a list of numbers from a database, put it into an array, send it to another page (using ajax) then the second page qill sort the array into a list of numbers, count how many numbers there are, and add them into the database. but i have no idea how to do arrays very well, i have looked at a few tutorials but still dont understand how to do what i need. Can someone help me please. Thanks Rich Quote Link to comment Share on other sites More sharing options...
WolfRage Posted July 22, 2009 Share Posted July 22, 2009 Can you post the code that you have and add comments for the parts that you are unsure of or do not know how to complete. Quote Link to comment Share on other sites More sharing options...
richarro1234 Posted July 22, 2009 Author Share Posted July 22, 2009 well there isnt any code yet as i dont knowe where to starts, thats what i was hopeing for, someone to help me get started and show me some examples of the type of thing im after and that kinda stuff. Quote Link to comment Share on other sites More sharing options...
WolfRage Posted July 22, 2009 Share Posted July 22, 2009 Well you are going to use mysql_fetch_array() to retrieve your result. Do you know how to use AJAX? You can count the number of elements in an array using count(). Now why would you want to return what you just extracted from the database and put it right back into the database? Quote Link to comment Share on other sites More sharing options...
Batosi Posted July 22, 2009 Share Posted July 22, 2009 Ok your going to come to a problem here because you cant just pass a php array via ajax. You need to put as part of a form, part of a url or a session (with the last one you can use an array). Explain what you are trying to do a little more though because it doesnt make much sense Quote Link to comment Share on other sites More sharing options...
richarro1234 Posted July 22, 2009 Author Share Posted July 22, 2009 well its goin into a different table. its like a news feed, ppl select what catagorys they want to see, then the script gets the list from the database, adds it to the new database, then the script outputs the users choice. but it needs to be a new row for each catagory. like: ID|CATID 1 | 1 1 | 3 2 | 1 2 | 5 etc etc... Well, the page im using needs to get a list of id's then that list needs to be passed to another script where that list of numbers can be added to the database as new rows for each. Im trying to create a news feed so need the friends id's as a list so that when its added to the database it shows to friends of the person posting the news. Quote Link to comment Share on other sites More sharing options...
richarro1234 Posted July 23, 2009 Author Share Posted July 23, 2009 bumping the topic, still need help please Quote Link to comment Share on other sites More sharing options...
abazoskib Posted July 24, 2009 Share Posted July 24, 2009 richarro, instead of explaining how you want the program to work, try explaining the real life situation a little better. start with, a user goes onto your website and... Quote Link to comment Share on other sites More sharing options...
Danny620 Posted July 24, 2009 Share Posted July 24, 2009 richarro are you trying to create a category of diffrent news and the user simply chosen which news she/he is intrested in and then that information on which news they prefer to watch gets updated into the database. Quote Link to comment Share on other sites More sharing options...
richarro1234 Posted July 24, 2009 Author Share Posted July 24, 2009 Ok, heres whats happening.... Its a different kind of social networking site (i wont go into detail) basically im creating a mini feed like facebook has got, and im trying to make it so that the news feed is posted to other peoples mini feeds. The only way i could think of doin that was by having it add a new row for each friend that person has. So, say i was id 1 and i was friends with id's 3,5,6,7,9,12. The database would look like this: userid | Friendid | action 1 3 updated status 1 5 updated status 1 6 updated status 1 7 updated status 1 9 updated status 1 12 updated status Then on the friends mini feeds (3,5,6,7,9,12) it will show <username>(id 1) has updated his status. unless you can think of an easier way to do it that doesnt involve creating a new row for every friend? Hope that explains it a bit better. Thanks Rich Quote Link to comment Share on other sites More sharing options...
abazoskib Posted July 24, 2009 Share Posted July 24, 2009 Why dont you just have a table that relates friends(user_id, friend_id) then just query the newest entries from the feed table for each friend. lets say i am a user and i post to my feed, or anyone posts to my feed(stored in the feed table). now on each person's feed, query the newest feed posts made by their friends by relating the friend relationship to the feed table. The method you suggested will cause redundant date to be built up. Let me know if you need a better explanation.. here's a quick diagram friend table ------------------------ user_id | friend_id 180 185 185 180 205 180 feed table ------------------------------------------ user_id | feed_post | posted_by 180 "hello" 180 180 "goodbye" 205 205 "haha" 180 You see how you can relate feed table and friends? its a join on the two tables. Quote Link to comment Share on other sites More sharing options...
richarro1234 Posted July 24, 2009 Author Share Posted July 24, 2009 oo i see, that makes more sense lol. can you explain abit more on how to do it though, i understand i just havent really used join() so not fully sure how it works. Thanks Rich Quote Link to comment Share on other sites More sharing options...
abazoskib Posted July 25, 2009 Share Posted July 25, 2009 to select all feed posts for user id 180 while you are user id 205 the query would look like: select friend_id,feed_post,posted_by from friend as fr,feed as fd where fr.user_id=205 and fr.friend_id=180 and fd.user_id=180 not tested, but hopefully you get the idea. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.