reading from the database

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
llamaclock
Forum Newbie
Posts: 3
Joined: Sun Mar 07, 2004 1:21 am
Location: california

reading from the database

Post by llamaclock »

I have got as far as reading from the database, however I need some help. I want to eliminate certain columns when reading from the database, for example I dont want my users IP address viewable by the public, I would like it logged though. I also need it to read so that the newest row is at the top.

Thanks
microthick
Forum Regular
Posts: 543
Joined: Wed Sep 24, 2003 2:15 pm
Location: Vancouver, BC

Post by microthick »

If you don't want to retrieve certain columns, then leave them out of your SELECT statement.

So, instead of "SELECT * FROM tblTable", use "SELECT colA, colB FROM tblTable" to only retrieve columns colA and colB.

You can order by record age so long as you have a column that can be compared to other records such that you can determine that recordA is older than recordB. This is normally done by having an ID column set to automatically increment each time a record is inserted.

Assuming you have a column of this type in your table, you can order by age like this: "SELECT colA, colB FROM tblTable ORDER BY id".
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

Reading just the fields desired is the best (as microthick explains), but for learning purposes I'll make an additional answer:
...eliminate certain columns when reading from the database, for example I dont want my users IP address viewable by the public...
Why echo/print it out in the first place? Even if you select your entire database, you yourself decide what gets shown to the public...
Post Reply