Jump to content

problem, please help me


itzknowledge

Recommended Posts

ok so i have this cms, and it displays the titles of the post ontop of each other in a single row, for example

title3

title2

title1

 

what i want it to do is display it 4 in a row and then move ontop and start a new row, for example

title8 title7 title6 title5

title4 title3 title2 title1

 

this is the code i have for the page:

 

<?php 
database_connect();
$query = "SELECT * from content
          WHERE status = 1
          ORDER by position;";
$error = mysql_error();
if (!$result = mysql_query($query)) {
    print "$error";
exit;
}

while($rij = mysql_fetch_object($result)){
  $title = $rij->title;
  $id = $rij->id;
  print("<a href=\"page.php?id=$id\" target=\"_self\"><strong>$title</strong></a>");
}
?>

 

can somebody please help me fix this.

Link to comment
https://forums.phpfreaks.com/topic/100587-problem-please-help-me/
Share on other sites

A table is probably the easiest way .

 

Create a html page with a table in it, and fill it with dummy data similar to what might be retrieved from your database.Once you can get the HTML table to render correctly, just insert the HTML in the appropriate places in your script.

 

Below is a script that creates rows of three fields. you can modify it to display rows of four.Basically it tests which record has been retrieved. Ie the first, second ,third etc and displays the corresponding HTML code to allow it to be positioned correctly.

 

 $count=0;
   $getmaincats="SELECT * from cl_categories where CatParent='0'";
   $getmaincats2=mysql_query($getmaincats) or die("Could not get root categories"); 
   print "<table class='maintable'>";
   while($getmaincats3=mysql_fetch_array($getmaincats2))
   {
     if($count%3==0)
     {
       print "<tr class='rows'><td class='columns'><A href='index.php?catid=$getmaincats3[CatID]'><b>$getmaincats3[CatName]</b></a><br>$getmaincats3[Catdescription]</td>";
     }
     else if($count%3==1)
     {
       print "<td class='columns'><A href='index.php?catid=$getmaincats3[CatID]'><b>$getmaincats3[CatName]</b></a><br>$getmaincats3[Catdescription]</td>";
     }
     else
     {
       print "<td class='columns'><A href='index.php?catid=$getmaincats3[CatID]'><b>$getmaincats3[CatName]</b></a><br>$getmaincats3[Catdescription]</td></tr>";
     }
     $count++;
   } 

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.