PHP/Mysql question

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
MJennings
Forum Newbie
Posts: 1
Joined: Mon Sep 06, 2010 2:40 am

PHP/Mysql question

Post by MJennings »

Hi. I wrote a simple script to grab information out of a database for ips on my home network. Right now my page just grabs every row, every column from the db and prints it in a html table.. very simple. Now I want to make it alittle more complicated but easier for the user. Every ip has a user assigned to it.. instead of listing one large table, I want the php script to make a new table for each user. How would I even start something like this? My columns are:
id ip hostname device_name mac rule user

sample data:
2.2.2.2 testadfadfs testadsf test arp -i br0 -s 2.2.2.2 00:16:3E:7A:14:38 matt

So you see I have multiple rows with user as "matt". I am thinking I could just make several sql queries/and loops in my php file for each user, but I am going to be adding more users/device sections as I go and I would like this to be automatic.
Gargoyle
Forum Contributor
Posts: 130
Joined: Wed Jul 14, 2010 12:25 am

Re: PHP/Mysql question

Post by Gargoyle »

I want the php script to make a new table for each user
what is the reasoning behind this? unless you have billions of rows per user, sharding isn't worth the effort.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: PHP/Mysql question

Post by AbraCadaver »

I assume by "new table" you mean a new HTML table and not a new database table? You do this in the query:

Code: Select all

SELECT * FROM `table_name` WHERE `user` = 'matt'
To normalize, you should have a users table with usernames and unique ids, and then user in the other table would just be the id.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Gargoyle
Forum Contributor
Posts: 130
Joined: Wed Jul 14, 2010 12:25 am

Re: PHP/Mysql question

Post by Gargoyle »

assume by "new table" you mean a new HTML table and not a new database table?
duh... I guess I should try to keep in mind most posts here are written by amateurs (no offense to anyone).
Post Reply