Jump to content


making tables stand side by side


4 replies to this topic

#1 Bl4ck-Vip3r

    Young Padawan

  • Members
  • Pip
  • 41 posts

Posted 31 March 2007 - 05:05 PM

i have a query pciking the rand tuts out of my db and i am displaying them at the top of the page but at the mo they stack ontop of eachother and i want them to go side by side how would i do this because if i add like another td and put the query in it then it picks the same 1. here the code


<?php
include "db.php";

echo "<table width ='100%'>
<div id = 'Text'>";

$result = mysql_query("SELECT * from $mysql_table ORDER BY RAND() LIMIT 2");
while($row = mysql_fetch_array($result)) {

echo"

<td>
<div align='left'><strong><font color ='#FF0000'><a class = 'FootLink' href='tutorials.php?category=".$row['category']."&id=".$row['id']." '> ".$row['title']." </a>
</font></strong></div></td>

	<tr>

<td>
<div align='left'> ".$row['description']."</div></td></tr>
  


"; // End of Template for the tutorials in a category.
} // End of grabbing information from database.

echo "</div></table>
";
?>


#2 curthard89

    Young Padawan

  • Members
  • Pip
  • 226 posts

Posted 31 March 2007 - 05:56 PM

<?php
include "db.php";

echo "
<div style=\"float: left\">
<table width ='100%'>
<div id = 'Text'>";

$result = mysql_query("SELECT * from $mysql_table ORDER BY RAND() LIMIT 2");
while($row = mysql_fetch_array($result)) {

echo"

<td>
<div align='left'><strong><font color ='#FF0000'><a class = 'FootLink' href='tutorials.php?category=".$row['category']."&id=".$row['id']." '> ".$row['title']." </a>
</font></strong></div></td>

<tr>

<td>
<div align='left'> ".$row['description']."</div></td></tr>



"; // End of Template for the tutorials in a category.
} // End of grabbing information from database.

echo "</div></table>
</div>
";
?>

try that :lol:, what happened to my include file idea? lol

#3 Bl4ck-Vip3r

    Young Padawan

  • Members
  • Pip
  • 41 posts

Posted 01 April 2007 - 03:18 AM

it worked great, but then i tried to make both sides scroll upward and it made my box expand really big :S so i gave up with the marquee and decided to have only the titles side by side ie

[tut1] [tut2] [tut3] [tut4] ...

and cheers :) lol 1 last question, any ideas how i can make it so after every5 tutorials or at the end of them all, it like has a break and echos an advert like p2l used to do so eg.

after every 5

[1]
[2]
[3]
[4]
[5]
[Advert]



or after them all so if i didnt have 5 or if it was an evan number

[1]
[2]
[3]
[4]
[5]
[6]
[advert]

Nm about at the end one, ill just put it after te while lol, and for the after 5 1 should i do like

loop until mysqlnumberofrows {



query limit 5

{

}

advert code

}

Edited by Bl4ck-Vip3r, 01 April 2007 - 04:23 AM.


#4 curthard89

    Young Padawan

  • Members
  • Pip
  • 226 posts

Posted 01 April 2007 - 05:55 AM

this is of the top of my head here,

im asuming yo will need to do a row count on tutorials,

then for every 5 it loops through printing an advert

ill see what i can find

#5 Demonslay

    P2L Jedi

  • Members
  • PipPipPip
  • 970 posts
  • Gender:Male
  • Location:A strange world where water falls out of the sky... for no reason.
  • Interests:Graphic Design, Coding, Splinter Cell, Cats

Posted 01 April 2007 - 12:19 PM

<?php
$i = 1;
$advert_num = 5;

while($t = mysql_fetch_array($query)){
// Echo your tutorial data like normal

if($i == $advert_num){
// Echo advertisement

$i = 1; // Reset the variable
}
else $i++;
}
?>

Simple as that.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users