Jimbo Posted October 24, 2007 Share Posted October 24, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/74591-getting-a-specific-row-from-a-mysql_queryselect-result/ Share on other sites More sharing options...
almightyegg Posted October 24, 2007 Share Posted October 24, 2007 Not entirely sure what you mean but I think this will do it: URL = mysite.com/items.php?id=XXX $id = $_GET['id']; $select = mysql_query("SELECT * FROM table WHERE id='$id'"); $item = mysql_fetch_array($select); Quote Link to comment https://forums.phpfreaks.com/topic/74591-getting-a-specific-row-from-a-mysql_queryselect-result/#findComment-376964 Share on other sites More sharing options...
Jimbo Posted October 24, 2007 Author Share Posted October 24, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/74591-getting-a-specific-row-from-a-mysql_queryselect-result/#findComment-376968 Share on other sites More sharing options...
adam291086 Posted October 24, 2007 Share Posted October 24, 2007 so you want a query, to locatate a row in another queries result ? Quote Link to comment https://forums.phpfreaks.com/topic/74591-getting-a-specific-row-from-a-mysql_queryselect-result/#findComment-376970 Share on other sites More sharing options...
Jimbo Posted October 24, 2007 Author Share Posted October 24, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/74591-getting-a-specific-row-from-a-mysql_queryselect-result/#findComment-376983 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.