Jump to content

Recommended Posts

I sure this is reall easy but I new to PHP  - in ASP I would simply put a rs.movenext between the <TD >TAGS

 

need to display

 

Row1 | row3

row4 | row5

 

till eof

 

what I have now is

 

<?php

do { ?>

                          <tr>

                            <td width="50%"><a href="http://<?php  Echo $row_RS2['URL'] ?>" target="_blank" class="V12">

                              <?php  Echo $row_RS2['employer'] ?>

                            </a></td>

                           

                            <td><a href="http://<?php  Echo $row_RS2['URL'] ?>" target="_blank" class="V12">

                              <?php  Echo $row_RS2['employer'] ?>

                            </a></td>

                          </tr>

                          <?php } while ($row_RS2 = mysql_fetch_assoc($RS2)); ?>

 

with just displays same data twice on each row - need to move to next row

 

any help will be appreciated

 

Ted

Link to comment
https://forums.phpfreaks.com/topic/148841-loop-thru-data-and-display-in-2-colums/
Share on other sites

Or the modulus operator.

 

Not tested, just thrown together quickly:

<?php
$i = 0;
do { 
if($i%2==0) {
	?>
	<tr>
		<td width="50%"><a href="http://<?php  Echo $row_RS2['URL'] ?>" target="_blank" class="V12">
		<?php  Echo $row_RS2['employer'] ?>
		</a></td>
<?php } else { ?>
		<td><a href="http://<?php  Echo $row_RS2['URL'] ?>" target="_blank" class="V12">
		<?php  Echo $row_RS2['employer'] ?>
		</a></td>
	</tr>
<?php }
$i++;
} while ($row_RS2 = mysql_fetch_assoc($RS2)); 
if($i%2>0) {
echo '<td></td></tr>';
// in case of ending in an odd number of columns
}
?>

Thank you , thank you,  thank you

 

I just had to add the table tags and it works great

 

<?php

$target= $_REQUEST['target'];

 

mysql_select_db($DBName, $militaryEdge);

//echo $DBName;

$query_RS2 = "SELECT * FROM jobfair_employers  order by sort_order";

$RS2 = mysql_query($query_RS2, $militaryEdge) or die(mysql_error());

$row_RS2 = mysql_fetch_assoc($RS2);

$totalRows_RS2 = mysql_num_rows($RS2);

?>

<table>

<?php

$i = 0;

do {

  if($i%2==0) {

      ?>

      <tr>

        <td width="50%"><a href="http://<?php  Echo $row_RS2['URL'] ?>" target="_blank" class="V12">

        <?php  Echo $row_RS2['employer'] ?>

        </a></td>

  <?php } else { ?>

        <td><a href="http://<?php  Echo $row_RS2['URL'] ?>" target="_blank" class="V12">

        <?php  Echo $row_RS2['employer'] ?>

        </a></td>

      </tr>

  <?php }

  $i++;

} while ($row_RS2 = mysql_fetch_assoc($RS2));

if($i%2>0) {

  echo '<td></td></tr>';

  // in case of ending in an odd number of columns

}

?>

</table>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.