claro Posted October 24, 2011 Share Posted October 24, 2011 I'm having a branching queries. I stored array in $course, is that possible? $course = array($_POST['course']); mysql_query (SELECT * FROM tbl_name WHERE course_Id = '$course') Quote Link to comment https://forums.phpfreaks.com/topic/249692-is-this-okay/ Share on other sites More sharing options...
claro Posted October 24, 2011 Author Share Posted October 24, 2011 $course = array ($_POST['course']); mysql_query ("SELECT * FROM tbl_course WHERE course_Id = '$course'") or die (mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/249692-is-this-okay/#findComment-1281727 Share on other sites More sharing options...
WebStyles Posted October 24, 2011 Share Posted October 24, 2011 not really... since you're searching for a specific course_id in your database, I'm assuming $_POST['course'] is just a number (or a reference) and therefor, does not need to be converted into an array. if(isset($_POST['course']){ $course = trim($_POST['course']); mysql_query ("SELECT * FROM tbl_course WHERE course_Id = '$course'") or die (mysql_error()); //... rest of database request }else{ echo 'No course selected.'; } Quote Link to comment https://forums.phpfreaks.com/topic/249692-is-this-okay/#findComment-1281730 Share on other sites More sharing options...
claro Posted October 24, 2011 Author Share Posted October 24, 2011 I'm so sorry, I think I didnt explain myself well. It should not be course_Id, course_Title instead, I want to select all files FRom tb_course where course_Title is the selected arrays..what if I have two or more course_Title selected. THank you for your response by the way. Quote Link to comment https://forums.phpfreaks.com/topic/249692-is-this-okay/#findComment-1281732 Share on other sites More sharing options...
WebStyles Posted October 24, 2011 Share Posted October 24, 2011 in that case, you need something like this: // this grabs each title and creates a string with each one wrapped in single quotes $titles = "'".implode("','",$_POST['course'])."'"; // use the mysql IN command to check all the titles at once. Change course_title to your REAL field name mysql_query ("SELECT * FROM tbl_course WHERE course_title IN ($titles)"); Quote Link to comment https://forums.phpfreaks.com/topic/249692-is-this-okay/#findComment-1281733 Share on other sites More sharing options...
trq Posted October 24, 2011 Share Posted October 24, 2011 $_POST is already an array, why are you passing it to the array function? As for your query. SQL is a language written in text. Text requires strings, not arrays. Quote Link to comment https://forums.phpfreaks.com/topic/249692-is-this-okay/#findComment-1281738 Share on other sites More sharing options...
WebStyles Posted October 24, 2011 Share Posted October 24, 2011 (what happened to the other post? I just answered this same question twice, and it seems to have disappeared from the forum.) Quote Link to comment https://forums.phpfreaks.com/topic/249692-is-this-okay/#findComment-1281741 Share on other sites More sharing options...
claro Posted October 25, 2011 Author Share Posted October 25, 2011 Many thanks! Quote Link to comment https://forums.phpfreaks.com/topic/249692-is-this-okay/#findComment-1281966 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.