SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Nov 2009
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    compare submitted value to a table

    hope someone can help.

    i have a mysql table that includes blocked numbers -

    $blockednum

    i would like to compare a value submitted in a form and do execute a command only if the number submitted does not appear in the blocked numbers list.

    hope i made myself clear.

    thanks

  2. #2
    SitePoint Enthusiast
    Join Date
    Apr 2009
    Location
    Greenville, South Carolina, United States
    Posts
    50
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, assuming blocked numbers means a set of numbers that you do not want (or, for instance, blocked from a phone?)


    Code PHP:
    $get_all_nums = mysql_query("SELECT * FROM `BLOCKEDNUMBERS` WHERE `$blockednum` = '$row[name]' ASC");
    while ($allnums = mysql_fetch_array($get_all_nums)){
     
     echo "$allnums <br />";
     
    }

  3. #3
    SitePoint Member
    Join Date
    Nov 2009
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks,


    i was able to print out all blockednum with the following code

    $result = mysql_query("SELECT * FROM sample")
    or die(mysql_error());

    $row = mysql_fetch_array($result) or die(mysql_error());

    while($row = mysql_fetch_array($result)){


    echo $row['blockednum'];
    echo "<br />";
    }


    what i am trying to achieve is to compare a variable called $number that is submitted in a form to the blocked numbers.

    if the $number variable appears in the list of blocked numbers i would like the code to execute something like echo "the number is blocked" and at that point to discontinue executing the rest of the code.

    if the $number does not match the list of blockednum's i would like the code to continue.

    thanks

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,216
    Mentioned
    58 Post(s)
    Tagged
    3 Thread(s)
    would you kindly run this query and show us the results
    Code:
    SHOW CREATE TABLE sample
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  5. #5
    SitePoint Member
    Join Date
    Nov 2009
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi

    i was able to solve the problem with the following

    $result = mysql_query("SELECT * FROM sample where blocked =
    '$number'");
    if(! $result) //if error in SQL display the error
    die(mysql_error()); //do not proceed beyond this point

    //see if we got any results
    if(mysql_num_rows($result) > 0) {

    //get phone number info to show below
    $row = mysql_fetch_array($result);

    echo "The number - " .$row['blocked']. " - has been blocked";


    thanks!!!


Tags for this Thread

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
  •