You are here: Finding a record's positon in a list of results. « PHP SQL « IT news, forums, messages
Finding a record's positon in a list of results.

Posted by Shawn Wilson on 09/30/05 03:17

This was almost asked recently, but not quite how I need to use it. I tried
to extrapolate, but alas I need some clarification.

What I am doing is displaying an image in a photo album. I get to the page
in question with this:

detail.php?picid=101

That page then calls a function to find out what set that pic belongs to,
and then I need to know that pics position in the whole scheme of things.
i.e. this is pic 5 of 10.

Up to this point, I have the picid and the setid it belongs to.

Since the mySQL return is an array that I normally step through, shouldn't I
be able to skip stepping through it myself and simply search the return from
mySQL for what I'm looking for and pull out it's position in the array
without stepping through it?

here's the long way (that works):

-----
function get_pic_position($picid_sent,$setid) {
$query = " SELECT picid FROM `pic` WHERE `setid` = '$setid' ORDER BY `sort`
ASC, `picid` ASC; ";
$result = mysql_query($query) or die('Query failed: $query<br><br>' .
mysql_error());
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
foreach($line AS $_NAME => $_VALUE) { $$_NAME = $_VALUE; }
$array_pic_ids[] = $picid;
# buidling this array is redundant isn't it?
}

$array_pic_position = array_keys($array_pic_ids, $picid_sent);
# can't I do this search directly on the results somehow?

$pic_position = $array_pic_position[0];
# is there a cleaner way of turning this one record array into a non-array?

return $pic_position;
}
-----

But I'm just thinking that there has to be a shorter way to do that, right?

Thanks in advance everyone!

--
Shawn Wilson

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация