Forum Moderators: open

Message Too Old, No Replies

mySQL index query question.

beginner mySQL index

         

thedude81

11:41 pm on Jan 24, 2009 (gmt 0)

10+ Year Member



Hi everyone,

I'm pretty new with mySQL, and have a question about a query that is probably laughably simple, but I can't seem to figure it out.

I have a table with 6 fields (part1, part2,...), and I need to retrieve say the 4th row of data which I will use as seperate variables in php, example for part1, $p1 = mysql_fetch_array($query)

so do I need to do a query for each separate field, and how do I call them by their index?

Sorry if this is really simple, but I have been researching this and getting kinda frustrated.

Thanks

Shores

4:52 pm on Jan 26, 2009 (gmt 0)

10+ Year Member



You seem to be unclear on the difference between fields and records.

Records represent each an object you've catalogued in your table, while a column represents a property and a field represents the value the property has for the object represented by the row.

That said, the php function mysql_fetch_array($query) returns an array which contains all the field values of the ACTIVE record only, so you'll want to repeat the calls to mysql_fetch_array to read all the records one by one.

Then , inside the array returned by mysql_fetch_array you'll fin field values in the same order they have in the record, numbered strating with 0: if you've done $record=mysql_fetch_assoc($queryhandle) , then $record[0] whould contain the first filed value, $record[1] would be the second field's value and so on.

Did i clarify your issue? :)

thedude81

8:08 pm on Jan 26, 2009 (gmt 0)

10+ Year Member



Shores-

That helped alot, thanks much! I did get records vs fields confused. Using a primary key field I'm able to now specify which row I need to retrieve (using ... WHERE id='x')

thanks again ;)

thedude81

8:11 pm on Jan 26, 2009 (gmt 0)

10+ Year Member



wait, did I say primary key field? I think I meant column. lol, well, I do understand the difference a whole lot better nonetheless..

Shores

8:38 pm on Jan 26, 2009 (gmt 0)

10+ Year Member



Happy of being useful!