Jump to content

Fetching Data from Database...


Fender963

Recommended Posts

Hello everyone,

Currently if I want to fetch data I have stored in my database I do a simple $arr=mysql_fetch_array(......)

and then

$temp = $arr['article'];
echo "$article";

This however is pretty limiting.  I would like to be able to somehow maybe read it character by character or do something so that I could say, insert an ad after the first 500 characters or something of this nature.

Any tips?
Link to comment
https://forums.phpfreaks.com/topic/29179-fetching-data-from-database/
Share on other sites

Well I use this function to put ... after a word after so many characters.

function myfragment($s,$n) {
$scan=0;
  while($scan==0){
  if(substr($s,$n,1)==' ' || strlen($s)<$n){
      $scan=1;
  }else{
      $n++;
  }   
  }
  return substr($s,0,$n) . "...";
}

lets try this (not tested, just a guess)
[code]
function myfragments($s,$n,$ad) {
$scan=0;
  while($scan==0){
  if(substr($s,$n,1)==' ' || strlen($s)<$n){
      $scan=1;
  }else{
      $n++;
  }   
  }
  return substr($s,0,$n) . "<br />" . $ad . "<br /> . substr($s,$n);
}

//
//Insert $my in $article after the first word ends ater 500 characters
//

echo myfragments($article,500,$myad);
[/code]


Hope this works, or at least gives you an idea.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.