SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Member
    Join Date
    Jul 2008
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    preg_match - searching in twor rows

    Is it possible to use preg_match function for searching in two rows? This example can search only in one row.

    PHP Code:
    <?php
      
    if(preg_match("/$blabla/i"$row[$mysql_row]))
    ?>
    regards

  2. #2
    SitePoint Enthusiast
    Join Date
    Aug 2007
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is it possible to use preg_match function for searching in two rows?
    What do you want, please give an example

  3. #3
    SitePoint Member
    Join Date
    Jul 2008
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I want to search first row($row[$mysql_row]) for a first variable($blabla) AND the second row($row[$mysql_row2]) for a second variable($blabla2) at the same time.
    The example, that I've written in the first post can search only in the one row for a one variable.

  4. #4
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,804
    Mentioned
    157 Post(s)
    Tagged
    3 Thread(s)
    assuming that $row is an array already, then iterate through it with a foreach loop.

    PHP Code:
    foreach($row as $data) {
        if(
    preg_match("/$blabla/i"$data))


    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  5. #5
    SitePoint Member
    Join Date
    Jul 2008
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The example:
    PHP Code:
    <?php

       $priorytet 
    implode(',',$_POST['priorytet']);
       
    $stopien implode(',',$_POST['stopien']); //
        
       
    $query "SELECT * FROM $db_table WHERE priorytet like '%{$priorytet}%' AND stopien like '%{$stopien}%'";//
       
    $result mysql_query($query);
       
    $numrows mysql_num_rows($result);
       while(
    $row mysql_fetch_array($result)){
       
       if(
    preg_match("/$priorytet/i"$row[$mysql_row]))
    //what should I write here?
    ?>

  6. #6
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Sorry, but I don't really understand your goal...but maybe this is what you're looking for.

    PHP Code:
    if( preg_match("/$priorytet/i"$row['rowOne']) && preg_match("/$priorytet/i"$row['rowTwo']) )
    {
        
    //-->Do Stuff

    SilverB.

  7. #7
    SitePoint Enthusiast
    Join Date
    Aug 2007
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    spikeZ +1, he is right.

    more example:
    Code:
    $str = implode(" ", $row);
     if(preg_match("/$blabla/i", $str)){
    ........


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •