records in columns and not rows

  • Nem
  • Guru
  • Guru
  • Nem
  • Posts: 1243
  • Loc: UK

Post 3+ Months Ago

hey guys.
i have a page that i want to show....

image of member
member name



Ok, i do not want the records to show going down but instead... make it go across the page like 3 times.. then go on to next road.

So basically i want something like ....

Code: [ Select ]
<table>
 <tr>
  <td>$IMAGE</td>
 </tr>
 <tr>
  <td>$MEMBER</td>
 </tr>
</table>
  1. <table>
  2.  <tr>
  3.   <td>$IMAGE</td>
  4.  </tr>
  5.  <tr>
  6.   <td>$MEMBER</td>
  7.  </tr>
  8. </table>


then make it loop each record in columns and after 3 records, go on the next row... etc
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • Nem
  • Guru
  • Guru
  • Nem
  • Posts: 1243
  • Loc: UK

Post 3+ Months Ago

bumpety bump :P
  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

did you solve it?
  • Nem
  • Guru
  • Guru
  • Nem
  • Posts: 1243
  • Loc: UK

Post 3+ Months Ago

nah, its very complicated... i tried

Code: [ Select ]
<tr>
<td></td>
</tr>
  1. <tr>
  2. <td></td>
  3. </tr>


So for example i want:

--------------------
|
|
|
____________|
____________|
|
|
|
____________|
____________|
|
|
|
____________|
____________|

Then the same beside it...


but they just keep going below each other.
  • Nem
  • Guru
  • Guru
  • Nem
  • Posts: 1243
  • Loc: UK

Post 3+ Months Ago

like this:

http://www.schroet.com/players.php

but with the text below images and with "username"
  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

you are going to have to post the code your are using. there is a thing called a modulus operator that will do exactely what you want here[/php]
  • Nem
  • Guru
  • Guru
  • Nem
  • Posts: 1243
  • Loc: UK

Post 3+ Months Ago

PHP Code: [ Select ]
 
<?
 
include("header.php");
 
$columns = 2;
 
mysql_connect('localhost','kilo69','kilo69');
 
mysql_select_db('69kilobytes_co_uk_portal');
 
//change the query to get another field from the database
 
$query = "SELECT username, image FROM members ORDER BY id";
 
$result = mysql_query($query);
 
?>
 
<table border="0">
 
<?
 
while($row = mysql_fetch_array($result)) {?>
 
    <tr>
 
        <td><img src="<?=$row['image'];?>"/></td>
 
        <td><?=$row['username'];?></td>
 
    </tr>
 
<?}?>
 
</table>
 
<? include("footer.php");?>
 
 
  1.  
  2. <?
  3.  
  4. include("header.php");
  5.  
  6. $columns = 2;
  7.  
  8. mysql_connect('localhost','kilo69','kilo69');
  9.  
  10. mysql_select_db('69kilobytes_co_uk_portal');
  11.  
  12. //change the query to get another field from the database
  13.  
  14. $query = "SELECT username, image FROM members ORDER BY id";
  15.  
  16. $result = mysql_query($query);
  17.  
  18. ?>
  19.  
  20. <table border="0">
  21.  
  22. <?
  23.  
  24. while($row = mysql_fetch_array($result)) {?>
  25.  
  26.     <tr>
  27.  
  28.         <td><img src="<?=$row['image'];?>"/></td>
  29.  
  30.         <td><?=$row['username'];?></td>
  31.  
  32.     </tr>
  33.  
  34. <?}?>
  35.  
  36. </table>
  37.  
  38. <? include("footer.php");?>
  39.  
  40.  


thanks rapid
  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

PHP Code: [ Select ]
 
<?
 
include("header.php");
 
$columns = 2;
 
mysql_connect('localhost','kilo69','kilo69');
 
mysql_select_db('69kilobytes_co_uk_portal');
 
//change the query to get another field from the database
 
$query = "SELECT username, image FROM members ORDER BY id";
 
$result = mysql_query($query);
 
$i    = 0;
 
?>
 
<table border="0">
 
<?
 
while($row = mysql_fetch_array($result)) {
 
    $counter = $i % 3
 
    if ($counter == 0 || $i == 0) {
 
        echo "<tr>";
 
    }
 
   echo "<td><img src=\"=".$row['image']."\"/></td><td>".$row['username']."</td> ";
 
   if ($counter == 0) {
 
      echo "<tr>"   ;
 
   }
 
   $i = $i+1;
 
}
 
