Jump to content

[SOLVED] PHP SQL search problem.. PLEASE HELP :-)


steve2007

Recommended Posts

Hello

 

Please can someone help me. I am trying to print a list from my sql database which will show counties and quantity of late deals.

 

example:-

France      (5)

Spain        (2)

USA          (5)

 

For some reason I'm only able to achieve the following result.

 

example:-

 

France    (5)

France    (2)

France    (5)

 

As you can see the below script is listing the quantities correctly however it is listing France for ever result.

 

{
$query = "SELECT 'country', COUNT(latedeals)  FROM properties WHERE latedeals NOT LIKE '' GROUP BY country ORDER BY RAND()
LIMIT 25"; 

$result = mysql_query($query) or die(mysql_error());

// Print out result
while($row = mysql_fetch_array($result)){
echo"	<table width=100% border=0 cellspacing=0 cellpadding=2><tr><td width=90>";
echo "$country";
echo"</td><td width=10%><div align=right> $latedeals";
echo "(". $row['COUNT(latedeals)'] .")";
echo "</div></td></tr></table>";

}
}

 

 

Any ideas why I can only list France as a country within the list???

 

Regards

 

Steve

Hello

 

Thanks for your response. I have changed the string to echo $row['country']; as you have recommended.

 

Now I am getting the following results.

 

Example

 

            (5)

            (2)

            (5)

 

 

I am missing the countries... any ideas????

 

Here is the edited script:

 

############################################################

 

 

Sorry...try again.... here's the updated code

 

##############################################################

 

{

$query = "SELECT 'country', COUNT(latedeals)  FROM properties WHERE latedeals NOT LIKE '' GROUP BY country ORDER BY RAND()

LIMIT 25";

 

$result = mysql_query($query) or die(mysql_error());

 

// Print out result

while($row = mysql_fetch_array($result)){

echo" <table width=100% border=0 cellspacing=0 cellpadding=2><tr><td width=90>";

echo $row['country'];

echo"</td><td width=10%><div align=right> $latedeals";

echo "(". $row['COUNT(latedeals)'] .")";

echo "</div></td></tr></table>";

 

}

}

I think all you need to do is get rid of some single quotes around 'country' in your query:

 

<?php
$query = "SELECT country, COUNT(latedeals)  FROM properties WHERE latedeals NOT LIKE '' GROUP BY country ORDER BY RAND()
LIMIT 25"; 
?>

 

When referring to table names, columns etc, you should either place nothing around the word, or use backticks(`). You'll need to use backticks if the name is a reserved word in mysql.

 

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.