xtrafile Posted March 26, 2008 Share Posted March 26, 2008 I have a MySQL database that I will be creating a website with. However, now I need to display that DB information. Is there a way to dynamically generate the thousands of pages that will list the records from the database? Thanks! Link to comment https://forums.phpfreaks.com/topic/97959-dynamically-creating-2000-pages-from-db/ Share on other sites More sharing options...
ansarka Posted March 26, 2008 Share Posted March 26, 2008 what do you really want if you hv 10000 of records in Db you dont want to create that much page just create one page and implement pagination logic ??? i think this is what you are asking for Link to comment https://forums.phpfreaks.com/topic/97959-dynamically-creating-2000-pages-from-db/#findComment-501193 Share on other sites More sharing options...
xtrafile Posted March 26, 2008 Author Share Posted March 26, 2008 Yes I need to create 2000+ pages. So I should instead use one page in a loop, loading the selected page from the DB? How would I have each of them setup though to call the page from the database? I need something time-efficient so I still do not have to manually load the data from the DB. Thanks Link to comment https://forums.phpfreaks.com/topic/97959-dynamically-creating-2000-pages-from-db/#findComment-501196 Share on other sites More sharing options...
trq Posted March 26, 2008 Share Posted March 26, 2008 Database driven websites do not have a physical page for each viewable web page. If your not sure of the logic behind dynamic websites, you've probably a long way to go. Theres a great link in my signiture that should get you started. Or, if you have a specific question, ask it. Link to comment https://forums.phpfreaks.com/topic/97959-dynamically-creating-2000-pages-from-db/#findComment-501197 Share on other sites More sharing options...
xtrafile Posted March 26, 2008 Author Share Posted March 26, 2008 Ah I see. Then I do have a long way to go. Thanks! Link to comment https://forums.phpfreaks.com/topic/97959-dynamically-creating-2000-pages-from-db/#findComment-501198 Share on other sites More sharing options...
trq Posted March 26, 2008 Share Posted March 26, 2008 A small example of some of the logic. listarticles.php <?php // connect to db. $sql = "SELECT id,title FROM articles ORDER BY stamp"; // query the database for all articles. if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { while ($row = mysql_fetch_assoc($result)) { // create a link to articles.php passing it the article id via the url. echo "<a href='articles.php?id={$row['id']}'>{$row['title']}</a><br />"; } } } ?> articles.php <?php if (isset($_GET['id'])) { // get article id from the url. $id = mysql_real_escape_string($_get['id']); } else { // a default article id. $id = 1; } // connect to db. $sql = "SELECT title,data FROM articles WHERE id = '$id' LIMIT 1"; if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { $row = mysql_fetch_assoc($result); echo "<h1>{$row['title']}</b1>"; echo "<p>{$row['data']}</p>"; } } ?> These two simple scripts could display hundreds/thousands even millions of articles. Of course they would need some tweaking. The first page simply lists all articles as links of titles sorted by date. When you click on a link you are taken to the second script which then displays the data for said article. Hope this helps some. Link to comment https://forums.phpfreaks.com/topic/97959-dynamically-creating-2000-pages-from-db/#findComment-501203 Share on other sites More sharing options...
xtrafile Posted March 26, 2008 Author Share Posted March 26, 2008 Thanks a lot! I haven't discovered pagination yet.. looks awesome! Link to comment https://forums.phpfreaks.com/topic/97959-dynamically-creating-2000-pages-from-db/#findComment-501222 Share on other sites More sharing options...
trq Posted March 26, 2008 Share Posted March 26, 2008 There is no pagination in my scripts. Pagination is the process of splitting results accross multiple pages. For instance, I stated that my script would need tweaking before they could serv thousands of articles. The reason is that listarticles.php will simply create links to all articles on one page. Thousands of articles would meen thousands of lines and pretty quickly the server would die, and the pages would not load. You might add pagination to the script in order to have it display say 20 links per page. You then have a next and previous link at the bottom to sort through more links. That is pagination. The scripts I posted are just one example of some simple dynamic page generation logic. Link to comment https://forums.phpfreaks.com/topic/97959-dynamically-creating-2000-pages-from-db/#findComment-501233 Share on other sites More sharing options...
xtrafile Posted March 26, 2008 Author Share Posted March 26, 2008 I gotcha. I'm quite newbie to this, but thanks! Guess I shouldn't say anymore before I make people mad Link to comment https://forums.phpfreaks.com/topic/97959-dynamically-creating-2000-pages-from-db/#findComment-501236 Share on other sites More sharing options...
trq Posted March 26, 2008 Share Posted March 26, 2008 Guess I shouldn't say anymore before I make people mad Questions are fine, thats what the board is for. Link to comment https://forums.phpfreaks.com/topic/97959-dynamically-creating-2000-pages-from-db/#findComment-501249 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.