?>
 
</table>
 
<? include("footer.php");?>
 
 
  1.  
  2. <?
  3.  
  4. include("header.php");
  5.  
  6. $columns = 2;
  7.  
  8. mysql_connect('localhost','kilo69','kilo69');
  9.  
  10. mysql_select_db('69kilobytes_co_uk_portal');
  11.  
  12. //change the query to get another field from the database
  13.  
  14. $query = "SELECT username, image FROM members ORDER BY id";
  15.  
  16. $result = mysql_query($query);
  17.  
  18. $i    = 0;
  19.  
  20. ?>
  21.  
  22. <table border="0">
  23.  
  24. <?
  25.  
  26. while($row = mysql_fetch_array($result)) {
  27.  
  28.     $counter = $i % 3
  29.  
  30.     if ($counter == 0 || $i == 0) {
  31.  
  32.         echo "<tr>";
  33.  
  34.     }
  35.  
  36.    echo "<td><img src=\"=".$row['image']."\"/></td><td>".$row['username']."</td> ";
  37.  
  38.    if ($counter == 0) {
  39.  
  40.       echo "<tr>"   ;
  41.  
  42.    }
  43.  
  44.    $i = $i+1;
  45.  
  46. }
  47.  
  48. ?>
  49.  
  50. </table>
  51.  
  52. <? include("footer.php");?>
  53.  
  54.  


try this. Will explain it to you if it works

By the way its Rabid with a b not a p ;>
  • Nem
  • Guru
  • Guru
  • Nem
  • Posts: 1243
  • Loc: UK

Post 3+ Months Ago

PHP Code: [ Select ]
 
<?
 
include("header.php");
 
$columns = 2;
 
mysql_connect('localhost','kilo69','kilo69');
 
mysql_select_db('69kilobytes_co_uk_portal');
 
//change the query to get another field from the database
 
$query = "SELECT username, image FROM members";
 
$result = mysql_query($query);
 
$i        = 0;
 
?>
 
<table border="0">
 
<?
 
while($row = mysql_fetch_array($result)) {
 
     $counter = $i % 3
 
     if ($counter == 0 || $i == 0) {
 
         echo "<tr>";
 
     }
 
    echo "<td><img src=\"=".$row['image']."\"/></td><td>".$row['username']."</td> ";
 
    if ($counter == 0) {
 
         echo "<tr>"   ;
 
    }
 
    $i = $i+1;
 
}
 
?>
 
</table>
 
<? include("footer.php");?>
 
 
  1.  
  2. <?
  3.  
  4. include("header.php");
  5.  
  6. $columns = 2;
  7.  
  8. mysql_connect('localhost','kilo69','kilo69');
  9.  
  10. mysql_select_db('69kilobytes_co_uk_portal');
  11.  
  12. //change the query to get another field from the database
  13.  
  14. $query = "SELECT username, image FROM members";
  15.  
  16. $result = mysql_query($query);
  17.  
  18. $i        = 0;
  19.  
  20. ?>
  21.  
  22. <table border="0">
  23.  
  24. <?
  25.  
  26. while($row = mysql_fetch_array($result)) {
  27.  
  28.      $counter = $i % 3
  29.  
  30.      if ($counter == 0 || $i == 0) {
  31.  
  32.          echo "<tr>";
  33.  
  34.      }
  35.  
  36.     echo "<td><img src=\"=".$row['image']."\"/></td><td>".$row['username']."</td> ";
  37.  
  38.     if ($counter == 0) {
  39.  
  40.          echo "<tr>"   ;
  41.  
  42.     }
  43.  
  44.     $i = $i+1;
  45.  
  46. }
  47.  
  48. ?>
  49.  
  50. </table>
  51.  
  52. <? include("footer.php");?>
  53.  
  54.  


i seem to be getting an error on:

