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
https://forums.phpfreaks.com/topic/20128-explode-and-arrays/
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
https://forums.phpfreaks.com/topic/20128-explode-and-arrays/#findComment-88458
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.