Jump to content

help with layout of multiple results in table... *SOLVED*


brown2005

Recommended Posts

[code]$query = mysql_query("SELECT LEFT(field, 1)  as 'first', field FROM table ORDER by first ASC");
$letter='';
while ($row=mysql_fetch_array($query)) {
if ($row['first'] !== $letter) {
  $letter=$row['first'];
  echo "<B>$first</b><br>";
}
if ($row['first'] == $letter) {
  echo "$row[field]<br>";
}
}[/code]


i beleave that should* work but hasn't been tested
Link to comment
Share on other sites

$query = mysql_query("SELECT LEFT(topic_a, 1)  as 'first', topic_a FROM A ORDER by first ASC");

$letter='';

while ($row=mysql_fetch_array($query))
{

if ($row['first'] !== $letter)
{
 
  $letter=$row['first'];
 
echo "<B>$first</b><br>";

}

if ($row['first'] == $letter)
{
 
  echo "$row[topic_a]<br>";
 
}

}

i have used the above and get http://www.fantasy-comps.com/a.php

but hasnt actually done what I wanted... i wanted the letter above it and then in the same row, and if fills up the row the next row....

i.e.

[b]A[/b]

a, ab, ac, ad, ae, af
ag, ah, ai, aj

[b]B[/b]

b
b, ba, bb, bc


Link to comment
Share on other sites

Do you mean
[code]
<?php

$query = mysql_query("SELECT LEFT(topic_a, 1)  as 'first', topic_a FROM A ORDER by topic_a");

$letter='';

while (list($first,$topic)=mysql_fetch_row($query))
{

  if ($first !== $letter)
  {

    $letter = $first;
    $count = 0;
    echo "<h3>" . strtoupper($first)  . "</h3>";
   
  }

  if (!$count) echo "$letter,";
  echo " $topic";
  $count++;
  if ($count%5 == 4) echo '<br>';
}

?>[/code]
Link to comment
Share on other sites

Hi, That is looking more like I want, but it needs a few adjustments, view [url=http://www.links-bid.com/1.php to]http://www.links-bid.com/1.php to[/url] and you will see.

I want the letter moved from the start, not the bold one the one say like a, and then it should have a , after every topic.....

Thanks for all your help
Link to comment
Share on other sites

[code]
<?php

$query = mysql_query("SELECT LEFT(topic_a, 1)  as 'first', topic_a FROM A ORDER by topic_a");

$letter='';

while (list($first,$topic)=mysql_fetch_row($query))
{

  if ($first !== $letter)
  {

    $letter = $first;
    $count = 0;
    echo "<h3>" . strtoupper($first)  . "</h3>";
   
  }

  echo ($count) ? "," : "";
  if ($count && $count%5 == 0) echo '<br>';
  echo ($count) ? " $topic" : "$topic";
  $count++;
}

?>[/code]

EDIT: In your reply #4 you said you wanted letter on row
[quote]i wanted the letter above it and then in the same row, [/quote]
Link to comment
Share on other sites

    echo"<table width='500' border='1' cellpadding='0' cellspacing='0'>";
    echo" <tr>
          <td>";
     
  echo ($count) ? "," : "";
  if ($count && $count%10 == 0) echo '<br>';
    echo ($count) ? " $topics_topic" : "$topics_topic";

    $count++;

echo"</td>
      </tr>";
echo"</table>";

Hi i have tried putting the results in a table so they can be easily aligned and stuff, but it comes out all wrong....

check www.allinthissite.co.uk for what happens...

is this the best way to do it in a table or would i use a div or something else?
Link to comment
Share on other sites

or use css

[code]<STYLE content="text/css">
DIV.item {
    width: 100px;
    height: 20px;
    float: left;
    padding: 3px;
    text-align: left;
    font-size: 0.8em;
    font-weight: 300;
    border:  1px solid #EEE;
}
DIV.head {
    width: 500px;
    height: 40px;
    padding: 13px 3px ;
    text-align: left;
    font-size: 0.9em;
    font-weight: 600;
    margin-top: 15px;
}
BR {
    clear: both;
}
</STYLE>
<?php
include 'db2.php';
define ("COLS", 5);

$query = mysql_query("SELECT LEFT(topic_a, 1)  as 'first', topic_a FROM A ORDER by topic_a");

$letter='';

while (list($first,$topic)=mysql_fetch_row($query))
{

  if ($first !== $letter)
  {

        $letter = $first;
        $count = 0;
        echo "<br/><DIV class='head'>" . strtoupper($first)  . "</DIV>";
   
  }

  if ($count && $count % COLS == 0) echo '<br>';
  echo  "<DIV class='item'>$topic</DIV>";
  $count++;
}

?>[/code]
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.