How to display row contents in 2 different columns

Discussion in 'PHP' started by vic_msn, Nov 5, 2006.

  1. #1
    I created a database with a single table. I created 3 more columns inside that table. then i queried and printed it using fetch_array. i worked.
    but it displays like
    but i want it to be like
    this is the code i use now

     
    vic_msn, Nov 5, 2006 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    Untested, but give this a try.
    
    <table border="1">
    <tr>
    <?php
    
    $int = 0;
    
    while($row = mysql_fetch_array($sql))
    {
    	echo "<td><a href=".$row['name'].">".$row['name']."</a></td>\n";
    	echo ++$int % 2 == 0 ? '</tr><tr>' : '';
    }
    
    ?>
    </tr>
    </table>
    
    Code (markup):
     
    nico_swd, Nov 5, 2006 IP
  3. vic_msn

    vic_msn Well-Known Member

    Messages:
    2,233
    Likes Received:
    125
    Best Answers:
    0
    Trophy Points:
    155
    #3
    i will try it
    i will make it more clear i want the contents to be displayed like in a link directory.
     
    vic_msn, Nov 5, 2006 IP
  4. vic_msn

    vic_msn Well-Known Member

    Messages:
    2,233
    Likes Received:
    125
    Best Answers:
    0
    Trophy Points:
    155
    #4
    no it is not working it prints them like this one, two, three ...
     
    vic_msn, Nov 5, 2006 IP
  5. vic_msn

    vic_msn Well-Known Member

    Messages:
    2,233
    Likes Received:
    125
    Best Answers:
    0
    Trophy Points:
    155
    #5
    it worked without the table tags thanks for the startup
    :)
     
    vic_msn, Nov 5, 2006 IP
  6. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #6
    EDIT: Too late.

    Glad it worked...



    I've just tested it, and it works for me.

    [​IMG]
     
    nico_swd, Nov 5, 2006 IP
  7. vic_msn

    vic_msn Well-Known Member

    Messages:
    2,233
    Likes Received:
    125
    Best Answers:
    0
    Trophy Points:
    155
    #7
    i want few data to be inserted into the the table using a submit form.
    how can that be done.
     
    vic_msn, Nov 5, 2006 IP
  8. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #8
    I can't say without seeing your database structure and knowing which data...

    http:// dev.mysql.com/doc/refman/5.0/en/insert.html
     
    nico_swd, Nov 5, 2006 IP
  9. vic_msn

    vic_msn Well-Known Member

    Messages:
    2,233
    Likes Received:
    125
    Best Answers:
    0
    Trophy Points:
    155
    #9
    thanks the database is in my computer. I will read some tutorials in the internet.
     
    vic_msn, Nov 5, 2006 IP
  10. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #10
    This might help more.

    http:// phpeasystep.com/mysql/5.html
    http:// infinite-fire.net/tutorials/php/insert-data-into-a-mysql-database
     
    nico_swd, Nov 5, 2006 IP
  11. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #11
    More dynamic:

    
    <?php
    //Coulmn Display Limit
    $DIS_LIM = 3;
    
    echo '<table width="100%"  border="0" cellspacing="0" cellpadding="2">';
    
    $x=1;
    while($row = mysql_fetch_array($sql)){
    	if($x == 1){ echo'<tr>';}
    	echo "<td><a href=".$row['name'].">".$row['name']."</a></td>\n";
    	if($x == $DIS_LIM){ echo '</tr>';$x=0;}
    	$x++;
    }
    if($x != 1){ 
    	for($z=0;$z<=$DIS_LIM-$x;$z++){ echo '<td>&nbsp;</td>';}
    	echo '</tr>';
    }
    
    echo '</table>';
    ?>
    
    PHP:
    Peace,
     
    Barti1987, Nov 5, 2006 IP