Irish SEO,  Marketing & Webmaster Discussion

 
Make money - save the planet!

Duplicate content from sql query

This is a discussion on Duplicate content from sql query within the Coding Help forums, part of the Webmaster Help category; Hi everyone. I have some code that i have a little problem with..... I am trying to make a drop ...


Go Back   Irish SEO, Marketing & Webmaster Discussion > Webmaster Help > Coding Help

Register Forum Rules FAQDonate Members List Calendar Search Today's Posts Mark Forums Read


Notices

Reply

 

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 21-11-2007, 12:11 PM
Joseph Grogan's Avatar
Wannabe Geek
 
Join Date: Jul 2007
Location: Bogland, beside birr...Cloghan
Posts: 147
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
Joseph Grogan will become famous soon enough
Send a message via Skype™ to Joseph Grogan
Default Duplicate content from sql query

Hi everyone. I have some code that i have a little problem with.....

I am trying to make a drop down menu that populates its self from an mysql database. I have it populating the menu but alot of it is duplicate content.

It is selecting the country. So say people are irish and there are 5 irish people in the db it shows ireland 5 times. Is there any way around this..

Here is the code i am using
PHP Code:
<?php
// Include our login information
include('dbloginDetails.php');
// Connect
$connection mysql_connect$db_host$db_username$db_password );
if (!
$connection)
{
   die (
"Could not connect to the database: <br />"mysql_error());
}
// Select the database
$db_select=mysql_select_db($db_database);
if (!
$db_select)
{
   die (
"Could not select the database: <br />"mysql_error());
}
// Assign the query

//$query = "SELECT * FROM `entrants` WHERE country = 'ireland' AND postcode = '7'";
$query "SELECT * FROM `entrants` ";
//$query = "SELECT * FROM `entrants`";

// Execute the query
$result mysql_query$query );
if (!
$result)
{
   die (
"Could not query the database: <br />"mysql_error());
}
?>

<div align="center">
        <form name="form1" method="post" action="readingdatabase.php">
                <select name="country" id="country">
                    <?php
                    
                    
// Fetch and display the results
                    
while ($result_row mysql_fetch_row(($result)))
                    {
                            echo 
'<option>' .$result_row[9] . '</option>';
                    }
                    
//Close the connection
                    
mysql_close($connection);
                    
?>
                </select>
            <p align="center"><input type="submit" name="Submit" value="Submit Form"></p></td>
        </form>
</div>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #2 (permalink)  
Old 21-11-2007, 01:07 PM
Hardcore Geek
 
Join Date: Nov 2006
Location: Navan, Meath
Posts: 566
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
davidbehan is a name known to alldavidbehan is a name known to alldavidbehan is a name known to alldavidbehan is a name known to alldavidbehan is a name known to alldavidbehan is a name known to all
Send a message via Skype™ to davidbehan
Default

Use:

SELECT DISTINCT

See here:

SQL SELECT Statement

Rgds, Dave
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3 (permalink)  
Old 21-11-2007, 01:20 PM
Joseph Grogan's Avatar
Wannabe Geek
 
Join Date: Jul 2007
Location: Bogland, beside birr...Cloghan
Posts: 147
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
Joseph Grogan will become famous soon enough
Send a message via Skype™ to Joseph Grogan
Default

Thanks dave. Still the same thing though..... I will keep playing around with it. I propably missed something
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4 (permalink)  
Old 21-11-2007, 01:30 PM
ziycon's Avatar
Wannabe Geek
 
Join Date: Jan 2007
Location: Dublin
Posts: 410
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
ziycon will become famous soon enough
Send a message via MSN to ziycon Send a message via Skype™ to ziycon
Default

Quote:
Originally Posted by Joseph Grogan View Post
Thanks dave. Still the same thing though..... I will keep playing around with it. I propably missed something
After the 'WHERE' bit of your statement add 'GROUP BY country'.
PHP Code:
query "SELECT * FROM entrants WHERE country = 'ireland' AND postcode = '7' GROUP BY country"
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5 (permalink)  
Old 21-11-2007, 01:37 PM
Joseph Grogan's Avatar
Wannabe Geek
 
