hmm

Discussion in 'PHP' started by terryuk, Dec 6, 2006.

  1. #1
    I'm wondering if anyone can help me out - i'm in the middle of making a new script, it grabs data from a table, and sorts the data alphabetically. The data will be placed in a table, but at the moment it does each result on a new line, i need it so it makes two columns for the first two results then moves down and makes another two etc..

    hope i explained enough.. thanks:eek:
     
    terryuk, Dec 6, 2006 IP
  2. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #2
    use colspan in the table html....
     
    krakjoe, Dec 6, 2006 IP
  3. terryuk

    terryuk Notable Member

    Messages:
    3,962
    Likes Received:
    319
    Best Answers:
    0
    Trophy Points:
    255
    #3
    Oh nah i know that - i mean i dunno the coding to make it seperate it into two columns etc
     
    terryuk, Dec 6, 2006 IP
  4. daboss

    daboss Guest

    Messages:
    2,249
    Likes Received:
    151
    Best Answers:
    0
    Trophy Points:
    0
    #4
    try this...

    print "<table>";
    
    while still got items to process {
      print "<tr>";
    
      while less than 2 times {
        print "<td>";
        if(still got items to process) {
          print item
        }
        else {
          leave empty
        }
        print "</td>";
      }
    
      print "</tr>";
    }
    
    print "</table>";
    Code (markup):
     
    daboss, Dec 6, 2006 IP
  5. terryuk

    terryuk Notable Member

    Messages:
    3,962
    Likes Received:
    319
    Best Answers:
    0
    Trophy Points:
    255
    #5
    Daboss - thanks i will try it afterwards, but i've came across another issue which i dont know how to fix. I havent done php in a year and i wish i kept with it :(

    But i have;
    
       $sql = "select * from breeds order by name";
       $result = mysql_query($sql, $conn) or die(mysql_error());
      
       while ($list = mysql_fetch_array($result)) {
          $letter = strtoupper(substr($list['name'],0,1));
          if ($letter != $prev_row) {
             echo "<br><table width=\"100%\" class=\"contenttable\" cellpadding=\"0\" cellspacing=\"0\">
      <tr>
        <td width=\"22\" height=\"22\" class=\"contentbox\"> '"; echo($letter); echo ("' Dog Breeds</td>
      </tr>
      <tr>
        <td class=\"in\"><p>");
          }
          $name = $list['name'];
      
          foreach($breed as $name => $letter){ echo "<a href=\"info/$name/\">$name</a> -"; }
           
       if($letter != $prev_row){
       echo("</p></td>
          </tr>
        </table> "); }    $prev_row = $letter;   
    	   } 
    
    Code (markup):
    that should print out each field which is under A, B, C, D etc, but i find that it echo's the first field then the second goes into an empty space out of the table, then the first B item works etc.

    Sorry but has anyone got any ideas :confused: :eek: Sorry if im been a pain in the ass

    I tried adding foreach() rather than echo for the fields but it doesnt seem to work. I just need it to echo all A's in the A table :confused:
     
    terryuk, Dec 6, 2006 IP
  6. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #6
    I'm having some lunch, after I'll look....
     
    krakjoe, Dec 6, 2006 IP
  7. terryuk

    terryuk Notable Member

    Messages:
    3,962
    Likes Received:
    319
    Best Answers:
    0
    Trophy Points:
    255
    #7
    Right i've taken a look on PHPfreaks.com and changed the code that i posted before to this;

    
    <?php
               include('conn.php');
                $sql = 'SELECT * FROM breeds ORDER BY name';
                $result = mysql_query($sql) or die('ERROR: '.$query.' '.mysql_error());
                $letterlinks = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
                echo '<a name="top"></a>';
                echo '<a href="#number">0-9</a> ';
                for ($i = 0; $i < 37; $i++):
                    echo '<a href="#'.$letterlinks[$i].'">'.$letterlinks[$i].'</a> ';
                endfor;
                while ($list = mysql_fetch_object($result)):
                    $letter = strtoupper(substr($list->name, 0, 1));
                    if ($prev_row != '0-9' && is_numeric($letter)):
                        echo '<br /><a name="number"></a><b><u>0-9</u></b> ';
                        echo '<a href="top"><i>goto top</i></a><br />';
                        $prev_row = '0-9';
                    endif;
                    if ($letter != $prev_row && !is_numeric($letter)):
                        echo '<br /><a name="'.$letter.'"></a><b><u>'.$letter.'</u></b> ';
                        echo '<a href="top"><i>goto top</i></a><br />';
                        $prev_row = $letter;
                    endif;
                    echo $list->name.'<br />';
                endwhile;
            ?> 
    
    Code (markup):
    to display the results in order, it works but i want to add a table around each letter but i cant figure it out :eek: I need to be able to put a line of code before and after each letter is displayed... any ideas..
     
    terryuk, Dec 7, 2006 IP
  8. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #8
    can I se the output of that so I know what you mean ?
     
    krakjoe, Dec 7, 2006 IP
  9. terryuk

    terryuk Notable Member

    Messages:
    3,962
    Likes Received:
    319
    Best Answers:
    0
    Trophy Points:
    255
    #9
    I only have it on localhost right now but it looks something like

    A - to top
    Abba
    Abby

    B - to top
    Bob
    Billy

    etc etc

    But i need to be able to put code after the end of each letter so something at the end of A and B etc
     
    terryuk, Dec 7, 2006 IP
  10. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #10
    so change what you have there to reflect what you want ....
     
    krakjoe, Dec 7, 2006 IP