Tiltan Posted June 1, 2010 Share Posted June 1, 2010 Hello, i have 2 problems, one that im at and the other one that i will get to I have a database with country names, each name can appear several times in the database. I want to use the database to create a dropdown menu but i dont know how to limit each country to appear just once. There is probobly a simple solution, i just havent evolved to that level and If i have a database with names: BartJacksson BartSimpsson MargeSimpsson HomerSimpsson Entry: 1 Bart Entry: 2 Simpsson is there a way to check if entry 1 and 2 exists in the databse (together) Bart and Simpsson should be allowed seperate but when entered together they should not be allowed (since they are allready in the database) im not sure if simple: if $"Entry: 1" == "bart" && $"Entry: 2" == "Simpsson" would work since that would simply check if any bart or simpsson exists right? Quote Link to comment https://forums.phpfreaks.com/topic/203562-limit-queries-and-checking-database/ Share on other sites More sharing options...
premiso Posted June 1, 2010 Share Posted June 1, 2010 SELECT first_name, last_name FROM table_name WHERE first_name = 'bart' AND last_name = 'simpson' And if you get a record back, the name is already in the database. If no records are returned, then the name combination is not in the database. Quote Link to comment https://forums.phpfreaks.com/topic/203562-limit-queries-and-checking-database/#findComment-1066304 Share on other sites More sharing options...
Tiltan Posted June 1, 2010 Author Share Posted June 1, 2010 SELECT first_name, last_name FROM table_name WHERE first_name = 'bart' AND last_name = 'simpson' And if you get a record back, the name is already in the database. If no records are returned, then the name combination is not in the database. aah yes ofc thanks allot. Any suggestions on the first problem? Quote Link to comment https://forums.phpfreaks.com/topic/203562-limit-queries-and-checking-database/#findComment-1066314 Share on other sites More sharing options...
jcbones Posted June 1, 2010 Share Posted June 1, 2010 I have a database with country names, each name can appear several times in the database. I want to use the database to create a dropdown menu but i dont know how to limit each country to appear just once. There is probobly a simple solution, i just havent evolved to that level. $sql = "SELECT DISTINCT country FROM table ORDER BY country ASC"; And if you have trouble with that query (Sometimes DISTINCT doesn't like the ORDER BY clause). Try. SELECT DISTINCT country FROM (table INNER JOIN table AS t ON table.id=t.id) ORDER BY country DESC; Quote Link to comment https://forums.phpfreaks.com/topic/203562-limit-queries-and-checking-database/#findComment-1066336 Share on other sites More sharing options...
Tiltan Posted June 2, 2010 Author Share Posted June 2, 2010 Thanks, seems to be working just fine Quote Link to comment https://forums.phpfreaks.com/topic/203562-limit-queries-and-checking-database/#findComment-1066854 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.