How to show.....

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
robynprivette
Forum Commoner
Posts: 46
Joined: Sun May 02, 2010 6:22 pm

How to show.....

Post 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
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: How to show.....

Post by requinix »

Code: Select all

SELECT field FROM table WHERE foo = bar
Substitute "field", "table", and "foo = bar" as needed.
User avatar
robynprivette
Forum Commoner
Posts: 46
Joined: Sun May 02, 2010 6:22 pm

Re: How to show.....

Post 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??
User avatar
robynprivette
Forum Commoner
Posts: 46
Joined: Sun May 02, 2010 6:22 pm

Re: How to show.....

Post 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
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: How to show.....

Post 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
User avatar
robynprivette
Forum Commoner
Posts: 46
Joined: Sun May 02, 2010 6:22 pm

Re: How to show.....

Post 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.... 8O
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: How to show.....

Post 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.
User avatar
robynprivette
Forum Commoner
Posts: 46
Joined: Sun May 02, 2010 6:22 pm

Re: How to show.....

Post 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
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: How to show.....

Post 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
Post Reply