Jump to content

Help with arrays please


richarro1234

Recommended Posts

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

 

 

Link to comment
Share on other sites

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.

Link to comment
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.