silveradogirl45 Posted August 14, 2009 Share Posted August 14, 2009 I don't know if I'm doing something wrong or if there isn't a way to do this so I've been driving myself nuts for the past 3 days . But maybe someone can help me here. I'm trying to write a code within one or a few php page(s) that will do the following: 1. Get all data from the first row of a DB table. 2. Set each piece of data from the first row into variables. 3. Print all the variables into a string (which will look like an html page on a product, like a camera, with a description, features, images, etc). 4. Write and create a php file of the page (like row1.php, which shows everything printed in the step 3). 5. Uploads this page to the server. 6. Once row1.php is uploaded the code will automatically start back at step #1, but continuing with row2, and so on till it has gone through all the rows in the table. Is this possible? I already have written a code to where I tell it to take out any row, but only one row at a time, in the table and write, create, and upload a page for that row. MY PROBLEM is I can't get it to do the last step which is automatically go back and repeat the same steps with the next row and so on, without me having to manually pick one row at a time. I'm dealing with thousands of pages, so doing one by one you can imagine takes forever! Thanks in advance to anybody who knows how or even if I can do this! Link to comment https://forums.phpfreaks.com/topic/170314-help-with-looping-through-db-info-by-row/ Share on other sites More sharing options...
mikesta707 Posted August 14, 2009 Share Posted August 14, 2009 a simple while loop? get a count of all the rows in your data base, and do a loop is $sql = "SELECT * FROM table"; $query = mysql_query($sql); $count = mysql_num_rows($query); $i = 0; while ($i < $count){ //do whatever //update counter $i++; } Hope that helps! Link to comment https://forums.phpfreaks.com/topic/170314-help-with-looping-through-db-info-by-row/#findComment-898423 Share on other sites More sharing options...
silveradogirl45 Posted August 14, 2009 Author Share Posted August 14, 2009 I will totally try that. I tried a while loop, but in a different way and probably just made it more complicated so threw myself off. I will post if it works or not. Thanks, mikesta707! Link to comment https://forums.phpfreaks.com/topic/170314-help-with-looping-through-db-info-by-row/#findComment-898426 Share on other sites More sharing options...
silveradogirl45 Posted August 14, 2009 Author Share Posted August 14, 2009 So I tested the while loop that was suggested out on 3 pages with just 3 rows of info from the table. I did a small screen shot of what it's creating of each page. For some reason row2.php didn't repeat like how row1.php and row3.php did. Not sure why it's doing this. Below is a simplified version of my code: $sql = mysql_query("SELECT * from Table WHERE manufacturer = 'Test'"); while ($rows = mysql_fetch_array($sql)) { $file = $rows['file']; $description = $rows['description']; $image = $rows['image']; } $count = mysql_num_rows($sql); $i = 0; while ($i < $count) { $data ="<?php <!--Page Content Begins--> <div id='content'> <h1>$file</h1> <img src='./image/image.jpg'> <p class='desc'>$ddescription</p> </div> <!--Page Content Ends--> ?>"; if (isset($file)) { include (to open, write, close, and upload file); } //update counter $i++; } I've attached images to this post of what the pages look like and another of what they should come out to look like. Anyone see the problem? [attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/170314-help-with-looping-through-db-info-by-row/#findComment-898513 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.