Page 1 of 1

Help - Creating a query using specific colums

Posted: Fri Sep 02, 2005 8:19 am
by mhouldridge
Hi,

I need to create a query taking specific colum data (IP, IP1, IP2, IP3 etc.) within my database however I do not know how to do this. Here is my code so far and explainations;

Code: Select all

$db = mysql_connect("localhost","","") or die("Problem connecting");
mysql_select_db("audit") or die("Problem selecting database");

$ips =  //this sets the variable to all of the IP colums withi nthe database
$query = "SELECT '$ips' FROM dedicated"; //$query looks through the ips
$result = mysql_query($query) or die ("Query failed"); //$result holds all of the found IP addresses 
$numofrows = mysql_num_rows($result); //Counts number of rows from $result

I will eventually output the data using an echo statement.

As always, any help would be greatly appreciated.

Posted: Fri Sep 02, 2005 8:22 am
by feyd
is there a reason your table design isn't normalized? i.e. having unknown multiple columns storing the same type of information often isn't best practice.

Posted: Fri Sep 02, 2005 8:32 am
by mhouldridge
Er, good point.

I havent really looked into database normalisation yet.... however I will be doing that shortly no doubt.

To normalise this sort of thing, would it be best to have created a seperate table called IPs?

Posted: Fri Sep 02, 2005 8:36 am
by feyd
a table where each row contains a single IP is most flexible. If this existing table holds other information, then yes, a seperate table is preferred, with a linking field that points to which row in the existing table the IP relates to.

Posted: Fri Sep 02, 2005 8:44 am
by mhouldridge
Ok -

Do you know how I could carry out the query using my existing database structure?

Posted: Fri Sep 02, 2005 9:06 am
by feyd
most often, it comes to querying the table for it's structure and filtering out all unwanted columns that way..