AV1611 Posted June 22, 2006 Share Posted June 22, 2006 I can't figure out how to query against an array...(MySQL/PHP)this gives no result (I know the pn's are good)[code]$list=array("900.026","900.859","900.809","900.669","900.667"); $result = mysql_query("SELECT * FROM crosslist WHERE TPN in ('$list')")or die(mysql_error()); while ($row=mysql_fetch_array($result)) { echo $row['TPN']." ".STR_PAD($row['TPN'],8,"0",STR_PAD_LEFT)."<br/>";; }[/code]Table structure if you want it...# Table "crosslist" DDLCREATE TABLE `crosslist` ( `CUST` varchar(8) NOT NULL default '', `CPN` varchar(16) NOT NULL default '', `CREV` varchar(9) NOT NULL default '', `TPN` varchar(15) NOT NULL default '', KEY `second` (`TPN`)) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='InnoDB free: 219136 kB; InnoDB free: 206848 kB; InnoDB free:' Quote Link to comment https://forums.phpfreaks.com/topic/12643-syntax-error/ Share on other sites More sharing options...
shoz Posted June 22, 2006 Share Posted June 22, 2006 [code]<?php$list=array("900.026","900.859","900.809","900.669","900.667");$list = '"'.implode('","',$list).'"';$result = mysql_query("SELECT * FROM crosslist WHERE TPN in ($list)") or die(mysql_error());while ($row=mysql_fetch_array($result)){ echo $row['TPN']." ".STR_PAD($row['TPN'],8,"0",STR_PAD_LEFT)."<br/>";;}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/12643-syntax-error/#findComment-48504 Share on other sites More sharing options...
AV1611 Posted June 22, 2006 Author Share Posted June 22, 2006 So, without the implode, I was seeing the array, not the contents of the array?[!--quoteo(post=386874:date=Jun 22 2006, 12:11 PM:name=shoz)--][div class=\'quotetop\']QUOTE(shoz @ Jun 22 2006, 12:11 PM) [snapback]386874[/snapback][/div][div class=\'quotemain\'][!--quotec--][code]<?php$list=array("900.026","900.859","900.809","900.669","900.667");$list = '"'.implode('","',$list).'"';$result = mysql_query("SELECT * FROM crosslist WHERE TPN in ($list)") or die(mysql_error());while ($row=mysql_fetch_array($result)){ echo $row['TPN']." ".STR_PAD($row['TPN'],8,"0",STR_PAD_LEFT)."<br/>";;}?>[/code][/quote] Quote Link to comment https://forums.phpfreaks.com/topic/12643-syntax-error/#findComment-48545 Share on other sites More sharing options...
shoz Posted June 22, 2006 Share Posted June 22, 2006 [quote]So, without the implode, I was seeing the array, not the contents of the array?[/quote]The array is evaluated inside of the string to become the string "Array" because PHP converts it to that.[a href=\"http://www.php.net/manual/en/language.types.string.php#language.types.string.casting\" target=\"_blank\"]String Conversion[/a]Implode() is used to put the contents of the array in a string that you can use in the query. Quote Link to comment https://forums.phpfreaks.com/topic/12643-syntax-error/#findComment-48574 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.