i'm failing at trying to get data out of mysql and formated in html they way i want.

aiming for a 3 column table with a row for thumbs followed by a row for name of thumb, repeat per records in db.

getting somewhere close, but no cigar on the following code;

$sql = ("

SELECT	ID,
	Category, 
	Name, 
	Desc01, 
	Desc02, 
	Desc03,  
	ThumbLink,
	ImageLink

FROM foo

");

$result = mysql_query($sql) or die (mysql_error());

while ($row = mysql_fetch_array($result)) {

$ID = $row['ID'];
$Category = $row['Category'];
$Name = $row['Name'];
$Desc01 = $row['Desc01'];
$Desc02 = $row['Desc02'];
$Desc03 = $row['Desc03'];
$ThumbLink = $row['Thumb'];
$ImageLink = $row['Image'];
// create array from table for thumb, name and id
	$threeI[] = $row['Thumb'];
	$threeN[] = $row['Name'];
	$threePID[] = $row['ID'];
// this isn't working...?
echo ("
	<tr>
	<td align='center'><a href='link.php?$threePID[0]'><img src='/images/$threeI[0]' border='0'></a></td>
	<td align='center'><a href='link.php?$threePID[1]'><img src='/images/$threeI[1]' border='0'></a></td>
	<td align='center'><a href='link.php?$threePID[2]'><img src='/images/$threeI[2]' border='0'></a></td>
	</tr>
	<tr>
	<td align='center' class='dName'><a href='link.php?$threePID[0]'>$threeN[0]</a></td>
	<td align='center' class='dName'><a href='link.php?$threePID[1]'>$threeN[1]</a></td>
	<td align='center' class='dName'><a href='link.php?$threePID[2]'>$threeN[2]</a></td>
	</tr>
");

}

my problem is the loop isn't working, or the arrays aren't working - somehow got to get it to loop so that each time the three thumbs/name/ids are the next three from the db...

any assistance would be greatly appreciated.

thank you.

    hi,
    i don't understand why u r usin some array - just try this:
    to access your arrays in a string, u gotta enclose em im {}, like this: {$threePID[0]}, moreover, u have to clear your arrays when they are larger than 3, e.g. like this:

    if(sizeof($threePID) > 3)
    $threePID = array();
    
    // etc. for the other arrrays
    

    hth

      thx Natty_Dreadlock for the reply and info, i was unable to acheive desired w/ this new info.

      basically what i'm trying to do is;

      load array with three rows of db (1 column) info, then echo that into a table, 2 rows, 3, cols. repeat w/ next three rows from db, and so on. end result will be a table with a series of 2 row/3 cols pieces.

      i've simplified the code for testing purposes;

      	$result = mysql_query($sql) or die (mysql_error());
      
      while ($row = mysql_fetch_array($result)) {
      
      
      $threeN = array();
      $threePID = array();
      $threeN[] = $row['portfolioCompanyName'];
      $threePID[] = $row['portfolioID'];
      
      if(sizeof($threePID) > 3) 
      $threePID = array(); 
      if(sizeof($threeN) > 3) 
      $threeN = array(); 
      
      echo ("
      	<tr>
      	<td align='center' class='dName'><a href='link.php?{$threePID[0]}'>$threeN[0]</a>&nbsp;</td>
      	<td align='center' class='dName'><a href='link.php?{$threePID[1]}'>$threeN[1]</a>&nbsp;</td>
      	<td align='center' class='dName'><a href='link.php?{$threePID[2]}'>$threeN[2]</a>&nbsp;</td>
      	</tr>
      	<tr>
      	<td align='center' class='dName'><a href='link.php?{$threePID[0]}'>$threePID[0]</a>&nbsp;</td>
      	<td align='center' class='dName'><a href='link.php?{$threePID[1]}'>$threePID[1]</a>&nbsp;</td>
      	<td align='center' class='dName'><a href='link.php?{$threePID[2]}'>$threePID[2]</a>&nbsp;</td>
      	</tr>
      ");

      this code results in a table with only 1 item in the first cell of each row. it's the correct data, but trying to get to echo as 3 col rows.

      the above code results in this;

      	$result = mysql_query($sql) or die (mysql_error());
      
      while ($row = mysql_fetch_array($result)) {
      
      
      $threeN = array();
      $threePID = array();
      $threeN[] = $row['portfolioCompanyName'];
      $threePID[] = $row['portfolioID'];
      
      if(sizeof($threePID) > 3) 
      $threePID = array(); 
      if(sizeof($threeN) > 3) 
      $threeN = array(); 
      
      echo ("
      	<tr>
      	<td align='center' class='dName'><a href='link.php?{$threePID[0]}'>$threeN[0]</a>&nbsp;</td>
      	</tr>
      	<tr>
      	<td align='center' class='dName'><a href='link.php?{$threePID[0]}'>$threePID[0]</a>&nbsp;</td>
      	</tr>
      ");
      
      } 

      ?

      i'm not familiar w/ arrays too much, not sure how to get a diff. value into the array 3 times, then loop w/ the next three values.

      any ideas?

      thank you.

        hi,
        first remove the $threeN = array(); $threePID = array(); statements at the beginning of your while loop coz they clean your every time. Next, check if the arrays larger than 3 and clear if necessary (the code u already have is ok).
        then load the data from the db and fill the arrays. the last thing to do is something like this:

        if(sizeof($threePID) == 3)
        {
        echo "your stuff-----";
        }
        

        so just replace the echo statement with your code and it should work.
        hth

          thank you Natty_Dreadlock - that nailed it.

          my non-logic brain is a handicap, but working on it. appreciate your help.

            actually this doesn't work right either.

            it doesn't echo all the records, i think it's skipping every 4th record. and what if there are only 2 records?

            got a lot of work on this to figure out. not sure how to get this, but thought i'd put in this messg just in case someone else ever sees this as a solution.

              Write a Reply...