project3 Posted March 4, 2008 Share Posted March 4, 2008 I have a function using case. Can I loop through the case's and fill that in with the db loop. function &getSortScheme($sortBy){ switch($sortBy){ case 'PriceHiLo': return 'myPrice desc'; break; case 'PriceLoHi': return 'myPrice asc'; break; case '': return 'sort_order asc'; break; default; return 'sortOrder, pName, myPrice'; break; } } Now what i want to do is have a sql statement and fill in more of the case like. $query = "SELECT DISTINCT ds_products.pID, ds_products.foodcat, ds_product_categories.pID, ds_product_categories.catID FROM ds_products, ds_product_categories WHERE (ds_products.pID = ds_product_categories.pID) AND ds_product_categories.catID = '$c' GROUP BY foodcat"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $foodcat = $row['foodcat']; case "$foodcat": return "$foodcat"; break; } Quote Link to comment Share on other sites More sharing options...
haku Posted March 4, 2008 Share Posted March 4, 2008 Your question wasn't that clear, but if I understand what you are asking, then yes you can do that. Did you try it out before asking? Please use code tags when posting code in the futre. Its the # button above the little smilies when you are typing your post. Quote Link to comment Share on other sites More sharing options...
project3 Posted March 4, 2008 Author Share Posted March 4, 2008 Yes I tried it out it doesn't work. I get an error. Parse error: syntax error, unexpected T_CASE function &getSortScheme($sortBy){ switch($sortBy){ case 'PriceHiLo': return 'myPrice desc'; break; case 'PriceLoHi': return 'myPrice asc'; break; case '': return 'sort_order asc'; break; case "Rolls": return "Rolls"; break; $c = $_REQUEST["c"]; $query = "SELECT DISTINCT ds_products.pID, ds_products.foodcat, ds_product_categories.pID, ds_product_categories.catID FROM ds_products, ds_product_categories WHERE (ds_products.pID = ds_product_categories.pID) AND ds_product_categories.catID = '$c' GROUP BY foodcat"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $foodcat = $row['foodcat']; case "$foodcat:"; return "$foodcat"; break; } Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted March 4, 2008 Share Posted March 4, 2008 which line? ??? Quote Link to comment Share on other sites More sharing options...
project3 Posted March 4, 2008 Author Share Posted March 4, 2008 which line? ??? { $foodcat = $row['foodcat']; >>THIS LINE ERRORS>> case "$foodcat:"; return "$foodcat"; break; } Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted March 4, 2008 Share Posted March 4, 2008 cant have a variable in a case name that is why Quote Link to comment Share on other sites More sharing options...
project3 Posted March 4, 2008 Author Share Posted March 4, 2008 cant have a variable in a case name that is why Cool thanks. I just quit trying to use the variables and just manually put in the values all work ok now. Thank you very much darkfreaks!! Quote Link to comment 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.