You are here: Re: Searching through an array « PHP Programming Language « IT news, forums, messages
Re: Searching through an array

Posted by Jerry Stuckle on 05/18/07 01:58

Akhenaten wrote:
> I have an array created but I need to search it. The array is created
> from a mysql call. Code as follows:
>
> ******************
> function respond_check($qid)
> {
> include "db.inc.php";
> $postchk2 = mysql_query("SELECT * FROM `answers` , `users` WHERE `qid`
> = $qid AND `a_uid` = `userid` LIMIT 0, 30",$db);
>
> while ($userx=mysql_fetch_array($postchk2))
> {
> $poster2 = $u_row22['username'];
>
>
> }
>
> }
>
> ******************
> I've tried including various *if* statements to search for $X in the
> array (which does exist) but I keep failing miserably. Suggestions?
>

I think maybe your problem is $postchk2 is a resource, not an array.
You get a single-dimensional array when you call mysql_fetch_array - but
only the current rows. If you want to search the entire contents
retrieved by MySQL, you need to do something like read everything
returned into an array in PHP then search it. Beware this can take huge
amounts of memory in the case of large rows and/or number of rows.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

 

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

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