html table trouble

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • _Skare_Krow_

    #1

    html table trouble

    I have a database with three columns. One is an atomic number, one is a
    pic url, and the other is a description. What I'm having trouble doing
    is putting the url in one table row and the description in another table
    row right below it like this...
    <tr<tdsome pic url</td<tdother pic url</td></tr>
    <tr><tdsome descripts </td<tdother descript </td></tr>

    whilest limiting the rows to about 10 cells each,,....

    any ideas?

    Aaron
  • iktorn

    #2
    Re: html table trouble

    _Skare_Krow_ napisał(a):
    I have a database with three columns. One is an atomic number, one is a
    pic url, and the other is a description. What I'm having trouble doing
    is putting the url in one table row and the description in another table
    row right below it like this...
    <tr<tdsome pic url</td<tdother pic url</td></tr>
    <tr><tdsome descripts </td<tdother descript </td></tr>
    >
    whilest limiting the rows to about 10 cells each,,....
    >
    any ideas?
    >
    Aaron
    The easiest way is to use CSS - div + float property.
    <?php

    $arr =array(
    array("file1"," desc1"),
    array("file2"," desc2"),
    array("file3"," desc3"),
    array("file4"," desc4"),
    array("file5"," desc5"),
    array("file6"," desc6"),
    array("file7"," desc7"),
    );

    define('TABLE_C OLS',4);

    print "<table>".PHP_E OL;
    $i=1;
    while(list($key ,$row) = each($arr)) {
    $tmp[$i]=$row;
    if($i++==TABLE_ COLS) {
    print "<tr>";
    for($j=1;$j<=TA BLE_COLS;$j++) {
    print "<td>".$tmp[$j][0]."</td>";
    }
    print "</tr>".PHP_EOL;
    print "<tr>";
    for($j=1;$j<=TA BLE_COLS;$j++) {
    print "<td>".$tmp[$j][1]."</td>";
    }
    print "</tr>".PHP_EOL;
    $i=1;
    }
    }
    if($i>1) {
    print "<tr>";
    for($j=1;$j<=TA BLE_COLS;$j++) {
    print "<td>".(($j<$i) ?$tmp[$j][0]:"")."</td>";
    }
    print "</tr>".PHP_EOL;
    print "<tr>";
    for($j=1;$j<=TA BLE_COLS;$j++) {
    print "<td>".(($j<$i) ?$tmp[$j][1]:"")."</td>";
    }
    print "</tr>".PHP_EOL;
    }
    print "</table>";



    --
    Wiktor Walc

    Comment

    • Jerry Stuckle

      #3
      Re: html table trouble

      _Skare_Krow_ wrote:
      I have a database with three columns. One is an atomic number, one is a
      pic url, and the other is a description. What I'm having trouble doing
      is putting the url in one table row and the description in another table
      row right below it like this...
      <tr<tdsome pic url</td<tdother pic url</td></tr>
      <tr><tdsome descripts </td<tdother descript </td></tr>
      >
      whilest limiting the rows to about 10 cells each,,....
      >
      any ideas?
      >
      Aaron
      Hi, Aaron,

      Two easy ways - as you go through the result set to get your url, save
      the matching description in an array. Then when you're done with your
      url's, you can go through the description array and get the values.

      The other way is after going through the result set to get your url, use
      mysql_data_seek () to reposition the internal pointer and go through the
      result set a second time to get the descriptions.
      --
      =============== ===
      Remove the "x" from my email address
      Jerry Stuckle
      JDS Computer Training Corp.
      jstucklex@attgl obal.net
      =============== ===

      Comment

      • shimmyshack

        #4
        Re: html table trouble

        On Apr 26, 6:28 am, _Skare_Krow_ <petra2...@gmai l.comwrote:
        I have a database with three columns. One is an atomic number, one is a
        pic url, and the other is a description. What I'm having trouble doing
        is putting the url in one table row and the description in another table
        row right below it like this...
        <tr<tdsome pic url</td<tdother pic url</td></tr>
        <tr><tdsome descripts </td<tdother descript </td></tr>
        >
        whilest limiting the rows to about 10 cells each,,....
        >
        any ideas?
        >
        Aaron
        once you have your results in a 2d array, use 2 loops, one to create
        the cells, which steps through the array echoing pics iterating by
        one, the outer loop iterates by however many cells you used, if 10
        then $i+=10, you could use array_shift with less complexity but it
        might be slower.

        you could use fluid (floating) css with a simple array and just set
        the number of columns using css instead.

        Comment

        • Jeff North

          #5
          Re: html table trouble

          On Thu, 26 Apr 2007 00:28:45 -0500, in comp.lang.php _Skare_Krow_
          <petra2201@gmai l.com>
          <nJmdnd-T__sfpa3bnZ2dnU VZ_rGinZ2d@sysm atrix.netwrote:
          >| I have a database with three columns. One is an atomic number, one is a
          >| pic url, and the other is a description. What I'm having trouble doing
          >| is putting the url in one table row and the description in another table
          >| row right below it like this...
          >| <tr<tdsome pic url</td<tdother pic url</td></tr>
          >| <tr><tdsome descripts </td<tdother descript </td></tr>
          >|
          >| whilest limiting the rows to about 10 cells each,,....
          >|
          >| any ideas?
          >|
          >| Aaron
          <?php
          //--- init record limit var
          $start=0;

          //--- open connection to db and table

          //--- get page number from url/post var
          //--- and update the $start var

          //--- create the query
          $sql = "SELECT * FROM table LIMIT {$start},{start + 10}";
          //--- execute query
          $row1=""; $row2="";
          for($i=0; $i<count($resul t); $i++)
          {
          $row1 .= "<td><img src'".$result[$i]->pic_url."'</td>";
          $row2 .= "<td>".$res ult[$i]->pic_desc."</td>";
          }
          ?>

          <table>
          <tr><?php echo $row1;></tr>
          <tr><?php echo $row2;></tr>
          </table>
          ---------------------------------------------------------------
          jnorthau@yourpa ntsyahoo.com.au : Remove your pants to reply
          ---------------------------------------------------------------

          Comment

          • _Skare_Krow_

            #6
            Re: html table trouble

            Jeff North wrote:
            On Thu, 26 Apr 2007 00:28:45 -0500, in comp.lang.php _Skare_Krow_
            <petra2201@gmai l.com>
            <nJmdnd-T__sfpa3bnZ2dnU VZ_rGinZ2d@sysm atrix.netwrote:
            >
            >| I have a database with three columns. One is an atomic number, one is a
            >| pic url, and the other is a description. What I'm having trouble doing
            >| is putting the url in one table row and the description in another table
            >| row right below it like this...
            >| <tr<tdsome pic url</td<tdother pic url</td></tr>
            >| <tr><tdsome descripts </td<tdother descript </td></tr>
            >|
            >| whilest limiting the rows to about 10 cells each,,....
            >|
            >| any ideas?
            >|
            >| Aaron
            >
            <?php
            //--- init record limit var
            $start=0;
            >
            //--- open connection to db and table
            >
            //--- get page number from url/post var
            //--- and update the $start var
            >
            //--- create the query
            $sql = "SELECT * FROM table LIMIT {$start},{start + 10}";
            //--- execute query
            $row1=""; $row2="";
            for($i=0; $i<count($resul t); $i++)
            {
            $row1 .= "<td><img src'".$result[$i]->pic_url."'</td>";
            $row2 .= "<td>".$res ult[$i]->pic_desc."</td>";
            }
            ?>
            >
            <table>
            <tr><?php echo $row1;></tr>
            <tr><?php echo $row2;></tr>
            </table>
            ---------------------------------------------------------------
            jnorthau@yourpa ntsyahoo.com.au : Remove your pants to reply
            ---------------------------------------------------------------
            thanks everyone.. i've got enough info to try out.. i will post back
            with my success or failure :P

            aaron

            Comment

            • _Skare_Krow_

              #7
              Re: html table trouble

              _Skare_Krow_ wrote:
              I have a database with three columns. One is an atomic number, one is a
              pic url, and the other is a description. What I'm having trouble doing
              is putting the url in one table row and the description in another table
              row right below it like this...
              <tr<tdsome pic url</td<tdother pic url</td></tr>
              <tr><tdsome descripts </td<tdother descript </td></tr>
              >
              whilest limiting the rows to about 10 cells each,,....
              >
              any ideas?
              >
              Aaron
              Oh and you guys are so much nicer and more helpful than the javascript
              group...

              aaron

              Comment

              Working...