getting data from rows containing $code

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
X3no
Forum Newbie
Posts: 12
Joined: Sun Aug 26, 2007 3:49 pm

getting data from rows containing $code

Post by X3no »

I have a mysql database with a table that contains account information. Users can have up to 5 accounts and each one shares a value called regkey. I want to find and echo the name of all the users that have the same regkey value.

How would I do this?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

A basic SELECT query?
X3no
Forum Newbie
Posts: 12
Joined: Sun Aug 26, 2007 3:49 pm

im new to this

Post by X3no »

Im pretty new to this can you give me an example script?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

There are plenty of examples throughout our forums, the manual(s) and the web. Sorry, no.
X3no
Forum Newbie
Posts: 12
Joined: Sun Aug 26, 2007 3:49 pm

I tried

Post by X3no »

I tried to find an example before I posted but couldn't find one.
Fiarr
Forum Newbie
Posts: 2
Joined: Sun Aug 26, 2007 4:14 pm

Post by Fiarr »

I was wondering the same thing....

I havn't been able to find the answer since I don't know what to search for....

Im completely new to php.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Fiarr
Forum Newbie
Posts: 2
Joined: Sun Aug 26, 2007 4:14 pm

Post by Fiarr »

And this will let me search the database for whatever I specify??
X3no
Forum Newbie
Posts: 12
Joined: Sun Aug 26, 2007 3:49 pm

Post by X3no »

Ok this doesn't explain what I need I can't figure out how to do this.

I say I get the table down to:

username|key
name1|key1
name2|key2
name3|key1

ok then i want a way so that if I tell it key 1 it would give me name1 and name 3 or if i gave it key2 i would get name 2.

Can someone just explain how I would do this?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Whats your table structure?
X3no
Forum Newbie
Posts: 12
Joined: Sun Aug 26, 2007 3:49 pm

table structure

Post by X3no »

|username|password|email|realname|regkey|

and I want to find all the usernames with a particular regkey
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

The manual will give you some more examples on querying your database based on certain fields. :arrow: http://dev.mysql.com/doc/refman/5.0/en/select.html

Code: Select all

SELECT * FROM `your_table_name_here` WHERE `regkey` = 'dsf2432dsf'
Some other links you should read over, mysql_connect(), mysql_query(), mysql_fetch_assoc(), mysql_num_rows(), mysql_real_escape_string()
X3no
Forum Newbie
Posts: 12
Joined: Sun Aug 26, 2007 3:49 pm

Post by X3no »

could I change * to username so that it would give me the usernames with that key?
X3no
Forum Newbie
Posts: 12
Joined: Sun Aug 26, 2007 3:49 pm

Post by X3no »

ok never mind but now I got the infomation I needed but and I am using this code

Code: Select all

$sql="SELECT username FROM ".$table." WHERE regkey = '".$_GET['regkey']."'";
$qry = mysql_query($sql);
while ($row = mysql_fetch_array ($qry)) 
{
echo $row[0];
}
and this gives me one of the entries but I should be getting 2 how do I change this so I can get 2?
Post Reply