Hello - just a quick one
Is it possible to identify the entry for say... row 3, column 4 from a standard SQL query?
ie something like
$result = mysql_query(" SELECT first, second, third, fourth FROM Test")
echo $result[3,4] ...or....$result[third,4]
Thanks in advance.
Chris
SQL Query and Arrays [Solved]
Moderator: General Moderators
SQL Query and Arrays [Solved]
Last edited by christh on Sun Sep 26, 2010 6:02 am, edited 1 time in total.
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: SQL Query and Arrays
You need to iterate your data set first. Your best option if you want to lookup keys in array is to build your results into a array, then you can do whatever.
I.e.,
However, you generally want to query the exact data you want instead of pulling your entire data set and thus performing the filter.
I.e.,
Code: Select all
$result = mysql_query(" SELECT first, second, third, fourth FROM Test");
$rows = array();
while ($row = mysql_fetch_assoc($result)) {
$rows[] = $row;
}
// Third row, column name "fourth"
// But remember, arrays begin at a zero based key, so third row is identified as the [2] key
echo $result[2]['fourth'];Re: SQL Query and Arrays
Excellent - thank you John
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: SQL Query and Arrays [Solved]
Just so there is no confusion, I had a typo.
Code: Select all
echo $result[2]['fourth'];
//should be
echo $rows[2]['fourth'];