Jump to content

[SOLVED] new line with php


chriscloyd

Recommended Posts

Heres my dilemma.  I have a script that is going to make a roster image that shows all the members on the team and I need to do rows of three.  So I have 9 images And i need to do three columns and then when it gets to the third image to make a new row how would i Do this?

Link to comment
Share on other sites

well heres an example go to www.team3d.com and look on the right side where it has the pics of the members

 

Okay let me try to explain better.

I have 9 users on my clan roster.  I need to show all their pics and i dont want to show all in one row or all on separate rows i wanna show them in rows of three once it hits three create a new row and display three more then once it hits six new row and display three more

Link to comment
Share on other sites

Oh :)

So lets say we have their names or whatever in an array called $names:

 

<?php

$i = 0

echo "<table>";

foreach($names as $name)
{
if($i % 3 == 0)
	echo "<tr>";
echo "<td>".$name."</td>";
if($i % 3 == 0)
	echo "</tr>";

$i++
}

//Just to make sure we are closing the last <tr>
if(($i-1) % 3 != 0)
echo "</tr>";

echo "</table>";

?>

 

Hope it helps,

Orio.

Link to comment
Share on other sites

well how would i put there name into an array

here would i do this

<?php
$game_id = $_GET['game'];
$names = array();
$get_roster = mysql_query("SELECT * FROM rosters WHERE game_id = '".$game_id."'") or die(mysql_error());
while($roster = mysql_fetch_array($get_roster)) {
$i = 0;
$names[] = $roster['displayname'];
foreach($names as $name) {
if($i % 3 == 0) {
	echo "<tr>";
}
echo "<td>".$name."</td>";
if($i % 3 == 0) {
	echo "</tr>";
}
$i++;
}
//Just to make sure we are closing the last <tr>
if(($i-1) % 3 != 0)
echo "</tr>";
}
?>

 

i tried that and it didnt work

Link to comment
Share on other sites

In your case it should be:

 

<?php

$game_id = $_GET['game'];

$get_roster = mysql_query("SELECT * FROM rosters WHERE game_id = '".$game_id."'") or die(mysql_error());

echo "<table>";
$i = 0;
while($roster = mysql_fetch_array($get_roster)) {
if($i % 3 == 0) {
	echo "<tr>";
}
echo "<td>".$roster['displayname']."</td>";
if($i % 3 == 0) {
	echo "</tr>";
}
$i++;
}

if(($i-1) % 3 != 0)
echo "</tr>";
}

echo "</table>";

?>

 

Orio.

Link to comment
Share on other sites

heres what im trying right now and its not working

<?php
$game_id = $_GET['game'];
$i = 0;
echo '<table width="100%" border="0" cellspacing="3" cellpadding="0">';
$get_roster = mysql_query("SELECT * FROM rosters WHERE game_id = '".$game_id."'") or die(mysql_error());
while($roster = mysql_fetch_array($get_roster)) {
$i++;
$get_user = mysql_query("SELECT * FROM users WHERE user_id = '".$roster['user_id']."'");
$user = mysql_fetch_array($get_user);
if ($i % 3) {
	echo '<tr>';
}
echo '<td><img src="'.$user['picture'].'"></td>';
if ($i % 3) {
	echo '</tr>';
}
}
echo '</table>';
?>

 

http://chaoslegionclan.net/CEGL-Work/ag/files/roster_images.php?game=1

 

its showing it on three separate lines

Link to comment
Share on other sites

Yeah my mistake:

 

<?php

$game_id = $_GET['game'];

$get_roster = mysql_query("SELECT * FROM rosters WHERE game_id = '".$game_id."'") or die(mysql_error());

echo "<table><tr>";
$i = 0;
while($roster = mysql_fetch_array($get_roster)) {
echo "<td>".$roster['displayname']."</td>";
if($i % 3 == 0) {
	echo "</tr><tr>";
}
$i++;
}

if(($i-1) % 3 != 0)
echo "</tr>";
}

echo "</table>";

?>

 

Orio.

Link to comment
Share on other sites

tried that too now shows two on each row

 

<?php
$game_id = $_GET['game'];
$i = 0;
$get_game = mysql_query("SELECT * FROM games WHERE game_id = '".$game_id."'") or die(mysql_error());
$game = mysql_fetch_array($get_game);
echo '<table width="100%" border="0" cellspacing="3" cellpadding="0">';
echo '<tr>';
echo '<td align="center" colspan="3">'.$game['gamename'].'</td>';
echo '</tr>';
echo '<tr>';
$get_roster = mysql_query("SELECT * FROM rosters WHERE game_id = '".$game_id."'") or die(mysql_error());
while($roster = mysql_fetch_array($get_roster)) {
$get_user = mysql_query("SELECT * FROM users WHERE user_id = '".$roster['user_id']."'");
$user = mysql_fetch_array($get_user);
echo '<td><img src="'.$user['picture'].'" height="65px" width="65px"></td>';
if ($i % 3) {
	echo '</tr><tr>';
}
$i++;
}
echo '</table>';
?>

 

http://chaoslegionclan.net/CEGL-Work/ag/files/roster_images.php?game=1

 

Link to comment
Share on other sites

<?php
$game_id = $_GET['game'];
$i = 0;
$get_game = mysql_query("SELECT * FROM games WHERE game_id = '".$game_id."'") or die(mysql_error());
$game = mysql_fetch_array($get_game);
echo '<table width="100%" border="0" cellspacing="3" cellpadding="0">';
echo '<tr>';
echo '<td align="center" colspan="3">'.$game['gamename'].'</td>';
echo '</tr>';
echo '<tr>';
$get_roster = mysql_query("SELECT * FROM rosters WHERE game_id = '".$game_id."'") or die(mysql_error());
while($roster = mysql_fetch_array($get_roster)) {
$get_user = mysql_query("SELECT * FROM users WHERE user_id = '".$roster['user_id']."'");
$user = mysql_fetch_array($get_user);
echo '<td align="center"><img src="'.$user['picture'].'" height="65px" width="65px"></td>';
if ($i % 3) {
	echo '</tr><tr>';
}
$i++;
}
echo '</tr>';
echo '</table>';
?>

 

 

http://www.chaoslegionclan.net/CEGL-Work/ag/files/roster_images.php?game=1

http://www.chaoslegionclan.net/CEGL-Work/ag/files/roster_images.php?game=1

http://www.chaoslegionclan.net/CEGL-Work/ag/files/roster_images.php?game=1

http://www.chaoslegionclan.net/CEGL-Work/ag/files/roster_images.php?game=1

http://www.chaoslegionclan.net/CEGL-Work/ag/files/roster_images.php?game=1

Link to comment
Share on other sites

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.