I am trying to use an array to query my db.
The following code displays one provinces data. -
-
$sql = 'SELECT * FROM `person` WHERE `Province` = CONVERT(_utf8 \'ON \' USING latin1) COLLATE latin1_swedish_ci AND `IsJudge` =1' . ' ORDER BY LastName, Firstname';
-
$result = $link->query($sql)or die( $link->error );
-
If I make an array like so; -
$provinces = array("BC","AB","SK","MB","ON","QC","NB","NS");
-
-
foreach( $provinces as $province )
-
{
-
# then change query like so
-
$sql = 'SELECT * FROM `person` WHERE `Province` = CONVERT(_utf8 \' "$province" \' USING latin1) COLLATE latin1_swedish_ci AND `IsJudge` =1' . ' ORDER BY LastName, Firstname';
-
$result = $link->query($sql)or die( $link->error );
-
}
-
I get no data back. Any ideas?
I got the answer ... changed code to; -
$sql = "SELECT * FROM person WHERE Province='" . $province . "' AND IsJudge=1 ORDER BY Lastname, FirstName";
-
and BobsURuncle, works just fine.
TNX
Bob
1 1164 Luuk 1,047
Expert 1GB
This wil eliminate the need for 'foreach()' -
$p = "";
-
$provinces = array("BC","AB","SK","MB","ON","QC","NB","NS");
-
while ( count($provinces)>0 ){ $p.=array_shift($provinces).","; }
-
$p = substr($p,0,strlen($p)-1);
-
$sql = 'SELECT * FROM `person` WHERE `Province` IN ('.$p.') AND `IsJudge` =1' . ' ORDER BY LastName, Firstname';
-
Sign in to post your reply or Sign up for a free account.
Similar topics
by: madsgormlarsen |
last post by:
Hi
I need to test a field(colum) in a SQL database for for NULL values,
and have done so in this way.
$query = "SELECT j FROM Andersen";
$result = mysql_query($query, $link_id);
$query_data...
|
by: Dan Baker |
last post by:
I'm trying to write a stand-alone application which will
query the contact database used in Outlook (or maybe
Exchange Server). I have no idea where to start
looking. Any advice?
Dan Baker
|
by: JC Voon |
last post by:
Hi All:
I'm new in Threading and Web Services, can someone please verify my
code, i'm not sure whether this is the correct way, althought it is
partially work, but some time it will raise...
|
by: Learner |
last post by:
Hi there,
I have installed Sql server 2005 developer on my machine which
already has a Sql server 2000 installed on. Now i am trying to query
the Sqlserver 2005 data(Ex: from Person.Address...
|
by: Allen Anderson |
last post by:
Hi,
I'm trying to design contact (names and addresses) tables in an Access
database. Some of the contacts represent vendors, some are board members of
the organization, some are donors, some...
|
by: gwb |
last post by:
I am new to database queries. I am using access, trying to query my database where the field memberdate is less than 31 days old. I thought maybe the DateDiff function would work but I'm not sure how...
|
by: Francis S |
last post by:
$record= array(
"product"=>array(
array("name"=>"apple","price"=>30.5),
array("name"=>"orange","price"=>20)
)
);
echo array_read($record, "") //out 30.5
print_r (array_read($record, ""))...
|
by: shelzmike |
last post by:
To start with, let me lay out the situation. I am a student at the very end of my last assignment of a beginner - intermediate VB class (we have been using VB 2005 Express + MSSQL Express 2005)....
|
by: DavidPr |
last post by:
I'm trying to do this:
$query = "SELECT * FROM response WHERE recipe_id='$file' AND allow='1'";
$result = mysql_query($query) or trigger_error("Query: $query\n<br>MySQL Error: " . mysql_error());...
|
by: rahulephp |
last post by:
Hi there,
can you please help me?
i have data in array and i want to insert it in a single table.
structure of table and array to be store is shown below:
Please let me know how to store...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
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...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
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...
|
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...
| |