Jump to content

display multiple columns


matvespa

Recommended Posts

I have this code which works fine. I want to improve it by displaying it into multiple columns. Current output:

 

TITLE 1

JOB1

---------

TITLE 2

JOB 2

---------

ETC...

 

I want it to display like this instead:

 

TITLE 1  |  TITLE 2

JOB 1    |  JOB 2

 

Here is my code:

$sql = "SELECT * FROM coaches WHERE position = 'Junior Coach'"; 
	$result = mysql_query ($sql); 

	while ($row = mysql_fetch_array($result)){ 
		$id = $row["id"];
		$firstname = $row["firstname"];
		$lastname = $row["lastname"];
		$position = $row["position"];
		$image = $row["image"];
	?>
             <table width="183" border="1">
                <tr>
                  <td align="center" height="18">
                  <?php echo "<img id='image_shadowCoaches' src=" . $image . ">"; ?><br />
			  <?php echo "<div id='Coaches_Detail'>".$firstname." ".$lastname."</div>" ?>
                 <?php echo "<div id='Coaches_DetailLower'>".$position."</div>" ?>
                  
                  </td>
                </tr>
                </table>
             <?php } ?>

Link to comment
https://forums.phpfreaks.com/topic/211993-display-multiple-columns/
Share on other sites

Hey Matvespa, try the following :)

 

<table cellpadding="0" cellspacing="0" border="1">
  <tr>

<?PHP

  // Create the the query
  $myQuery1 = "SELECT * FROM coaches WHERE position = 'Junior Coach'";
  // Execute the above query here
  $result   = mysql_query($sql); 
  
  // While records exists keep fetching them
  while($row = mysql_fetch_array($result)){ 

    // Give each of the records a $variable name
    $id        = $row['id'];
    $firstname = $row['firstname'];
    $lastname  = $row['lastname'];
    $position  = $row['position'];
    $image     = $row['image'];
?>

  <td align="center" height="18" width="183">
<?php echo '<img id="image_shadowCoaches" src='.$image.'>'; ?><br />
<?php echo '<div id="Coaches_Detail">'.$firstname.' '.$lastname.'</div>'; ?>
<?php echo '<div id="Coaches_DetailLower">'.$position.'</div>'; ?>
  </td>

<?php } ?>

</tr>
</table>

 

Hope it helps you, if not just let me know.

 

Thanks, Paul.

I was just about to say that Matvespa, he wasn't far off though :)

 

Try the following

<table cellpadding="0" cellspacing="0" border="1">
  <tr>

<?PHP

  $myQuery1 = "SELECT * FROM coaches WHERE position = 'Junior Coach'"; // Create the the query
  $result   = mysql_query($sql); // Execute the above query here
  $number   = '0'; // Set a number so we can limit the number of TD's per row
  $tbNumber = '2'; // Set how many TD's you want per row

  // While records exists keep fetching them
  while($row = mysql_fetch_array($result)){ 

    // Give each of the records a $variable name
    $id        = $row['id'];
    $firstname = $row['firstname'];
    $lastname  = $row['lastname'];
    $position  = $row['position'];
    $image     = $row['image'];
?>

  <td align="center" height="18" width="183">
<?php echo '<img id="image_shadowCoaches" src='.$image.'>'; ?><br />
<?php echo '<div id="Coaches_Detail">'.$firstname.' '.$lastname.'</div>'; ?>
<?php echo '<div id="Coaches_DetailLower">'.$position.'</div>'; ?>
  </td>

<?php if(is_int($number/$tbNumber)) { echo '</tr><tr>'; } } ?>

</tr>
</table>

 

This should work now, if not let me know.

 

Thanks, Paul.

Sorry about that Matvespa, I over looked a simple little bit of code, I didn't increment the $number variable, use the following...

 


<table cellpadding="0" cellspacing="0" border="1">
  <tr>

<?PHP

  $myQuery1 = "SELECT * FROM coaches WHERE position = 'Junior Coach'"; // Create the the query
  $result   = mysql_query($sql); // Execute the above query here
  $number   = '1'; // Set a number so we can limit the number of TD's per row
  $tbNumber = '2'; // Set how many TD's you want per row

  // While records exists keep fetching them
  while($row = mysql_fetch_array($result)){ 

    // Give each of the records a $variable name
    $id        = $row['id'];
    $firstname = $row['firstname'];
    $lastname  = $row['lastname'];
    $position  = $row['position'];
    $image     = $row['image'];
?>

  <td align="center" height="18" width="183">
<?php echo '<img id="image_shadowCoaches" src='.$image.'>'; ?><br />
<?php echo '<div id="Coaches_Detail">'.$firstname.' '.$lastname.'</div>'; ?>
<?php echo '<div id="Coaches_DetailLower">'.$position.'</div>'; ?>
  </td>

<?php if(is_int($number/$tbNumber)) { echo '</tr><tr>'; } $number ++; } ?>

</tr>
</table>

 

Thanks, Paul.

Archived

This topic is now archived and is closed to further replies.

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