hassank1 Posted March 28, 2008 Share Posted March 28, 2008 I've got an error executing this script !! I don't know what's wrong !! $StudyGroups=array( 'Arts & Design', 'Engineering', 'Education', 'Communication Arts', 'Computer', 'Business', 'Pharmacy', 'sciences', 'Lab Reports (Engineering)', 'Lab Reports (Sciences)' ); $GetStudyGroups_Query="select GroupID,GroupName from groups where GroupName IN $StudyGroups "; $StudyGroups_Result=mysql_query($GetStudyGroups_Query); echo mysql_num_rows($StudyGroups_Result);exit(); Link to comment https://forums.phpfreaks.com/topic/98382-why-this-is-not-working/ Share on other sites More sharing options...
dezkit Posted March 28, 2008 Share Posted March 28, 2008 <? $StudyGroups=array( 'Arts & Design', 'Engineering', 'Education', 'Communication Arts', 'Computer', 'Business', 'Pharmacy', 'sciences', 'Lab Reports (Engineering)', 'Lab Reports (Sciences)' ); $GetStudyGroups_Query="select GroupID,GroupName from groups where GroupName IN $StudyGroups "; $StudyGroups_Result=mysql_query($GetStudyGroups_Query); echo mysql_num_rows($StudyGroups_Result);exit(); ?> Link to comment https://forums.phpfreaks.com/topic/98382-why-this-is-not-working/#findComment-503479 Share on other sites More sharing options...
hassank1 Posted March 28, 2008 Author Share Posted March 28, 2008 it is still the same !! Link to comment https://forums.phpfreaks.com/topic/98382-why-this-is-not-working/#findComment-503484 Share on other sites More sharing options...
alecks Posted March 28, 2008 Share Posted March 28, 2008 what is the error, that you are getting... Link to comment https://forums.phpfreaks.com/topic/98382-why-this-is-not-working/#findComment-503486 Share on other sites More sharing options...
Barand Posted March 28, 2008 Share Posted March 28, 2008 <?php $groupList = join ("','", $studyGroups); $GetStudyGroups_Query="select GroupID,GroupName from groups where GroupName IN ('$groupList'); "; Link to comment https://forums.phpfreaks.com/topic/98382-why-this-is-not-working/#findComment-503487 Share on other sites More sharing options...
hassank1 Posted March 28, 2008 Author Share Posted March 28, 2008 <?php $groupList = join ("','", $studyGroups); $GetStudyGroups_Query="select GroupID,GroupName from groups where GroupName IN ('$groupList'); "; thanks it worked however,why my previous code didn't work ? and what the above code means (join() !! ) ? Link to comment https://forums.phpfreaks.com/topic/98382-why-this-is-not-working/#findComment-503489 Share on other sites More sharing options...
Barand Posted March 28, 2008 Share Posted March 28, 2008 if you have $ar = array ('A'. 'B', 'C'); then join (',' , $ar) returns "A,B,C" (the array elements separated by a comma). For your query you needed .... IN ('A','B','C') , with quotes, so I joined the elements with "','" www.php.net/join Link to comment https://forums.phpfreaks.com/topic/98382-why-this-is-not-working/#findComment-503494 Share on other sites More sharing options...
hassank1 Posted March 28, 2008 Author Share Posted March 28, 2008 ok thx . SOLVED Link to comment https://forums.phpfreaks.com/topic/98382-why-this-is-not-working/#findComment-503499 Share on other sites More sharing options...
Barand Posted March 28, 2008 Share Posted March 28, 2008 however,why my previous code didn't work ? try doing it your way and echo $GetStudyGroups_Query; then echo my query. Link to comment https://forums.phpfreaks.com/topic/98382-why-this-is-not-working/#findComment-503506 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.