zero-perfoliate
zero-perfoliate

Author Topic: Find value in associative array?  (Read 352 times)

Offline effex

  • New PHP Members
  • Posts: 1
  • Karma: +0/-0
Find value in associative array?
« on: January 24, 2009, 06:24:21 PM »
Hello,

I am querying a MySQL database and storing the results in an array using the following method:

Code: [Select]
$resource = mysql_query("select * from tImages where imgCategory = '" . $category . "' ORDER BY imgTitle ASC");
$row = mysql_fetch_assoc($resource);

I'd like to be able to find out which index/row (not sure of the terminology in this case) a particular value falls on.

The table has a column called "imgID", I want to find the "index/key/row" that my variable $imgid matches up on in these results. If that is not possible, I'd like to implement a counter that will count until this value is found in the results. This count / value is needed for later operations in my application.

Any help would be appreciated, let me know if you need further clarification.

-Mike


Offline PhPHelper

  • http://Digiscapers.com
  • Full Member
  • PHP Problem Solvers
  • ****
  • Posts: 179
  • Karma: +50/-0
    • Bad Apple Mail
Re: Find value in associative array?
« Reply #1 on: February 10, 2009, 05:46:57 PM »
since your using

Code: [Select]
$row = mysql_fetch_assoc($resource);
you can refernece parts of the array using the column name from the datbase like this:

Code: [Select]
echo $row['imgID'];


that would print out the id of the image column.

 

zero-perfoliate