Wrox Programmer Forums
|
BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6
This is the forum to discuss the Wrox book Beginning PHP, Apache, MySQLWeb Development by Michael K. Glass, Yann Le Scouarnec, Elizabeth Naramore, Gary Mailer, Jeremy Stolz, Jason Gerner; ISBN: 9780764557446
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 6th, 2005, 01:04 AM
Authorized User
 
Join Date: Jul 2004
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to vinodkalpaka Send a message via Yahoo to vinodkalpaka
Default compare array with coma seperated table fileld

Hello,

I have an array(in php) with id's of cities, like 1 for city1,2 for city2,3 for city3
In the database table field , one particular row contains a coma seperated field which have the name city_id.(varchar) for example ,1,2,3,4,5,6,7 .

Here is my problem. How can I compare the array value with the field value in a single query. I know that, if this php variable is not an array, I can use the keyword 'like' .(example - SELECT * FROM TABLE1 WHERE city_id like '%variablename%') But what I have to with an array? I am using MySQL 4.0.18-nt. Please help me.

Thanking in advance,
From,
Vinod

 
Old April 23rd, 2005, 10:41 AM
Registered User
 
Join Date: Apr 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hope this helps..

$query = "SELECT * FROM TABLE1 WHERE ";
$flag = 0;
foreach($city_array as $cid) {
  if($flag)
    $query .= " AND "; // or OR
  else
    $flag = 1;
  $query .= "city_id like '%$cid%'";
}

there should be a better way to do this






Similar Threads
Thread Thread Starter Forum Replies Last Post
string compare in table field alxtech SQL Server 2000 1 April 27th, 2007 12:25 AM
Compare two table - Find missing record lawsoncobol Access VBA 5 August 4th, 2006 01:18 AM
Sort by a value that's a comma seperated list medic XSLT 0 June 7th, 2006 09:52 AM
need comma seperated values in select atulmar SQL Server 2000 2 April 12th, 2005 07:01 PM
Compare FE table with same BE version of table amerk20 Access VBA 5 November 29th, 2004 04:51 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.