Jump to content

Looping results layout help


realjumper

Recommended Posts

Hi,

 

This is my loop:

 

    $num = 1;
    while($row20 = mysql_fetch_array( $result20 )) {
// Print out the contents of each row into a table
echo "<tr>";
echo "<td><input type=\"checkbox\" name=\"$num\" value=\"$row20[email]\" onClick=\"forward.disabled=true;emiko.disabled=true;\"></td>";
$full_name = ucwords(strtolower($row20[full_name]));
echo "<td>$full_name</td>";
echo "</tr>";
$num++;
}

 

The above gives a list down the page of results like this, with each name in it's own table cell...and row:

 

John Smith

Ian Bell

George Brown

Jane Doe

 

 

How can I make it display like this, so that I have two users per table row, each in their own table cell?

 

John Smith              Ian Bell

George Brown          Jane Doe

 

 

Thanks :-)

 

Link to comment
https://forums.phpfreaks.com/topic/97904-looping-results-layout-help/
Share on other sites

try

 

    $num = 1;
    while($row20 = mysql_fetch_array( $result20 )) {
	if($num % 2!=0){
		echo "<tr>";
		echo "<td><input type=\"checkbox\" name=\"$num\" value=\"$row20[email]\" onClick=\"forward.disabled=true;emiko.disabled=true;\"></td>";
	}else{
		$full_name = ucwords(strtolower($row20[full_name]));
		echo "<td>$full_name</td>";
		echo "</tr>";
	}
	$num++;
}

   $num = 1;
    while($row20 = mysql_fetch_array( $result20 )) {
	$full_name = ucwords(strtolower($row20[full_name]));
	if($num % 2!=0){
		echo "<tr>";
		echo "<td>$full_name</td>";
	}else{
		echo "<td>$full_name</td>";
		echo "</tr>";
	}
	$num++;
}

 

that should give to columns but i not sure what exactly you want!

Thank you teng84.......here is what I was after, which is soooo close to your solution.

 

I appreciate your help....now I will figure out how it works :-)

 

$num = 1;
    while($row20 = mysql_fetch_array( $result20 )) {
	$full_name = ucwords(strtolower($row20[full_name]));
	if($num % 2!=0){
		echo "<tr>";
		echo "<td><input type=\"checkbox\" name=\"$num\" value=\"$row20[email]\" onClick=\"forward.disabled=true;emiko.disabled=true;\"></td>";
		echo "<td>$full_name</td>";
	}else{
		echo "<td><input type=\"checkbox\" name=\"$num\" value=\"$row20[email]\" onClick=\"forward.disabled=true;emiko.disabled=true;\"></td>";
		echo "<td>$full_name</td>";
		echo "</tr>";
	}
	$num++;
}

[code]

[/code]

The easiest way to deal with this since your HTML layout has " " in it is to place the echo in ' ' (No Shift).

 

Example:


echo '<td><input type="checkbox" name="'.$num.'" value="'.$row[email].'" onClick="forward.disabled=true;emiko.disabled=true;"></td>' ;

 

No need for back slashes anymore to signify a quote character inside quoted code. Pointless and twice the work..

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.