display 2 columns in php do, while

i'm trying to do this with a table - specifically 2 columns:

<?php do { ?>
          <div id="atBox"><div id="leftImage"><img src="http://joeyrichards.com/images/chinese_art/<?php echo $row_rsPieces['piece_number']; ?>-sm.jpg"></div><div id="rightTxt"><strong><?php echo $row_rsPieces['piece_number']; ?><br><?php echo $row_rsPieces['piece_title']; ?></strong><br><?php echo $row_rsPieces['piece_describe']; ?></div></div><?php } while ($row_rsPieces = mysql_fetch_assoc($rsPieces)); ?>

so something like this:
<table>
<?php do { ?>
       <tr><td><div id="leftImage"><img src="http://joeyrichards.com/images/chinese_art/<?php echo $row_rsPieces['piece_number']; ?>-sm.jpg"></div><div id="rightTxt"><strong><?php echo $row_rsPieces['piece_number']; ?><br><?php echo $row_rsPieces['piece_title']; ?></strong><br><?php echo $row_rsPieces['piece_describe']; ?></div></td></tr><?php } while ($row_rsPieces = mysql_fetch_assoc($rsPieces)); ?></table>

I was doing this with styles but the images aren't all the same height -this is why i think i need table cells, 2 across repeating down the page -

here's a link to the stylesheet version - you can see the problems i'm running into when an image is exceptionally high:

http://healthpresence.com/jr/ancient/
phillystyle123Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Roger BaklundCommented:
Try this:
<?php
  $count = 1;
  echo '<table>';
  while ($row_rsPieces = mysql_fetch_assoc($rsPieces)) {
    $piece_number = $row_rsPieces['piece_number'];
    if($count%2) echo '<tr>';
    echo '<td><div id="leftImage">'.
         '<img src="http://joeyrichards.com/images/chinese_art/'.
         $piece_number.'-sm.jpg"></div>'.
         '<div id="rightTxt"><strong>'.
         $piece_number.'<br>'.
         $row_rsPieces['piece_title'].'</strong><br>'.
         $row_rsPieces['piece_describe'].'</div></td>';
    if(!($count%2)) echo '</tr>';
    $count += 1;
  }
  if(!($count%2)) echo '<td>&nbsp;</td></tr>';
  echo '</table>';
