SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Guru
    Join Date
    Oct 2004
    Location
    uk
    Posts
    853
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    array into html table

    Hi guys

    Im calling a array from my database

    it lists 16 category names

    I want to put these into a html table

    How can I do this?


    PHP Code:
    <?php


    //connect to your database ** EDIT REQUIRED HERE **
    mysql_connect("localhost","notexper_two","three"); //(host, username, password)

    //specify database ** EDIT REQUIRED HERE **
    mysql_select_db("notexper_one") or die("Unable to select database"); //select which database we're using


                  
    $sql " select * from category";

                  
    $result mysql_query ($sql);

                  while (
    $row mysql_fetch_array($result))
                  {

                  
    $field1$row["category"];
                 
               


    echo 
    "<A href=sector.php?category=$field1>$field1</a><br>";






    }
    ?>

  2. #2
    SitePoint Addict mmanders's Avatar
    Join Date
    Jul 2006
    Location
    Edinburgh, Scotland
    Posts
    358
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This will just be returning 16 results - what kind of table do you want. Is it just one column and 16 rows with each result in a cell, or are the results to form column headers, i.e. 16 columns, 1 row?!

  3. #3
    SitePoint Addict mmanders's Avatar
    Join Date
    Jul 2006
    Location
    Edinburgh, Scotland
    Posts
    358
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You basically want to do something like this

    Code PHP:
    <!-- First construct the start of the table -->
    <table>
    <!-- Then start your PHP -->
    <?php
    mysql_connect("localhost","notexper_two","three");
    mysql_select_db("notexper_one") or die("Unable to select database");
    $sql = "select * from category";
    $result = mysql_query($sql);
    while ($row = mysql_fetch_array($result))
    {
    ?>
       <tr>
          <td>
          <?php
             echo $row["category"];
          ?>
          </td>
       </tr>
    <?php
    }
    ?>

  4. #4
    SitePoint Guru
    Join Date
    Oct 2004
    Location
    uk
    Posts
    853
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I want to put them in to 2 rows

  5. #5
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Could you please show us your category table structure in the database so that it would be more easier to tell you and give some code also?
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  6. #6
    SitePoint Member
    Join Date
    Sep 2006
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you could do like this
    echo"<tr>";
    while($i<8)
    {
    echo "<td>$field[$i]</td>";
    $i++;
    }
    echo"</tr>

    echo"<tr>";
    while($i<16)
    {
    echo "<td>$field[$i]</td>";
    $i++;
    }
    echo"</tr>";
    This will solve your problem

  7. #7
    SitePoint Guru
    Join Date
    Oct 2004
    Location
    uk
    Posts
    853
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nothing is displaying?

    Can you see what im doing wrong


    PHP Code:
    <? 

     $id 
    $_GET['id'];

                  
    $sql " select * from category";

                  
    $result mysql_query ($sql);

                  while (
    $row mysql_fetch_array($result))
                  {

                  
    $field1$row["category"];
                 
               





    while(
    $row<8)
    {
    echo 
    "<Td><A href=sector.php?category=$field1>$field1</a></td>";
    $field1++;
    }
    echo
    "</tr>";

    echo
    "<tr>";
    while(
    $row<16)
    {
    echo 
    "<Td><A href=sector.php?category=$field1>$field1</a></td>";
    $field1++;
    }
    echo
    "</tr>";













    }



    ?>

  8. #8
    SitePoint Evangelist
    Join Date
    Aug 2005
    Posts
    453
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $id $_GET['id'];
    $sql " select * from category";
    $result mysql_query ($sql);

    $i 0;
    $row mysql_fetch_array$result );

    echo 
    "<table><tr>";
    while( 
    $i<) {
        echo 
    "<Td><A href=sector.php?category=$row['category']>$row['category']</a></td>";
        
    $row mysql_fetch_array$result );
        
    $i++;
    }

    echo 
    "</tr>";
    echo 
    "<tr>";

    while( 
    $i >= && $i<16 ) {
        echo 
    "<Td><A href=sector.php?category=$row['category']>$row['category']</a></td>";
        
    $row mysql_fetch_array$result );
        
    $i++;
    }

    echo 
    "</tr></table>"
    Computers and Fire ...
    In the hands of the inexperienced or uneducated,
    the results can be disastrous.
    While the professional can tame, master even conquer.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •