preg_match

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kyle4017
Forum Newbie
Posts: 1
Joined: Tue May 19, 2009 8:04 pm

preg_match

Post by kyle4017 »

Ok so the following code works, but I need to put information from my mySQL database into $var1. The information is seperated by commas in the different columns of my database (ex: col_1 = object1, object2, object3). I need to basically "echo" a columns contents into $var1. Is this possible? Hopefully that makes sense

Code: Select all

 
 
$result = mysql_query("SELECT * FROM table_name");
 
$var1 = "need databse information to go here";
 
  while($row=mysql_fetch_array($result))
  {
  $rows=explode(", ", $row['table_row']);
    
  foreach($rows as $table_row)
   {
      if (preg_match("/\b$table_row\b/i", "$var1")) {
 
echo $table_row.'RED HIGHLIGHT<BR> ';
      }else {
echo $table_row.'<BR> ';
  }
   }
  }
 
 
Last edited by Benjamin on Tue May 19, 2009 8:34 pm, edited 1 time in total.
Reason: Changed code type from text to php.
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: preg_match

Post by JAB Creations »

Information separated by commas? Easy, blow it all up! :twisted:
http://php.net/explode
Post Reply