Jump to content

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.

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.