Join Date: Jul 2007
Location: Bogland, beside birr...Cloghan
Posts: 147
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
Joseph Grogan will become famous soon enough
Send a message via Skype™ to Joseph Grogan
Default

Once i put DISTINCT in anywhere absolutly nothing shows up.....
This is the query i trying now.

PHP Code:
$query "SELECT DISTINCT country FROM entrants"
The only query that works is
PHP Code:
$query "SELECT * FROM `entrants`"
but it displays all countries numerious times
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6 (permalink)  
Old 21-11-2007, 01:44 PM
ziycon's Avatar
Wannabe Geek
 
Join Date: Jan 2007
Location: Dublin
Posts: 410
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
ziycon will become famous soon enough
Send a message via MSN to ziycon Send a message via Skype™ to ziycon
Default

Quote:
Originally Posted by Joseph Grogan View Post
Once i put DISTINCT in anywhere absolutly nothing shows up.....
This is the query i trying now.

PHP Code:
$query "SELECT DISTINCT country FROM entrants"
The only query that works is
PHP Code:
$query "SELECT * FROM `entrants`"
but it displays all countries numerious times
Did you try:
PHP Code:
$query "SELECT country FROM entrants GROUP BY country"
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #7 (permalink)  
Old 21-11-2007, 01:47 PM
Joseph Grogan's Avatar
Wannabe Geek
 
Join Date: Jul 2007
Location: Bogland, beside birr...Cloghan
Posts: 147
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
Joseph Grogan will become famous soon enough
Send a message via Skype™ to Joseph Grogan
Default

Yep....

No idea whats going on. If i try specify anything nothing shows up. Just the *(everything) statement works....

I am baffiled
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #8 (permalink)  
Old 21-11-2007, 01:53 PM
ziycon's Avatar
Wannabe Geek
 
Join Date: Jan 2007
Location: Dublin
Posts: 410
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
ziycon will become famous soon enough
Send a message via MSN to ziycon Send a message via Skype™ to ziycon
Default

If you look closey at your code in the OP there is two types of commas, which will give you problems, make sure you replace all the commas with '.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #9 (permalink)  
Old 21-11-2007, 01:53 PM
Joseph Grogan's Avatar
Wannabe Geek
 
Join Date: Jul 2007
Location: Bogland, beside birr...Cloghan
Posts: 147
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
Joseph Grogan will become famous soon enough
Send a message via Skype™ to Joseph Grogan
Default

Got it working if i use
PHP Code:
$query "SELECT * FROM `entrants` GROUP BY country"
it works.

so putting the
PHP Code:
country 
in instead of the
PHP Code:

made it act funny and the GROUP BY made all the countries one..


Cheers for the help... Much appriciated
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Tags
content, duplicate, query, sql

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads

Thread Thread Starter Forum Replies Last Post
Successful Site in 12 Months with Google Alone montyauto Webmaster Articles 11 18-02-2008 01:28 PM
Mobile Website and Duplicate content Fintan Search Engine Optimisation 9 26-09-2007 11:38 AM
SQL Query ziycon Coding Help 4 23-08-2007 09:22 PM
Question Regarding Duplicate Content Mirrored Sites and multiple TLD's Drang3d Search Engine Optimisation 4 31-03-2007 11:29 PM
Duplicate Content? blacknight Search Engine Optimisation 6 25-11-2006 10:51 AM


Sponsored links

Paid On Results


All times are GMT +1. The time now is 01:35 PM.


Powered by: vBulletin Version 3.7.3, Copyright ©2000 - 2008, Jelsoft Enterprises Limited.
Hosted in Ireland by Blacknight - Test your ISP |Irish Hosting Directory| Armchair.ie|Logo by Eden Web Design|Avatars by Afterglow |Latest Blog Entries | VPS HostingAd Management by RedTyger

Search Engine Friendly URLs by vBSEO 3.2.0