Help - Creating a query using specific colums

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
mhouldridge
Forum Contributor
Posts: 267
Joined: Wed Jan 26, 2005 5:13 am

Help - Creating a query using specific colums

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
User avatar
mhouldridge
Forum Contributor
Posts: 267
Joined: Wed Jan 26, 2005 5:13 am

Post 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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
User avatar
mhouldridge
Forum Contributor
Posts: 267
Joined: Wed Jan 26, 2005 5:13 am

Post by mhouldridge »

Ok -

Do you know how I could carry out the query using my existing database structure?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

most often, it comes to querying the table for it's structure and filtering out all unwanted columns that way..
Post Reply