Jump to content

Looping Problem Still...Need Help


silveradogirl45

Recommended Posts

I'm trying to get the following to happen:

 

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.

 

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've tested this while loop 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. 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 and what I'm missing in my loop to make it cause the repeating problem in the image attached?

 

Thanks in advance for any help!!

 

 

[attachment deleted by admin]

Link to comment
https://forums.phpfreaks.com/topic/170676-looping-problem-stillneed-help/
Share on other sites

$sql = mysql_query("SELECT * from Table WHERE manufacturer = 'Test'");

while ($rows = mysql_fetch_array($sql)) {
   $file = $rows['file'];
   $description = $rows['description'];
   $image = $rows['image'];

   $data ="<?php 
   <!--Page Content Begins-->
   <div id='content'>
   <h1>$file</h1>
   <img src='./image/image.jpg'>
   <p class='desc'>$description</p>
   </div>
   <!--Page Content Ends-->
   ?>";

   if (isset($file)) {
      include_once (to open, write, close, and upload file);
   }
}

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.