showing data from mysql in horizontal manner using php and html

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Vkas
    New Member
    • Feb 2009
    • 78

    #1

    showing data from mysql in horizontal manner using php and html

    I had one problem in php

    below is the code which fetches campus id and campus name form the mysql database and store them in two variables and using while loop i had fetch all the records from the Related table (Campus) by the code below
    Code:
                                                 <?php
    $query="SELECT * FROM campuses ORDER BY campus_id ASC"; 
    $result=mysql_query($query) or die(mysql_error());
    $rClr="ffffff";
    			  while($row=mysql_fetch_array($result)) {
    			   if($rClr=="ffffff"){
    			  $rClr="F7F7F7";
    			  }else{
    			  $rClr="ffffff";
    			  }	
    			  $campid= $row['campus_id'];
    			  $campnam= $row['campus_name'];
    			 
    ?>
    Below is the HTML embedded code that i want to repeat
    its a HTML table in which each campus name is fetched and shown and loop repeats itself until the last record is fetched

    Code:
        
    <tr>
                           <td align="center" valign="middle"><table width="260" border="0" cellpadding="2" cellspacing="2">
                              <tr>
         
                                <td align="center" valign="middle"  style="background-repeat:no-repeat;"  class="Eventheading"><a href="eventsdetail.php?camp_id=<?php print $campid?>&amp;campus_name=<?php print $campnam ?>" class="Eventheading" ><?php echo $row['campus_name'];?></a></td>
                              
                             </tr>
                            </table></td>
                           
                        
                          </tr>
    ending tag of the loop

    Code:
        <?php }?>

    My problem is that the loop always repeat the content vertical mean row wise

    such as
    ( campus name 1
    Campus name 2
    campus name 3 )
    but i want it to be shown horizontally

    LIke this ( campus name 1 Campus name 2 campus name 3)


    any idea can any one
  • Mayur2007
    New Member
    • Aug 2007
    • 67

    #2
    Hello Vkas,

    You have to generate tr conditionally like below
    Code:
    if($counter % 5 == 0) {
    echo "</tr><tr>"
    }
    <td><table>.... ..</table></td>
    the counter variable will be set to zero before while loop and incremented in the loop.

    Hope this will help you.

    Thanks & Regards,
    Mayur Bhayani

    Comment

    • Vkas
      New Member
      • Feb 2009
      • 78

      #3
      mean you want to say that

      Code:
      if($counter % 5 == 0) {
       echo "</tr>
      
      Remain content!!!!! here
      <tr>"
       }

      Comment

      • Vkas
        New Member
        • Feb 2009
        • 78

        #4
        this process works!!!
        but in this it tries to show all of the record in a single row by dividing that single row in several columns

        i want o display
        Campus name1 Capmus name 2 Campus name 3

        three values in a row

        Comment

        • Vkas
          New Member
          • Feb 2009
          • 78

          #5
          i had almost done let me explain you again

          Code:
          <tr>
                <?php
          $query="SELECT * FROM campuses ORDER BY campus_id ASC"; 
          $result=mysql_query($query) or die(mysql_error());
          $rClr="ffffff";
          			  while($row=mysql_fetch_array($result)) {
          			   if($rClr=="ffffff"){
          			  $rClr="F7F7F7";
          			  }else{
          			  $rClr="ffffff";
          			  }	
          			  $campid= $row['campus_id'];
          			  $campnam= $row['campus_name'];
          			 
          ?>    
                 <!-- BEGIN Grid range_menu -->
          <div id="horiz">
          <!-- BEGIN Row --><td align="center" valign="middle"><table width="248" border="0" cellpadding="2" cellspacing="0">
            <tr>
            
              <td width="248" height="69" align="center" valign="middle" background="http://bytes.com/images/eventsbg.jpg"  style="background-repeat:no-repeat;"  class="Eventheading"><a href="eventsdetail.php?camp_id=<?php print $campid?>&amp;campus_name=<?php print $campnam ?>" class="Eventheading" ><?php echo $row['campus_name'];?></a></td>
            </tr>
           
          </table></td> 
          </div>
                <?php }?>                   <td align="center" valign="middle">&nbsp;</td>
            </tr>
          i have implemented the while loop like this

          table
          inside table row
          created a div and repeted the <td> from the above code


          i had achieved the target that it repeats the table column but it reapers all the column in a single row which disturbs the whole page layout

          i want this that it should only show three records in a single row and then repeats the row also !!!


          please any of the person that can give guideline

          Comment

          Working...