PHP Code: [ Select ]
 
 if ($counter == 0 || $i == 0) {
 
 
  1.  
  2.  if ($counter == 0 || $i == 0) {
  3.  
  4.  
  • Nem
  • Guru
  • Guru
  • Nem
  • Posts: 1243
  • Loc: UK

Post 3+ Months Ago

ok here is the new code

PHP Code: [ Select ]
 
<?
 
include("header.php");
 
if (@ $id) {
 
    // I assume all this works, so I omit it for brevity
 
} else {
 
    // show employee list
 
   include('connect.php');
 
    $query = mysql_query("SELECT * FROM members ORDER BY id ASC",$db);
 
    $COLUMNS = (int) 2; // change if you want a different number of columns
 
    $i = (int) 0;
 
    while ($myrow = mysql_fetch_array($result)) {
 
        if($i++ == 0) { // first column
 
            printf("<tr>"); // start a row
 
        }
 
        printf("<td align=center><a href=\"%s?id=%s\">%s<br>%s</a></td> ",
 
            $PHP_SELF, $myrow["image"], $myrow["username"]);
 
        if($i == $COLUMNS) { // last column
 
            printf("</tr>");  // end a row
 
            $i = 0; // next column is a first column
 
        }
 
    }
 
    // "what if" cleanup code:
 
    if($i > 0) { // *plum*, we ended in the middle of a row!
 
        while($i++ != $COLUMNS) { // for each remaining column,
 
            printf("<td>&nbsp;</td>"); // add an empty cell
 
        }
 
        printf("</tr>"); // end the row
 
    }
 
}
 
?>
 
 
 
<? include("footer.php");?>
 
 
  1.  
  2. <?
  3.  
  4. include("header.php");
  5.  
  6. if (@ $id) {
  7.  
  8.     // I assume all this works, so I omit it for brevity
  9.  
  10. } else {
  11.  
  12.     // show employee list
  13.  
  14.    include('connect.php');
  15.  
  16.     $query = mysql_query("SELECT * FROM members ORDER BY id ASC",$db);
  17.  
  18.     $COLUMNS = (int) 2; // change if you want a different number of columns
  19.  
  20.     $i = (int) 0;
  21.  
  22.     while ($myrow = mysql_fetch_array($result)) {
  23.  
  24.         if($i++ == 0) { // first column
  25.  
  26.             printf("<tr>"); // start a row
  27.  
  28.         }
  29.  
  30.         printf("<td align=center><a href=\"%s?id=%s\">%s<br>%s</a></td> ",
  31.  
  32.             $PHP_SELF, $myrow["image"], $myrow["username"]);
  33.  
  34.         if($i == $COLUMNS) { // last column
  35.  
  36.             printf("</tr>");  // end a row
  37.  
  38.             $i = 0; // next column is a first column
  39.  
  40.         }
  41.  
  42.     }
  43.  
  44.     // "what if" cleanup code:
  45.  
  46.     if($i > 0) { // *plum*, we ended in the middle of a row!
  47.  
  48.         while($i++ != $COLUMNS) { // for each remaining column,
  49.  
  50.             printf("<td>&nbsp;</td>"); // add an empty cell
  51.  
  52.         }
  53.  
  54.         printf("</tr>"); // end the row
  55.  
  56.     }
  57.  
  58. }
  59.  
  60. ?>
  61.  
  62.  
  63.  
  64. <? include("footer.php");?>
  65.  
  66.  


im getting the following error

Quote:
Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/virtual/site2/fst/var/www/html/members.php on line 8

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/virtual/site2/fst/var/www/html/members.php on line 11


Line 8 is:
PHP Code: [ Select ]
$result = mysql_query("SELECT * FROM members ORDER BY id ASC",$db);


and line 11 is:
PHP Code: [ Select ]
while ($myrow = mysql_fetch_array($result)) {


i dont understand why they are showing, i mean they should be connecting just fine?
  • Nem
  • Guru
  • Guru
  • Nem
  • Posts: 1243
  • Loc: UK

Post 3+ Months Ago

ok i sorted the connection out, now im getting error on line 17 saying:

Too few Printf() statements on line 17

PHP Code: [ Select ]
$PHP_SELF, $myrow["image"], $myrow["username"]);
  • rjstephens
  • Professor
  • Professor
  • User avatar
  • Posts: 774
  • Loc: Brisbane, Australia

Post 3+ Months Ago

try putting that bit on line 16
  • Nem
  • Guru
  • Guru
  • Nem
  • Posts: 1243
  • Loc: UK

Post 3+ Months Ago

the same error, i think its because of the quoatation marks on the first bit and none on the second?
  • Nem
  • Guru
  • Guru
  • Nem
  • Posts: 1243
  • Loc: UK

Post 3+ Months Ago

what is the parse error on this line of code:

PHP Code: [ Select ]
printf( "<td align=center>/"$PHP_SELF, $myrow["image"], $myrow["username"]"/</td>" );
  • Nem
  • Guru
  • Guru
  • Nem
  • Posts: 1243
  • Loc: UK

Post 3+ Months Ago

ok no more parse error, but now the footer isnt appearing and the rest of the contents apart from the header. :'(

:( whats wrong?

PHP Code: [ Select ]
 
<?
 
include("header.php");
 
if (@ $id) {
 
    // I assume all this works, so I omit it for brevity
 
} else {
 
    // show employee list
 
$db = mysql_connect("localhost", "", "");
 
mysql_select_db("69kilobytes_co_uk_portal",$db);
 
$result = mysql_query("SELECT * FROM news ORDER BY id DESC",$db);
 
    $COLUMNS = (int) 2; // change if you want a different number of columns
 
    $i = (int) 0;
 
   while ($myrow = mysql_fetch_array($result)) {
 
        if($i++ == 0) { // first column
 
            echo("<tr>"); // start a row
 
        }
 
 
 
 
 
echo "<td align=center>\"$PHP_SELF $myrow[image] $myrow[username]\"</td>";
 
 
 
        if($i == $COLUMNS) { // last column
 
            echo("</tr>");  // end a row
 
            $i = 0; // next column is a first column
 
        }
 
    }
 
    // "what if" cleanup code:
 
    if($i > 0) { // *plum*, we ended in the middle of a row!
 
        while($i++ != $COLUMNS) { // for each remaining column,
 
            echo("<td>&nbsp;</td>"); // add an empty cell
 
        }
 
        echo("</tr>"); // end the row
 
    }
 
}
 
?>
 
 
 
<? include("footer.php");?>
 
 
  1.  
  2. <?
  3.  
  4. include("header.php");
  5.  
  6. if (@ $id) {
  7.  
  8.     // I assume all this works, so I omit it for brevity
  9.  
  10. } else {
  11.  
  12.     // show employee list
  13.  
  14. $db = mysql_connect("localhost", "", "");
  15.  
  16. mysql_select_db("69kilobytes_co_uk_portal",$db);
  17.  
  18. $result = mysql_query("SELECT * FROM news ORDER BY id DESC",$db);
  19.  
  20.     $COLUMNS = (int) 2; // change if you want a different number of columns
  21.  
  22.     $i = (int) 0;
  23.  
  24.    while ($myrow = mysql_fetch_array($result)) {
  25.  
  26.         if($i++ == 0) { // first column
  27.  
  28.             echo("<tr>"); // start a row
  29.  
  30.         }
  31.  
  32.  
  33.  
  34.  
  35.  
  36. echo "<td align=center>\"$PHP_SELF $myrow[image] $myrow[username]\"</td>";
  37.  
  38.  
  39.  
  40.         if($i == $COLUMNS) { // last column
  41.  
  42.             echo("</tr>");  // end a row
  43.  
  44.             $i = 0; // next column is a first column
  45.  
  46.         }
  47.  
  48.     }
  49.  
  50.     // "what if" cleanup code:
  51.  
  52.     if($i > 0) { // *plum*, we ended in the middle of a row!
  53.  
  54.         while($i++ != $COLUMNS) { // for each remaining column,
  55.  
  56.             echo("<td>&nbsp;</td>"); // add an empty cell
  57.  
  58.         }
  59.  
  60.         echo("</tr>"); // end the row
  61.  
  62.     }
  63.  
  64. }
  65.  
  66. ?>
  67.  
  68.  
  69.  
  70. <? include("footer.php");?>
  71.  
  72.  
  • Scorpius
  • Proficient
  • Proficient
  • User avatar
  • Posts: 401
  • Loc: Scorpion Hole

Post 3+ Months Ago

Well, unless you have created that the table for the columns in the header, and clost it in the footer, you should probably do that.

Post Information

  • Total Posts in this topic: 16 posts
  • Users browsing this forum: No registered users and 83 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.