jkkenzie Posted October 29, 2008 Share Posted October 29, 2008 foreach($_POST['mycountries'] as $mo) mysql_select_db($database_app_conn, $app_conn); $getCountriesQry ="SELECT parameter FROM tbldata WHERE strCountry='".$mo."' ORDER BY strCountry"; $rs_countries = mysql_query($getCountriesQry, $app_conn) or die(mysql_error()); while($rows = mysql_fetch_assoc($rs_countries)) { $parameters[]=$rows['parameter']; echo $rows['parameter']; } } If i echo $mo i get results BUT when i echo $rows['parameter'];, am getting nothing at all. Regards jkkenzie Link to comment https://forums.phpfreaks.com/topic/130541-solved-not-getting-results/ Share on other sites More sharing options...
MasterACE14 Posted October 29, 2008 Share Posted October 29, 2008 try changing this... mysql_fetch_assoc to this... mysql_fetch_array remove this line... $parameters[]=$rows['parameter']; and double check that you have spelt parameter the same as its spelt in your database. Link to comment https://forums.phpfreaks.com/topic/130541-solved-not-getting-results/#findComment-677232 Share on other sites More sharing options...
jkkenzie Posted October 29, 2008 Author Share Posted October 29, 2008 I had forgotten to include the { mark after foreach statement Now its working BUT check this out: <?php if (isset($_POST['continue'])) { if ( $_POST['mycountries']==""){ echo "No Countries chosen"." <a href='chooseproject.php'>Try again</a>";}else { $countrieschoosen=""; $num=0; foreach($_POST['mycountries'] as $mo) { $list[] = $mo; $num++; } mysql_select_db($database_app_conn, $app_conn); $getCountriesQry ="SELECT parameter FROM tbldata WHERE strCountry IN ('".$list[$num]."') ORDER BY strCountry"; $rs_countries = mysql_query($getCountriesQry, $app_conn) or die(mysql_error()); while($rows = mysql_fetch_assoc($rs_countries)) { $parameters[]=$rows['parameter']; echo $rows['parameter']; } } } ?> my query ( SELECT parameter FROM tbldata WHERE strCountry IN ('".$list[$num].") needs each value i collected so that i can get parameters field value WHERE country was "whatever i got from my foreach statement" Any idea? Link to comment https://forums.phpfreaks.com/topic/130541-solved-not-getting-results/#findComment-677237 Share on other sites More sharing options...
bobbinsbro Posted October 29, 2008 Share Posted October 29, 2008 implode $list[] using (', ') as glue. this will give you a string of all countries, which you can place in the sql string. $getCountriesQry ="SELECT parameter FROM tbldata WHERE strCountry IN ('".implode("', '", $list)."') ORDER BY strCountry"; Link to comment https://forums.phpfreaks.com/topic/130541-solved-not-getting-results/#findComment-677239 Share on other sites More sharing options...
jkkenzie Posted October 29, 2008 Author Share Posted October 29, 2008 is this right? because am not getting any results.: mysql_select_db($database_app_conn, $app_conn); $getCountriesQry ="SELECT parameter FROM tbldata WHERE strCountry IN ('".implode("', '", $list)."') "; $rs_countries = mysql_query($getCountriesQry, $app_conn) or die(mysql_error()); while($rows = mysql_fetch_array($rs_countries)) { echo $rows['parameter']; } Link to comment https://forums.phpfreaks.com/topic/130541-solved-not-getting-results/#findComment-677246 Share on other sites More sharing options...
bobbinsbro Posted October 29, 2008 Share Posted October 29, 2008 looks ok to me... can you echo the result of implode and print_r($list) for me please Link to comment https://forums.phpfreaks.com/topic/130541-solved-not-getting-results/#findComment-677253 Share on other sites More sharing options...
jkkenzie Posted October 29, 2008 Author Share Posted October 29, 2008 this is what i get : 1. for echo $x=implode("', '",$list); i get: American Samoa', ' Andorra', ' Angola', ' Anguilla', ' Armenia', ' Canada 2.For echo print_r($list); i get: Array ( [0] => American Samoa [1] => Andorra [2] => Angola [3] => Anguilla [4] => Armenia [5] => Canada ) Link to comment https://forums.phpfreaks.com/topic/130541-solved-not-getting-results/#findComment-677260 Share on other sites More sharing options...
bobbinsbro Posted October 29, 2008 Share Posted October 29, 2008 i think the reason your not getting any results is that each of the name has a heading space in the implode string. i tested the implode code you use, and the space isn't introduced there. the space already exists in the $list array for some reason. i think mysql is told to search for countries that look like " American Samoa" instead of "American Samoa", so there are no results. changing $list[] = $mo; to $list[] = trim($mo); and check what happens. Link to comment https://forums.phpfreaks.com/topic/130541-solved-not-getting-results/#findComment-677264 Share on other sites More sharing options...
jkkenzie Posted October 29, 2008 Author Share Posted October 29, 2008 Good it works: Thanks Link to comment https://forums.phpfreaks.com/topic/130541-solved-not-getting-results/#findComment-677273 Share on other sites More sharing options...
bobbinsbro Posted October 29, 2008 Share Posted October 29, 2008 your welcom. glad i could help. please set topic to solved. Link to comment https://forums.phpfreaks.com/topic/130541-solved-not-getting-results/#findComment-677284 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.