+ Reply to Thread
Results 1 to 2 of 2

Thread: HTML tag formating php and MySQL

  1. #1

    HTML tag formating php and MySQL

    I have the following MySQL statement :
    Code:
    Select
    type.type,
    color.color,
    ShotName ,
    Item.name,
    Item.Item_id
    From   type Inner Join  Item On type.type_id =Item.type_id Inner Join   color On color.color_id =Item.color_id Where  Item.state =0 And
     Item.offline = 0
     Group By 
     color.color,
     Item.name,
     type.order_nr
     Order By  
     type_D.order_nr,
     color.color,
     Item.name_d";
    How can do this with php to get a result formatted as the following html tag?
    HTML CODE :
    Code:
    <body>
    <h2> Type AA </h2>
    <h3> color black </h3>
    <ul>
    <li> ShortName 1 name 1</li>
    <li> ShortName 2 name 2</li>
    <li> ShortName 3 name 3</li>
    <li> ShortName 4 name 4</li>
    <li> ShortName 5 name 5</li>
    </ul>
    <h3> color green </h3>
    <ul>
    <li> ShortName 7 name 7</li>
    <li> ShortName 8 name 8</li>
    <li> ShortName 9 name 9</li>
    <li> ShortName 10 name 10</li>
    <li> ShortName 11 name 11</li>
    </ul>
    <h2> Type AB </h2>
    <h3> color black </h3>
    <ul>
    <li> ShortName 12 name 12</li>
    <li> ShortName 13 name 13</li>
    <li> ShortName 14 name 14</li>
    <li> ShortName 15name 15</li>
    <li> ShortName 16name 16</li>
    </ul>
    <h3> color green </h3>
    <ul>
    <li> ShortName 17 name 17</li>
    <li> ShortName 18 name 18</li>
    <li> ShortName 19 name 19</li>
    <li> ShortName 20 name 20</li>
    <li> ShortName 22 name 22</li>
    </ul>
    </body>
    Here is php code :
    Code:
    $myfile = mysql_query($query_myfile, $db) or die(mysql_error());
    $totalRows_myfile = mysql_num_rows($myfile);
    
        while ( $row_myfile = mysql_fetch_assoc($myfile) ) 
        {
           if ( $type != $row_myfile[ 'type' ] ) 
           {
    
               $type = $row_myfile[ 'type' ];
    
               echo "<h2>$type</h2>";
    
           }
           if ( $color != $row_myfile[ 'color' ] ) 
           {
    
               $color = $row_myfile[ 'color' ];
    
               echo "<h3>$color</h3>";
           }
    
           echo "<li><a href=\"itemDetail.php?item_id=".$row_myfile['myfile_id']. "\">";
           echo $row_myfile['ShortName'].' ';
           echo $row_myfile['name']; ?></a></li>

  2. #2
    Junior Member
    Join Date
    Jan 2012
    Posts
    40
    Code:
    $sql = "copy sql";
    
    $result_set = $result = mysql_query($sql);
    echo "<body>";
    $type = false;
    $color = false;
    $close_ul = false;
    while ($row = mysql_fetch_assoc($result)) {
        if ($type != $row['type']) {
            if ($close_ul) { 
                echo "</ul>"; 
                $close_ul = false;
            }
            $type = $row['type'];
            echo "<h2>$type</h2>";
            $color = false;
        }
        if ($color != $row['color']) {
            if ($close_ul) { 
                echo "</ul>"; 
                $close_ul = false;
            }
            $color = $row['color'];
            echo "<h3>$color</h3>";
            echo "<ul>";
            $close_ul = true;
        }
    
        echo "<li>",$row['shortname'],"</li>";
    }
    if ($close_ul) { 
        echo "</ul>"; 
        $close_ul = false;
    }
    echo "</body>";

+ Reply to Thread

Tags for this Thread

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