Question about reading an array

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • runway27
    Banned
    New Member
    • Sep 2007
    • 54

    Question about reading an array

    I need to insert email address into a table, before that i need to make sure that this email address is not already in the table. to check this i used =

    if(in_array($em ail, $emailrows)) = This works however it only reads the value of email in the First row only not the remaining rows in the table.

    please provide the code to check all the rows in the table for the Email field.
  • Lumpy
    New Member
    • Oct 2007
    • 69

    #2
    Any chance that we can see the code you have that is running your query. That might help to get a better idea of what your doing and where the code might need a little tweaking.

    Comment

    • w0rKInPHP
      New Member
      • Oct 2007
      • 6

      #3
      [CODE=php]//sql?
      <?php
      $query = "select pk from tablename where email = 'emailaddress'" ;
      $result = pg_query($query ); //mysql_query() for mysql
      $total = pg_num_rows($re sult); //mysql_num_rows( ) for mysql

      if($total == 0)
      {
      //code goes here.
      }
      ?>


      //array?
      foreach($emaila rray as $email)
      {
      if(strcasecmp($ email, $otheremail) == 0)//case insensitive comparison
      {
      //code goes here
      }
      }[/CODE]
      Last edited by pbmods; Oct 27 '07, 02:14 PM. Reason: Changed [CODE] to [CODE=php].

      Comment

      • aym
        New Member
        • Oct 2007
        • 4

        #4
        Originally posted by w0rKInPHP
        Code:
        //sql?
        <?php
        $query = "select pk from tablename where email = 'emailaddress'";
        $result = pg_query($query); //mysql_query() for mysql
        $total = pg_num_rows($result); //mysql_num_rows() for mysql
        
        if($total == 0)
        {
          //code goes here.
        }
        ?>
        
        
        //array?
        foreach($emailarray as $email)
        {
          if(strcasecmp($email, $otheremail) == 0)//case insensitive comparison
          {
            //code goes here
          }
        }
        the first thing that I noticed is that u forgot to put the $ sign near "where email = 'emailaddress'" .
        last thing is that I could not understand ur question well. Please declare more.

        Comment

        • pbmods
          Recognized Expert Expert
          • Apr 2007
          • 5821

          #5
          Heya, runway27.

          Try using the REPLACE keyword instead of INSERT.

          Comment

          Working...