You are here: Re: mySQL loop and string operation « PHP Language « IT news, forums, messages
Re: mySQL loop and string operation

Posted by Norman Peelman on 02/04/07 13:55

Simon Harris wrote:
> Hi All,
>
> I have a page which loops through many database records, running a string
> function to strip HTML (Using RegEx/preg_replace). I am concerned that over
> time, this is going to become very slow.
>
> Few ideas I had:
>
> a) Cache the HTML free version of the text in the DB, updating/creating each
> records text when the page is loaded, based on the updated date of the
> record.
> b) Is there a faster way to strip the HTML? Could I do this on-the-fly at
> mySQL level?
> c) In ASP ( My native language! :-) ) I can load the results into an array,
> then loop the array which is quicker. Can this be done in PHP?
>
> Any ideas much appreciated.
>
> Simon.
>
>

Yes, you can do the same in PHP. It can be done like so:

$dbc = mysql_connect('localhost','user','passwword');
$db = mysql_select_db('database',$dbc);

$query = "SELECT * FROM tablename WHERE ????"; // you get the idea. :)
$result = mysql_query($query,$dbc);

// grab rows into array $data with associative keys
while($data[] = mysql_fetch_array($result,MYSQL_ASSOC)
{
}

// subtract 1 as an extra row still gets created when the final
mysql_fetch_array fails.
$data_size = count($data)-1;

// loop through data
for($loop = 0;$loop <= $data_size; $loop++)
{
echo "{$data[$loop]}<br>";
$stripped = strip_tags($data[$loop]);
echo "$stripped<br>";
}

---

Norm

 

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

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