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
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++;
   } 

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.