PDA

View Full Version : find_in_set


sabret00the
07-21-2005, 10:43 PM
can someone run through this with me please?
if ($do == "step3" AND $_GET['sectionid'] AND $_GET['category'])
{
globalize($_GET, array(
'do' => STR,
'agree' => STR,
'sectionid' => INT,
'category' => INT,
'goto'
));

$sectionid = intval(trim($sectionid));
$category = intval(trim($category));
// make style dropdown
$getstyles = $DB_site->query("
SELECT *
FROM prs_styles
WHERE FIND_IN_SET($category,catid)
ORDER BY catid ASC
");
echo("
SELECT *
FROM prs_styles
WHERE FIND_IN_SET($category,catid)
ORDER BY catid ASC
");

$style_dropdown = "<option value=\"0\">Select A Style</option>\n";
$style['description'] = "Please select the style you feel best suits the piece you're about to submit.";
$thetext1 = "thetext1[0]=\"" . $style[description] . "\"\n";
$thetextcount = 1;
while ($style = $DB_site->fetch_array($getstyles))
{
echo $style[description] . "<hr />";
$style_dropdown .= "\t\t\t\t\t\t\t\t<option value=\"$style[styleid]\">$style[stylename]</option>\n";
$thetext1 .= "\t\t\t\t\t\tthetext1[" . $thetextcount++ . "]=\"" . $style[description] . "\"\n";
}
eval('$prs_main = "' . fetch_template('prs_submit_styles') . '";');
}

catid is either a solo number or a string "35 454 9845 908432 930483409 23434" shouldn't find_in_set do this perfectly?

Paul M
07-22-2005, 12:28 AM
FIND_IN_SET(<string>, <list>) looks for <string> in the comma seperated <list> of items, and returns its position in the list (or 0, or null) - this doesn't seem to be what you are doing ?

sabret00the
07-22-2005, 09:13 AM
nope i'm trying to do a select based on the existence of a <string> in a <list> kinda like a while

so "SELECT * FROM prs_styles WHERE FIND_IN_SET(1, 1 5 10 15 20 25 30) ORDER BY catid ASC" is supposed to return a list of all rows which contain '1'.

$getstyles = $DB_site->query("
SELECT *
FROM prs_styles
WHERE catid LIKE '$category %' OR catid LIKE '% $category %' OR catid LIKE '% $category' OR catid = $category
ORDER BY catid ASC
"); is the fix i've ended up going for.