Hi All,
I'm newish to php & have an issue on a project I'm working on...
I've an array containing zip codes which displays if I echo it like
it returns 926299262492693926779267592673926079267492672
I need to implode/explode with commas so it passes like 92629,92624,92693,92677,92675,92673,92607,92674,92 672 so I can use it as a WHERE IN condition.
What's the best way to do this?
Thanks
Karl
6 1876
Hi All,
I'm newish to php & have an issue on a project I'm working on...
I've an array containing zip codes which displays if I echo it like
it returns 926299262492693926779267592673926079267492672
I need to implode/explode with commas so it passes like 92629,92624,92693,92677,92675,92673,92607,92674,92 672 so I can use it as a WHERE IN condition.
What's the best way to do this?
Thanks
Karl
$key is not an array! The value you show via the "echo $key;" here is a normal string value. So you cannot plode it. Unless you have made a mistake
Ronald :cool:
Kinda new/part-time with php, learning every time I sit down with it, please excuse my ignorance.
OK, I guess I'm on the wrong path. I'll detail things a little...
I'm using a class for querying a single table zip code db. I'm adding a table of companies and making a company locator based on range from originating zip code.
I have - $z = new zipcode_class;
-
$zips = $z->get_zips_in_range($_POST["zip1"], $_POST["radius"], _ZIPS_SORT_BY_DISTANCE_ASC, true);
-
if ($zips === false) echo 'Error: '.$z->last_error;
-
else {
-
-
foreach ($zips as $key => $value) {
-
$query_rsTech = "SELECT * FROM tech_info WHERE tech_zip_code = '$key,'";
-
$rsTech = mysql_query($query_rsTech) or die(mysql_error());
-
$row_rsTech = mysql_fetch_assoc($rsTech);
-
}
-
}
Should I replace the foreach to $zips as $array then check with an is_array?
Thanks, learning as I go...
Karl
Can I make the string ($key) an array to use in a query, maybe?
Karl
vssp 268
Contributor
Count the total number and split the string 5 and the store the valus on single array I hope thsi idea is not bad.
I'm gonna try that... After iterating through the first array with - foreach ($zips as $key => value)
I need to split a string that looks like
926299262492693926779267592673926079267492672
into one that looks like
92629,92624,92693,92677,92675,92673,92607,92674,92 672
so it can be used in a WHERE clause.
I've been reading & trying diffrent things, no success yet.
Any suggestions?
Can we bounce this one? I re-started it under a more descriptive title.
Thanks,
Karl
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Andreas Paasch |
last post by:
I'm having trouble with the implode function and need some help here.
I've been reading at php.net but that didn't solve my problem.
I'm having the below code:
$query = "SELECT top1, top2,...
|
by: Geoff Berrow |
last post by:
I don't particularly need to do this but I've just found out that
print implode("<br>", $_SERVER);
Gives the warning :
Notice: Array to string conversion in c:\phpdev\www...
Doesn't do it...
|
by: DJ Craig |
last post by:
I have 2-dimensional array with numeric indices for both dimensions,
called $results, which contains the search results from a database.
The first dimension contains the records, and the second...
|
by: ben3003 |
last post by:
I am trying to put a date in my database in the form dd-mm-yyy, as for
my PHP page is returns 3 variables $date, $month, $year. is ther a way
to put these together? i have tried imploding them but...
|
by: Maksim Kasimov |
last post by:
in php-scripts, to insert data to database, i'm doing like this:
...
$query_param = array(
'field0' => 1,
'field1' => 3,
'field2' => $var2,
'field3' => $var3,
);
...
| |
by: NoWhereMan |
last post by:
Maybe a stupid question.
-------------------------
1
-------------------------
$str = '';
for($i=0; $i<10; $i++)
$str .= $i;
|
by: scatfly |
last post by:
I have a set of values that were put into a form and am now using this to put into a database. this is my error:
"Warning: implode() : Bad arguments. in /home/xxxxxx/public_html/login.php on line...
|
by: atyndall |
last post by:
OK, this is the relevant portion script:
<?php
$username = '__'; // MySQL Database Username.
$password = '__'; // MySQL Database Password.
$server = '__'; // MySQL Database server (most...
|
by: BryanA |
last post by:
I'm not quite sure which function to use when I want to add a comma to
the end of every line and a semi colon to the last one. Because it
generates everything on the fly I can't count the rows from...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |