Jump to content

Getting a specific row from a mysql_query(SELECT *) result


Jimbo

Recommended Posts

Hi,

 

I'm selecting a group of records from a table, then, using mysql_fetch_array() and successfully creating a table of results.  All fine and no problem.

 

A row in this table is a small portion of the fields from the database record, with the whole record to be displayed on an item details page via a link.

 

My question is: When the user clicks a link to a particular item, which will be identified by the unique id from the record, how do I query the result resource that I already have from the select query to feed that, specifc, record to the details page?

 

I don't want to have to re-query the database using the unique ID if I don't have to.

 

I understand that mysql_fetch_array just advances the array pointer along one.

 

What am I missing?

 

Any advice gratefully lapped up!

 

Cheers.

 

Link to comment
Share on other sites

Thanks for the reply.  I guess I did waffle a bit, as this isn't what I'm asking.

 

I'm trying to avoid having that second query, the one you've just written, when I've already got an array (well, the 'resource') with all the records I want in it. 

 

I just want to be able to query that same resource by the selected 'id'.  I want to pull out a specific row.

 

If it's not possible, then sure, I'll run the query that looks up the 'id'.

 

mysql_data_seek()?  Although that looks up a row number, doesn't it?

 

Hehe, it's a simple concept that I'm managing to explain really badly! Sorry.

 

Edit:  I should add that I'm sticking the result of the query, in $_SESSION, hence not wanting to bother with another query on the details page.

Link to comment
Share on other sites

so you want a query, to locatate a row in another queries result ?

 

Eek, you wouldn't think I was a native English speaker would you?

 

Not a query, no, I want to know if there's a php function to look at a result resource from a multi-record SELECT * query and give you the array row that corresponds to the db record with the primary key you want to look up.

 

All I know is that I can mysql_fetch_array records sequentially from wherever the array pointer is currently at, or I can use mysql_data_seek to get a particular row by it's row_id.

 

Edit: And, yes, I know I said "I just want to query" in my previous post....sorry, didn't mean as in query db!  Urk.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.