Results 1 to 3 of 3
Jan 24, 2010, 08:21 #1
- Join Date
- Jan 2010
- 0 Post(s)
- 0 Thread(s)
Querying MySQL with PHP: How to Select Certain Data to Display?
As php/mysql practice, I'm creating a basic simpet engine (if that's what you'd call it).
I've got most of it worked out but one problem I ran into is how to select and display certain data from a table in mysql.
Here's what my table looks like:
Table name: pets
id - owner
1 - KenKenderson
2 - chocolat
3 - KenKenderson
4 - KenKenderson
5 - chocolat
The 'id' is unique for every pet and is also set up as the primary key. The 'owner' I set up as a fulltext index.
What I want to happen is this:
When a user visits their own profile, a query will be sent to mysql searching the owner column for their username. For every row containing their username, the profile will echo an img tag corresponding to the individual pet (for instance, 1.jpg if the first row is called).
So if KenKenderson logs in, the profile page will display three images, 1.jpg, 3.jpg, and 4.jpg. When chocolat logs in, it will display 2.jpg and 5.jpg.
My main problem is that I'm not sure how to go about setting up the query.
The only option I was able to think of was to go through the id #'s one by one, checking the owner column, printing or not printing, and then moving on to the next id #. This way is feasible and I know I can program it, but I was wondering if there was a faster, more feasible way to go about it? For instance, what if there were 200 rows? 1000 rows? 10,000 rows? As the numbers grow, is that search method still a viable one?
I've gone through the book I am using to teach myself many times looking for an answer, have done a lot of googling, and browsed a half dozen pages of thread titles on here with no luck. Any help and/or advice would be appreciated