Jump to content

Recommended Posts

Hello, i have 2 problems, one that im at and the other one that i will get to :P

 

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?

Link to comment
https://forums.phpfreaks.com/topic/203562-limit-queries-and-checking-database/
Share on other sites

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.

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 :P thanks allot. Any suggestions on the first problem?

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;

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.