PDA

View Full Version : Several Queires on A Single Page


stevenmw
08-06-2007, 06:16 AM
These days there are many websites ran entirely out of databases. Say someone has a table in a database, and each row of that table contains code that makes up a single web-page.(each row has the code for one web-page)

Now let's say there is a single web-page that uses several queries to pull out each row of the database I mentioned above seperately. This way a single web-page can display many web-pages.

Is this possible?
Could a navigation be made to where when a link is clicked the row corresponding to that link could be displayed all by itself?


I'm know I can use the ids that correspond to each row in the table, but how would I set the query up that pulls out the row? First how would I only display one row at a time, second how would I set up the query so it's pulls out a different row's id depending on which link in the navigation is clicked?

And finaly how would I make a navigation that generates a new link whenever a new row / page is added to the database?

guelphdad
08-06-2007, 03:32 PM
have you looked in the PHP manual specifically the mysql functions? have a look at mysql_fetch_row, mysql_fetch_array and mysql_fetch_assoc and see the examples there for some ideas.

note there is nothing wrong with multiple queries in a page, just use them judiciously. say you have two tables, one with artists and one with songs or albums they have written.

what many people do, incorrectly I might add, is query the artists table for all artists, they then create a loop in php and inside that loop they query the albums/songs table to return all data.

what you want to do instead is do a JOIN on the two tables, extract all the data for artists and albums/songs all at once. and then use one loop to output those results.

I know you might not be doing exactly this, but it is the most common mistake made by those that don't use databases on a regular basis.