473,378 Members | 1,658 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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.


Expand|Select|Wrap|Line Numbers
  1. require("zipcode.php"); 
  2.  
  3.  
  4. $zip1 = $HTTP_GET_VARS['zip1']; 
  5. $radius = $HTTP_GET_VARS['radius']; 
  6.  
  7. if($radius !=""){ 
  8. $array = close_zipcodes($zip1,$radius,"M"); 
  9. $x=0; 
  10.  
  11. while($x<count($array)) { 
  12. $thezip = $array[$x][0]; 
  13.  
  14. if (!function_exists("GetSQLValueString")) { 
  15. function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
  16.   $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; 
  17.  
  18.   $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); 
  19.  
  20.   switch ($theType) { 
  21.     case "text": 
  22.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; 
  23.       break;     
  24.     case "long": 
  25.     case "int": 
  26.       $theValue = ($theValue != "") ? intval($theValue) : "NULL"; 
  27.       break; 
  28.     case "double": 
  29.       $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; 
  30.       break; 
  31.     case "date": 
  32.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; 
  33.       break; 
  34.     case "defined": 
  35.       $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; 
  36.       break; 
  37.   } 
  38.   return $theValue; 
  39.  
  40. mysql_select_db($database_conn_dynamic, $conn_dynamic); 
  41. $query_rs_sidedata = "SELECT * FROM Members WHERE Zip = $thezip"; 
  42. $rs_sidedata = mysql_query($query_rs_sidedata, $conn_dynamic) or die(mysql_error()); 
  43. $row_rs_sidedata = mysql_fetch_assoc($rs_sidedata); 
  44. $totalRows_rs_sidedata = mysql_num_rows($rs_sidedata); 
  45.  
  46. echo $row_rs_sidedata['City']; 
  47. echo " "; 
  48. echo $array[$x][0]; 
  49. echo " "; 
  50. echo round($array[$x][1], 1); 
  51. echo"<br>"; 
  52. $x++; 
  53. }
Oct 12 '10 #1
1 1553
JKing
1,206 Expert 1GB
Echo your variable as shown below. What does it print to the screen?
Expand|Select|Wrap|Line Numbers
  1. while($x<count($array)) { 
  2. $thezip = $array[$x][0]; 
  3. echo "The zip: " . $thezip;
  4.  
Oct 12 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Stephen | last post by:
I was wondering if someone could please help me with an array I'd like to create in an asp.net page. I have to design an array which stores the values of addresses manually entered into textboxes...
1
by: ferky | last post by:
I have this code below when I asign strOldTkinit = strNewTkinit and then read the new value for the strNewTkinit from the recordset the strOldTkinit changes the value also. So when I run my...
12
by: Martien van Wanrooij | last post by:
I have been using for a while a class to create photo albums. Shortly, an array of photo's is declared, initially they are shown as thumbnails, by clicking on a thumbnail a larger photo is shown...
13
by: delram | last post by:
Hello All! I've been struggling with this problem for a while. I have a database from which I need to read and display some data on a browser. (The database is set up for remote access). ...
12
luke14free
by: luke14free | last post by:
Hello, i have projected a page for voting my website, i have created a mysql tab with 2 INT fields (total votes and number of voters) and an id (working). Now I have problems running this code, why?...
0
by: Nolanclark | last post by:
Hi there. I've read a previous thread regarding the Old VB 6 checkbox array and how it's not really needed any more. That's fine, but I'm not really sure how to implement the checkbox control array...
0
by: anuptosh | last post by:
Hi, I have been trying to run the below example to get a Oracle Array as an output from a Java code. This is an example I have found on the web. But, the expected result is that the code should...
6
by: SeeMe | last post by:
i want to ask, is it my coding got problem? Because when i run my program that can't be insert in mysql. cn some body let me noe my mistake? thanks include("php_library/connect.php"); $tablename =...
16
by: haft | last post by:
I have posted this question on a javascript forum as it contains javascript code however it was believed to be an asp issue. The following head section javascript code contains the function...
6
by: tc18a | last post by:
I'm looking for a fast algorithm for sorting an array of integers with respect to a master list. For example: Master List: 7 3 9 1 32 6 5 4 99 100 201 13 Array that needs to be sorted array1:...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.