[Phpwm] mysql in() lists

Phil Beynon phil at infolinkelectronics.co.uk
Sun Oct 1 18:42:27 BST 2006


Hi all,

Is there a more efficient way of making in() list sql other than
concatenating them together?

Currently I'm doing this;

$sql = "select user_name from imageasset where user_name like
'%DUMMY_IMAGE.jpg'";
$cleanup = mysql_query($sql); if(!$cleanup){echo("<p>Error in select cleanup
dummy image E66 : " . mysql_error() . "</p>"); exit();}
if(mysql_num_rows($cleanup) >= 1){while($row =
mysql_fetch_array($cleanup,MYSQL_ASSOC)){$in_name = $in_name .
$row["user_name"] . "','";}
$in_name = substr_replace($in_name,"",(strlen($in_name)-3));}

which then results in a nice little string along the lines of;

username1.jpg','username2.jpg','username3.jpg','....usernamex.jpg','

The substr_replace just trims the last ',' off the end.
The % in the sql is because there is a random precursor sequence added to
the filenames.

This then gets used as;

$sql = "select user_name from Type_B_Image_Tracking where user_name like
'%DUMMY_IMAGE.jpg' and user_name not in('$in_name')";


Which all works fine, but just seems a bit long winded!


Phil




More information about the Phpwm mailing list