tryin to get a table to add a new td /td for every result from the Db. but can't for life of me figure it out...

the nubers are the results and there are 3 required infos from each entry,(abc)
so if there were 4 results it would have a 4a,4b,4c...

its prob really simple but i cant get it! how would i print it via PHP?
thanks.

<table width="85%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>1a</td>
<td>2a</td>
<td>3a</td>
</tr>
<tr>
<td>1b</td>
<td>2b</td>
<td>3b</td>
</tr>
<tr>
<td>1c</td>
<td>2c</td>
<td>3c</td>
</tr>
</table>

    that doesn't seem to work at all.

    ive got

    $top="<table width=\"90%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";$page ="<img src=\"../thumbs/th_$file_name\" borders=\"0\">";	
    
    $tda .="<td>$grouped</td>";
    $tdb .="<td>$page</td>";
    $tdc .="<td>$project_title</td>";
    
    $archive .="$top<tr> 
        $tda
      </tr>
      <tr> 
        $tdb
      </tr>
      <tr> 
        $tdc 
      </tr>
     </table>";	
    
    }
    echo"<BR>";
    }
    print"$archive";
    
    

      Oh, wait a sec.. you are trying to display individual rcords next to eachother, and fields below eachother?

      hm..

      //database querystuff here
      while($row = mysql_fetch_array($result))
        {
         $field1results .= "<td>$row[field1]</td>";
         $field2results .= "<td>$row[field1]</td>";
         $field3results .= "<td>$row[field1]</td>";
         }
      
      $results = "
      <table><tr>
       $field1results
      </tr><tr>
       $field2results
      </tr><tr>
       $field3results
      </tr></table>
      ";
      echo $results;
      
      

        thanks, probably my bad explaining was to blame.

        its nearly working but i need to create a table for each group. at the moment there is only one with many columns.

        http://jynk.net/belinda/admin/bel_groups_imagesc.php

        code;

        while($myrow = mysql_fetch_array($sql)){
        		$id = $myrow["id"];
               	$grouped = $myrow["grouped"];
        
        	$sql_answers = mysql_query("SELECT * FROM bel_photos WHERE grouped='$grouped' ORDER BY grouped");
        
        	$total_clips = mysql_query("SELECT COUNT(id) FROM bel_photos WHERE grouped='$grouped'");
        	$total_clips_b = mysql_result($total_clips,0);
        
        	while($myrow = mysql_fetch_array($sql_answers)){			
        		$qid = $myrow["id"];
           		$project_title = $myrow["project_title"];
           		$image_info= $myrow["image_info"];
        	    $file_name = $myrow["file_name"];	
        	    $w++;
        	$project_title=str_replace("&","%26",$project_title);		
        
        $page ="<img src=\"../thumbs/th_$file_name\" borders=\"0\">";	
        
        $tda .="<td>$grouped (group$i)</td>";
        $tdb .="<td>$page</td>";
        $tdc .="<td>$project_title</td>";
        
        }
        
        $archive="
        <table width=\"90%\" border=\"1\" cellspacing=\"0\" cellpadding=\"1\">
        <tr> 
            $tda
          </tr>
          <tr> 
            $tdb
          </tr>
          <tr> 
            $tdc 
          </tr>
         </table><BR>";	
        }
        
        print"$archive";
        
        

          Hi,

          I cleaned the code a bit. I hope it helps

          
          // reset the groups
          $last_group =-1;
          
          // retrieve the result
          
          while($myrow = mysql_fetch_array($sql))
            {
            if($last_grouped == $myrow["grouped"]) // this is the same group still
               {
                $qid = $myrow["id"];
                $project_title = $myrow["project_title"];
                   $project_title=str_replace("&","%26",$project_title);        
          $image_info= $myrow["image_info"]; $file_name = $myrow["file_name"];
          $page ="<img src=\"../thumbs/th_$file_name\" borders=\"0\">"; $tda .="<td> $grouped (group$i) </td>"; $tdb .="<td> $page </td>"; $tdc .="<td> $project_title </td>"; } else { $last_grouped = $myrow["grouped"]; $archive .=" <table width=\"90%\" border=\"1\" cellspacing=\"0\" cellpadding=\"1\"> <tr> $tda </tr><tr> $tdb </tr><tr> $tdc </tr></table> <BR> ";
          $tda = ""; $tdb = ""; $tdc = ""; } } print"$archive";

            sorry, but now i'm just cunfused. it doesn't work at all now. except a bit of a table.
            http://jynk.net/belinda/admin/bel_groups_imagesc.php
            do you not need 2 queries and fetch arrays?

            include("bel_conf.php");
            
            $d =mysql_connect($host, $user, $pass) or die ("Unable to connect!");
            mysql_select_db($db) or die ("Unable to select database!");
            
            $sql =mysql_query("SELECT * FROM bel_photos GROUP BY grouped");
            
            // reset the groups 
            $last_grouped*=-1;
            // retrieve the result 
            while($myrow=mysql_fetch_array($sql)){
            
            
            if($last_grouped==$myrow["grouped"]){// this is the same group still
            
            $qid=$myrow["id"];
            $project_title=$myrow["project_title"];
            $project_title=str_replace("&","%26",$project_title);
            $image_info=$myrow["image_info"];
            $file_name*=$myrow["file_name"];
            
            $page*="<img*src=\"../thumbs/th_$file_name\"*borders=\"0\">";
            
            $tda*.="<td>$grouped(group$i)</td>";
            $tdb*.="<td>$page</td>";
            $tdc*.="<td>$project_title</td>";
            
            }else{
            $last_grouped*=$myrow["grouped"];
            $archive .="
            <table*width=\"90%\"*border=\"1\"*cellspacing=\"0\"*cellpadding=\"1\">
            <tr>
            $tda
            </tr><tr>
            $tdb
            </tr><tr>
            $tdc
            </tr></table>
            <BR>
            ";
            $tda="";
            $tdb="";
            $tdc="";
            }
            }
            print"$archive";
            
            

            ps. a bit unrelated, but everytime i cut& paste from here i have to manually delete all the white space as there seems to be loadsa invis characters messing it up. do u ever find that?

              ah. got it. thanks for your help. i had to revert to my messy code a little.

              d.

                It works now?

                your query sahould be 1 query:

                SELECT * FROM bel_photos ORDER BY grouped

                which get all the records. The processing is then done by the code. You can use a where statement to limit the number of records.

                The spaces and stuff I put in on purpose. It is called formatting, and makes it much easier to spot errors, since each new loop / if / while / .. starts on a different loevel in the code.

                J

                  Oh, by the way..

                  On your website, you are using so much & %$% javascript, that even the back button on the browser doesn't work, and I get lots of annoying popups with screensizes and timers and stuff. I would not do this too much, since it is really annoying.

                  J.

                    Write a Reply...