dcsimg
www.webdeveloper.com
Results 1 to 2 of 2

Thread: [RESOLVED] Outputting array content into a table

  1. #1
    Join Date
    Oct 2008
    Location
    moreno valley, California ,usa
    Posts
    161

    resolved [RESOLVED] Outputting array content into a table

    Valued associates:
    I am trying to do what would seem to be a simple thingutput array contents into a table. I read a mysql table and create an array of folder names. I read a second table and create an array of picture file names. I need to iterate through these arrays creating a table with three pictures per row. I have no idea how large these arrays are. $num=mysql_num_rows($result2); and $rownum=ceil($num/3); will give me the number of rows needed.

    After this, I use a for loop to iterate as you will see below. The first iteration does fine, but I get blank squares and empty paths after that. Any suggestions would be greatly appreciated.

    the relevant code is as follows:

    $rownum=ceil($num/3);//find out how many rows will be needed

    $i=0;
    while($frow=mysql_fetch_array($result))//retrieve the folder names and open each folder
    {
    $folder[$i]=$frow['item_name'];
    $folder_name=$folder[$i];
    $folder_name="images/".$folder_name."/";
    opendir($folder_name);
    $i++;
    }

    $j=0;
    while($prow=mysql_fetch_array($result2))//retrieve the picture file names and open each file
    {
    $picfile[$j]=$prow['img_fr'];
    $picfile_name=$picfile[$j];
    $picfile_name="images/".$folder[$j]."/".$picfile_name;
    fopen($picfile_name,"r");
    $j++;
    }
    for($n=0;$n<2;$n++)//row number
    {
    $s=$n * 3;//starting picture file number
    echo '<h3>the s variable is:'.' '.$s.'</h3>';
    echo '<tr><td><img src="images/'.$folder[$s]."/".$picfile[$s].'" /></td><td><img src="images/'.$folder[$s+1]."/".$picfile[$s+1].'" /></td><td><img src="images/'.$folder[$s+2]."/".$picfile[$s+2].'" /></td><tr>';
    //check read out of path specification; after first iteration the paths are blank and no pictures appear
    echo '<h3>path spec.s :<br /></h3>';
    echo '"images/'.$folder[$s]."/".$picfile[$s].'"<br />';
    echo '"images/'.$folder[$s+1]."/".$picfile[$s+1].'"<br />';
    echo '"images/'.$folder[$s+2]."/".$picfile[$s+2].'"<br />';

    }

    captsig

  2. #2
    Join Date
    Oct 2008
    Location
    moreno valley, California ,usa
    Posts
    161

    Found better code

    Assoicates,
    you may disregard this problem statement as I have found code to solve the problem (I can see how badly misguided my first attempt was!!). I'll list the code here for the curious:

    picking it up after the initial queries to create the arrays...

    $i=0;
    while($frow=mysql_fetch_array($result, MYSQL_BOTH))//retrieve the folder names and open each folder
    {
    $folder[$i]=$frow['item_name'];
    $folder_name=$folder[$i];
    $folder_name="images/".$folder_name."/";
    opendir($folder_name);
    $i++;
    }

    $j=0;
    while($prow=mysql_fetch_array($result2,MYSQL_BOTH))//retrieve the picture file names and open each file
    {
    $picfile[$j]=$prow['img_fr'];
    $picfile_name=$picfile[$j];
    // echo '<h3>picture file name is:'.' '.$picfile_name.'</h3>';
    $picfile_name="images/".$folder[$j]."/".$picfile_name;
    fopen($picfile_name,"r");
    $j++;
    }
    $fp=array_combine($folder,$picfile);
    $count=0;
    echo '<table><tr>';
    foreach($fp as $key=>$item)
    {
    if($count==3)
    {
    echo '</tr><tr>';
    $count=0;
    }
    echo '<td><img src="images/'.$key."/".$item.'" /></td>';
    $count++;
    }

    echo '</tr></table>';
    ?>

    The last echo was just a path check for me.

    All the best,
    captsig

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles