Jump to content

[SOLVED] table and array result please help


redarrow

Recommended Posts

can anybody get the same result with the main array

so i don't need to split the array up.

 

this is row 1  this is row 5

 

this is row 2  this is row 6

 

this is row 3  this is row 7

 

this is row 4  this is row 8

 

current table


<table boreder="4">
<?php

$array=array("this is row 1","this is row 2","this is row 3","this is row 4",
              "this is row 5","this is row 6","this is row 7","this is row 8");

$a=array("{$array[0]}","{$array[1]}","{$array[2]}","{$array[3]}");
$b=array("{$array[4]}","{$array[7]}","{$array[6]}","{$array[7]}");

?>

<?php for($i=0; $i<4; $i++){ ?>

<tr>
<td>
<?php echo $a[$i]; ?>
</td>
<td>
<?php echo $b[$i]; ?>
</td>

</tr>

<?php }?>

</table>

 

result

<table boreder="4">


<tr>
<td>
this is row 1</td>
<td>
this is row 5</td>

</tr>


<tr>
<td>
this is row 2</td>
<td>
this is row 8</td>

</tr>


<tr>
<td>
this is row 3</td>
<td>
this is row 7</td>

</tr>


<tr>
<td>
this is row 4</td>
<td>
this is row 8</td>

</tr>


</table>

Link to comment
Share on other sites

<table border="4">
<?php

$a = array("this is row 1","this is row 2","this is row 3","this is row 4",
              "this is row 5","this is row 6","this is row 7","this is row 8");
?>

<?php for($i=0; $i<4; $i++){ ?>
   
<tr>
<td>
<?php echo $a[$i]; ?>
</td>
<td>
<?php
$j = $i + 4;
echo $a[$j]; ?>
</td>

</tr>

<?php }?>

</table>

Link to comment
Share on other sites

ober thanks mate but, because off the current array needs to be looped 4 times to get the row's correctly looking,

 

The user is restricted to 16 forums only in the admin page at the moment.

 

is there a way to get the number of rows endless.

 

Let say the user had 35 forums added to the database , I want the table to show them rows as meny as he adds to the database.

 

but i want it in the order as you see now.

 

how can i do that will i need to use a switch or is there another way.

 

Link to comment
Share on other sites

 

Incase anybody wants to no how to increment the array by 4 thanks to USER: ober.


<table align="center" width="1200px">
<?php 

$a=array("This is froum 1","This is forum 2","This is forum 3","This is forum 4",
"This is forum 5","This is forum 6","This is forum 7","This is forum 8",
"This is forum 9","This is forum 10","This is forum 11"," This is forum 12",
"This is forum 13","This is forum 14","This is frorum 15","This is forum 16");

for($i=0; $i<4; $i++){?>

<tr>
<td align="center">
<?php echo $a[$i];?>
<br><br><br>
</td>
<td align="center">

<?php $b=$i+4; echo $a[$b];?>
<br><br><br>
</td>
<td align="center">
<?php $c=$b+4; echo $a[$c]; ?>
<br><br><br>
</td>
<td align="center">
<?php $d=$c+4; echo $a[$d]; ?>
<br><br><br>
</td>
</tr>
<?php }?>
</table>

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.