Page 1 of 1
How to show.....
Posted: Sun Oct 17, 2010 9:06 pm
by robynprivette
I have a db named scrolls.
there is one table inside the db containing two fields user & code
I want to show ALL codes from the table that match the user field. how would I do this?
For example:
a user has three code entries and i want to show all entries from the user
Re: How to show.....
Posted: Sun Oct 17, 2010 10:11 pm
by requinix
Code: Select all
SELECT field FROM table WHERE foo = bar
Substitute "field", "table", and "foo = bar" as needed.
Re: How to show.....
Posted: Sun Oct 17, 2010 10:17 pm
by robynprivette
tasairis wrote:Code: Select all
SELECT field FROM table WHERE foo = bar
Substitute "field", "table", and "foo = bar" as needed.
what do i put for foo and bar??
Re: How to show.....
Posted: Sun Oct 17, 2010 10:25 pm
by robynprivette
i don't think i was clear enough. say user Silver is in the column user three times. there are three different codes in column code beside the name Silver. I want to echo the user's name and then all the codes entered by that user
Re: How to show.....
Posted: Sun Oct 17, 2010 11:58 pm
by requinix
You were clear enough, I just didn't give you the full answer that you wanted to hear. I'm expecting you to learn a little SQL and PHP.
SELECT query syntax
PHP+MySQL tutorials
Re: How to show.....
Posted: Mon Oct 18, 2010 12:04 am
by robynprivette
tasairis wrote:You were clear enough, I just didn't give you the full answer that you wanted to hear. I'm expecting you to learn a little SQL and PHP.
SELECT query syntax
PHP+MySQL tutorials
i know i'm trying... i've been googling and reading and trying things till i'm blue in the face!! that's why i came here....

Re: How to show.....
Posted: Mon Oct 18, 2010 12:52 am
by requinix
The query is basically
Code: Select all
SELECT code FROM table WHERE user = "Silver"
Any PHP+MySQL tutorial will show you how to print the results of that query.
Re: How to show.....
Posted: Mon Oct 18, 2010 12:57 am
by robynprivette
tasairis wrote:The query is basically
Code: Select all
SELECT code FROM table WHERE user = "Silver"
Any PHP+MySQL tutorial will show you how to print the results of that query.
there are other users too though. i want to echo everyone's codes under their name
Re: How to show.....
Posted: Mon Oct 18, 2010 1:27 am
by requinix
Then select everything, order by the person's name, perhaps sort by code too, and loop through it all:
1. Fetch a row
2. If the previous row's user doesn't match the current row's user (or if this is the first row) then you're showing codes for a new person
3. Print the code
4. Go to 1