Jump to content

[SOLVED] Not getting results


jkkenzie

Recommended Posts

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

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?

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'];
			  }    

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 )

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.