Results 1 to 2 of 2

Thread: Alternate Table View

  1. #1
    Join Date
    Oct 2006
    Posts
    94
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Cool Alternate Table View

    It was a bit hard to discribe this topic in the subject so please feel free to amend it to something better!!

    Here's the script in original working form...

    PHP Code:
    $query = "SELECT `Name`, `Country`, `Location` FROM `approved`";
    $result = mysql_query($query) 
    or die(mysql_error()); 
    ?>
      <center>
      <table border="5" cellpadding="5" cellspacing="0" style="border-collapse: collapse" bordercolor="#808080" width="80%" id="AutoNumber1" bgcolor="#C0C0C0">
        <tr>
          <td width="20%" align="center" bgcolor="#FFFFcc"><b>Name</b></td>
          <td width="20%" align="center" bgcolor="#FFFFcc"><b>Country</b></td>
          <td width="20%" align="center" bgcolor="#FFFFcc"><b>Location</b></td>
        </tr>
    <?php
    while(list($Name$Country$Location)=mysql_fetch_row($result))

    ?>
        <tr>
          <td width="20%" align="center"><b><font color="#0000FF">=</font><font color="#FFFFFF">(</font><font color="#00FFFF">SC</font><font color="#FFFFFF">)</font><font color="#0000FF">=</font><span class="name-firstletter"><?php echo($Name[0]); ?></span><span class="name-rest"><?php echo(substr($Name1)); ?></span></b></td>
          <td width="20%" align="center"><?php echo($Country);?></td>
          <td width="20%" align="center"><?php echo($Location);?></td>
    </tr>
    <?php
    }
    Basically, when my data is outputted it looks something like this.....

    --------------------------------------------------------
    | ID | | Name | | Country | | Location |
    --------------------------------------------------------
    | 1 | | "name" | | "country" | | "location" |
    ---------------------------------------------------------

    The problem I have with this is I have 19 fields which causes the table to be so long across the page. It would be better if I could have the fields going down instead of across. I have tried to do it myself but all that happens is this.....

    ----------------------------------
    | ID | | 1 |
    ---------------------------------
    | Name | | "name" |
    ----------------------------------
    | Country | | "country" |
    ----------------------------------
    | Location | | "location" |
    ----------------------------------
    | ID | | 2 |
    ---------------------------------
    | Name | | "name" |
    ----------------------------------
    | Country | | "country" |
    ----------------------------------
    | Location | | "location" |
    ----------------------------------

    What I want is this............

    ---------------------------------------------------
    | ID | | 1 | | 2 |
    ---------------------------------------------------
    | Name | | "name" | | "name" |
    ---------------------------------------------------
    | Country | | "country" | | "country" |
    ---------------------------------------------------
    | Location | | "location" | | "location" |
    ----------------------------------------------------

    Here's my script for the output so far.....


    PHP Code:
    <?php 
    $query 
    "SELECT * FROM approved"
    $result mysql_query($query)  
    or die(
    mysql_error());  
    while(list(
    $id$Name$Country$Location)=mysql_fetch_row($result)) 
    {  
    ?> 
    <table border="5" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#808080" width="40%" id="AutoNumber1" bgcolor="#C0C0C0"> 
      <tr> 
        <td width="50%" bgcolor="#FFFFcc"><b>ID</b></td> 
        <td width="50%"><?php echo($id);?></td> 
      </tr> 
      <tr> 
        <td width="50%" bgcolor="#FFFFcc"><b>Name</b></td> 
        <td width="50%"><?php echo($Name);?></td> 
      </tr> 
      <tr> 
        <td width="50%" bgcolor="#FFFFcc"><b>Country</b></td> 
        <td width="50%"><?php echo($Country);?></td> 
      </tr> 
      <tr> 
        <td width="50%" bgcolor="#FFFFcc"><b>Location</b></td> 
        <td width="50%"><?php echo($Location);?></td> 
      </tr> 
    <?php 

    ?> 
    </table> 
    </center>
    Hope this helps someone to help me! Thanks in advance.

  2. #2
    Join Date
    Oct 2006
    Posts
    94
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Never mind!!! Ive done it.

    For those who are interested....

    PHP Code:
    <?php
    include '../sql/config.php';
    $sql mysql_query("SELECT * FROM approved") or die(mysql_error()); 

    //while($row = mysql_fetch_row($sql)){
    while($row mysql_fetch_array($sqlMYSQL_ASSOC)){

    $id .= "<td width='50%'>" $row['id'] . "</td>";
    $name .= "<td width='50%'>" $row['Name'] . "</td>";
    $country .= "<td width='50%'>" $row['Country'] . "</td>";
    $location .= "<td width='50%'>" $row['Location'] . "</td>";
    }
    ?>
    <table border="5" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#808080" width="40%" id="AutoNumber1" bgcolor="#C0C0C0">
      <tr>
        <td width="50%" bgcolor="#FFFFcc"><b>ID</b></td>
        <?php echo $id;?>
      </tr>
      <tr>
        <td width="50%" bgcolor="#FFFFcc"><b>Name</b></td>
        <?php echo $name;?>
      </tr>
      <tr>
        <td width="50%" bgcolor="#FFFFcc"><b>Country</b></td>
        <?php echo $country;?>
      </tr>
      <tr>
        <td width="50%" bgcolor="#FFFFcc"><b>Location</b></td>
        <?php echo $location;?>
      </tr>
    <?php
    include '../sql/configend.php';
    ?>
    </table>
    </center>

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
  •