?>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Roger BaklundCommented:
There should be an & nbsp; in line 17: '<td>& nbsp;</td></tr>' without the space between & and nbsp! (EE converts this to a space, so I can't write it!)
0
phillystyle123Author Commented:
thanks so much cxr -worked great - i do have another related ? concerning adding some simple javascript to my php code - basically, i can't seen to output singlequotes in the js in my href.

here's a link to that ? if you you're interested:

http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_23889348.html
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

phillystyle123Author Commented:
cxr - i just found a glitch in the code - if i'm only outputting 1 record - the record doesn't show in the code

0
Roger BaklundCommented:
That was odd. It works with one record when I test it. Post your code, and I will take a look at it.
0
phillystyle123Author Commented:
<?php
  $count = 1;
  echo '<table align="center" style="width:740px">';
  while ($row_rsPieces = mysql_fetch_assoc($rsPieces)) {
    $piece_number = $row_rsPieces['piece_number'];
    if($count%2) echo '<tr>';
   echo '<td valign="top" style="padding-bottom:10px;">'.
     '<div id="leftImage">'.
         '<a href="#" onClick="MM_openBrWindow(\'popup.php?id='.
         $row_rsPieces['id']."','".$row_rsPieces['piece_number']."','".
         'width='.$row_rsPieces['width'].
         ',height='.$row_rsPieces['height']."')".
         '"><img border="0" '.
         'src="http://joeyrichards.com/images/chinese_art/'.
         $piece_number.'-sm.jpg"></a></div>'.
         '<div id="rightTxt"><strong>'.
         $piece_number.'<br>'.
         $row_rsPieces['piece_title'].'</strong><br>'.
         $row_rsPieces['piece_describe'].
     '</div></td>';
    if(!($count%2)) echo '</tr>';
    $count += 1;
  }
  if(!($count%2)) echo '<td>&nbsp;</td></tr>';
  echo '</table>';
?>
0
Roger BaklundCommented:
I don't have your database, but faking a record I do get the correct output (a single row):
<?php
  # faking a single database record
  $rsPieces = array(
    array('piece_number'=>1,'id'=>1,'width'=>100, 'height'=>100,
          'piece_title'=>'Title', 'piece_describe'=>'Description')
  );
 
  $count = 1;
  echo '<table align="center" style="width:740px">';
  while ($row_rsPieces = array_shift($rsPieces)) {
    $piece_number = $row_rsPieces['piece_number'];
    if($count%2) echo '<tr>';
   echo '<td valign="top" style="padding-bottom:10px;">'.
     '<div id="leftImage">'.
         '<a href="#" onClick="MM_openBrWindow(\'popup.php?id='.
         $row_rsPieces['id']."','".$row_rsPieces['piece_number']."','".
         'width='.$row_rsPieces['width'].
         ',height='.$row_rsPieces['height']."')".
         '"><img border="0" '.
         'src="http://joeyrichards.com/images/chinese_art/'.
         $piece_number.'-sm.jpg"></a></div>'.
         '<div id="rightTxt"><strong>'.
         $piece_number.'<br>'.
         $row_rsPieces['piece_title'].'</strong><br>'.
         $row_rsPieces['piece_describe'].
     '</div></td>';
    if(!($count%2)) echo '</tr>';
    $count += 1;
  }
  if(!($count%2)) echo '<td>&nbsp;</td></tr>';
  echo '</table>';
?>

Open in new window

0
phillystyle123Author Commented:
here's my db - not sure what to do
$colname_rsPieces = "-1";
if (isset($_GET['piece_cat'])) {
  $colname_rsPieces = (get_magic_quotes_gpc()) ? $_GET['piece_cat'] : addslashes($_GET['piece_cat']);
}
mysql_select_db($database_joey, $joey);
$query_rsPieces = sprintf("SELECT id, piece_number, piece_title, piece_describe, piece_cat, order_no, width, height FROM content WHERE piece_cat = %s ORDER BY order_no ASC", GetSQLValueString($colname_rsPieces, "text"));
$rsPieces = mysql_query($query_rsPieces, $joey) or die(mysql_error());
$row_rsPieces = mysql_fetch_assoc($rsPieces);
$totalRows_rsPieces = mysql_num_rows($rsPieces);

Open in new window

0
Roger BaklundCommented:
That is not your database, it is your php code used to read the database. But I think it explains your problem. In line 8, you fetch the first row into the variable $row_rsPieces. That means when the while loop starts to read from the result set using mysql_fetch_assoc($rsPieces), that first row is allready read, and there are no more rows. Remove row 8, and you should be fine.
0
phillystyle123Author Commented:
thanks cxr! every answer has been so on the mark - i really really appreciate it!!!

sql below - thanks again!
$colname_rsPieces = "-1";
if (isset($_GET['piece_cat'])) {
  $colname_rsPieces = (get_magic_quotes_gpc()) ? $_GET['piece_cat'] : addslashes($_GET['piece_cat']);
}
mysql_select_db($database_joey, $joey);
$query_rsPieces = sprintf("SELECT id, piece_number, piece_title, piece_describe, piece_cat, order_no, width, height FROM content WHERE piece_cat = %s ORDER BY order_no ASC", GetSQLValueString($colname_rsPieces, "text"));
$rsPieces = mysql_query($query_rsPieces, $joey) or die(mysql_error());
$totalRows_rsPieces = mysql_num_rows($rsPieces);

Open in new window

0
Roger BaklundCommented:
I assume it works as expected now.

Happy to help! :)
0
phillystyle123Author Commented:
all working great and i learned a lot in the process - thanks again
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.