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
reading from the database
Moderator: General Moderators
-
llamaclock
- Forum Newbie
- Posts: 3
- Joined: Sun Mar 07, 2004 1:21 am
- Location: california
-
microthick
- Forum Regular
- Posts: 543
- Joined: Wed Sep 24, 2003 2:15 pm
- Location: Vancouver, BC
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".
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".
Reading just the fields desired is the best (as microthick explains), but for learning purposes I'll make an additional answer:
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......eliminate certain columns when reading from the database, for example I dont want my users IP address viewable by the public...