Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

searching array for value 1

Status
Not open for further replies.

Microbe

Programmer
Oct 16, 2000
607
AU
Hey folks,

I am trying to create a pair of previous/next links.

I find a value from a database and then want my links to be the previous and next records.

I have determined that all my values are in the array but I am having trouble accessing them.

Testing, I can loop through the array OK using
Code:
do{
	echo $row_categories["categoryID"] . " ";
}while($row_categories = mysql_fetch_assoc($categories));

However I would have thought that I would have hte same result from
Code:
foreach ($row_categories as $a ){
	echo $a . "<br>";
}
but it only returns the first record.

I am a bit brain dead and am likely not seeing the obvious here...but I just can't see how to achieve what I know is relatively straight forward.

The way I would really like to do this is use array_search to find the key for the value of the record I have and then find prev and next (allowing for beginning and end of array etc)

Maybe I just need a break...but any pointers appreciated.

Steve
- I have fun with telemarketers
 
$row_categories will only have ONE row in it at any one time, the way that you have set things up.

and note with the do ... while loop that the first call to it will not have ANY row data. Hence it is FAR more usual to use a while {} loop for database recordset iteration.

to get all your data into an array do the following

Code:
while ($row_categories = mysql_fetch_assoc($categories)){
 $r_c[] = $row_categories['categoryID'];
}
the data will be in the $r_c array
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top