How to put an array into MySql code into a looped recordset?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • K Middlesworth

    #1

    How to put an array into MySql code into a looped recordset?

    I am trying to add a variable ($thezip) from a loop into the WHERE statement of a recordset within that loop. This has been no problem in other situations, but because the variable in the loop is an array, it doesn't seem to work. Not sure how to fix it although I'm assduming (hoping) that it is a simple fix.

    Below is the code. Thanks so much for the help.


    Code:
    require("zipcode.php"); 
    
    
    $zip1 = $HTTP_GET_VARS['zip1']; 
    $radius = $HTTP_GET_VARS['radius']; 
    
    if($radius !=""){ 
    $array = close_zipcodes($zip1,$radius,"M"); 
    $x=0; 
    
    while($x<count($array)) { 
    $thezip = $array[$x][0]; 
    
    if (!function_exists("GetSQLValueString")) { 
    function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
    { 
      $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; 
    
      $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); 
    
      switch ($theType) { 
        case "text": 
          $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; 
          break;     
        case "long": 
        case "int": 
          $theValue = ($theValue != "") ? intval($theValue) : "NULL"; 
          break; 
        case "double": 
          $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; 
          break; 
        case "date": 
          $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; 
          break; 
        case "defined": 
          $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; 
          break; 
      } 
      return $theValue; 
    } 
    } 
    
    mysql_select_db($database_conn_dynamic, $conn_dynamic); 
    $query_rs_sidedata = "SELECT * FROM Members WHERE Zip = $thezip"; 
    $rs_sidedata = mysql_query($query_rs_sidedata, $conn_dynamic) or die(mysql_error()); 
    $row_rs_sidedata = mysql_fetch_assoc($rs_sidedata); 
    $totalRows_rs_sidedata = mysql_num_rows($rs_sidedata); 
    
    echo $row_rs_sidedata['City']; 
    echo " "; 
    echo $array[$x][0]; 
    echo " "; 
    echo round($array[$x][1], 1); 
    echo"<br>"; 
    $x++; 
    } 
    }
    Last edited by Markus; Oct 12 '10, 01:22 PM. Reason: Added [code] tags
  • JKing
    Recognized Expert Top Contributor
    • Jun 2007
    • 1206

    #2
    Echo your variable as shown below. What does it print to the screen?
    Code:
    while($x<count($array)) { 
    $thezip = $array[$x][0]; 
    echo "The zip: " . $thezip;

    Comment

    Working...