Jump to content

explode() and arrays


tleisher

Recommended Posts

Alright, so here's how my database works. If someone adds a book as their favorite it takes their current favorite book column, adds "," and then the book name so it comes up  like "1,2,3".

Then in the favbook.php file, I want to have it display all the usernames of the people who have the book id in their fav_book column.

So far I figured that I should read that column with a mysql query, then mysql_fetch_array the query, and then explode(",", $fav_book);

But how would I do this in a loop so that it reads through the array and if it doesnt find $_GET["id"] then it doesn't print that username, then continues on to the next row with the new username and so on until it gets to the bottom of the table?
Link to comment
Share on other sites

Just a note.. this method of storage (delimeted list) is looked upon as 'sloppy' because, well, it is sloppy.

Use a table to store all the users entries with a foreign key for the user id and a foreign key for the book details. Essentiall 3 columns: index, userid, bookid.

Then select the rows from that table, with joins on users and books if necessary. It will be MUCH more efficient.
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.