Need result of query to be horizontal

Discussion in 'Programming' started by Jakobi, May 3, 2007.

  1. #1
    This piece of code pulls data from a database and the result of it is positioned vertically like so:

    1
    2
    3
    4
    5

    Now I need it to be like this:

    1 2 3 4 5

    I have tried some css and html things but have had no luck. How can I make it so the result is horizontal and not vertical?

    
    <?php
    require_once ('global.php');
    ?>
    
    <?
    if(isset($select)&&$select!=""){
    $select=$_GET['select'];
    }
    ?>
    
    <?
     $list=mysql_query("select * from files ORDER BY RAND() asc LIMIT 5");
     while($row_list=mysql_fetch_assoc($list)){
     ?>
     
    <center>
    <table>
    <tr>
    <td>
    <a href="URL/file.php?id=<? echo $row_list['file_id']; ?>"></a></td>
    <td>
    <img src="URL/thumbnails/<? echo $row_list['filename']; ?>.png" width="120" height="90"  /></td>
    <td width="115" class="table_content"><span class="style1"><? echo $row_list['title']; ?></span>
    </td> 
    </tr>
    </table>	
    </center>
    
    Code (markup):
     
    Jakobi, May 3, 2007 IP
  2. sarahk

    sarahk iTamer Staff

    Messages:
    28,838
    Likes Received:
    4,542
    Best Answers:
    123
    Trophy Points:
    665
    #2
    Just don't finish and start the rows

    omit the </tr><tr> from your code
     
    sarahk, May 3, 2007 IP
  3. Jakobi

    Jakobi Active Member

    Messages:
    291
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    #3
    Thanks for the reply, but it doesnt work. See it repeats this table 5 times so it looks like this in the view source:

    
    <center>
    <table>
    <tr>
    <td>
    <a href="URL/file.php?id=<? echo $row_list['file_id']; ?>"></a></td>
    <td>
    <img src="URL/thumbnails/<? echo $row_list['filename']; ?>.png" width="120" height="90"  /></td>
    <td width="115" class="table_content"><span class="style1"><? echo $row_list['title']; ?></span>
    </td> 
    </tr>
    </table>	
    </center>
    
    <center>
    <table>
    <tr>
    <td>
    <a href="URL/file.php?id=<? echo $row_list['file_id']; ?>"></a></td>
    <td>
    <img src="URL/thumbnails/<? echo $row_list['filename']; ?>.png" width="120" height="90"  /></td>
    <td width="115" class="table_content"><span class="style1"><? echo $row_list['title']; ?></span>
    </td> 
    </tr>
    </table>	
    </center>
    
    <center>
    <table>
    <tr>
    <td>
    <a href="URL/file.php?id=<? echo $row_list['file_id']; ?>"></a></td>
    <td>
    <img src="URL/thumbnails/<? echo $row_list['filename']; ?>.png" width="120" height="90"  /></td>
    <td width="115" class="table_content"><span class="style1"><? echo $row_list['title']; ?></span>
    </td> 
    </tr>
    </table>	
    </center>
    
    <center>
    <table>
    <tr>
    <td>
    <a href="URL/file.php?id=<? echo $row_list['file_id']; ?>"></a></td>
    <td>
    <img src="URL/thumbnails/<? echo $row_list['filename']; ?>.png" width="120" height="90"  /></td>
    <td width="115" class="table_content"><span class="style1"><? echo $row_list['title']; ?></span>
    </td> 
    </tr>
    </table>	
    </center>
    
    <center>
    <table>
    <tr>
    <td>
    <a href="URL/file.php?id=<? echo $row_list['file_id']; ?>"></a></td>
    <td>
    <img src="URL/thumbnails/<? echo $row_list['filename']; ?>.png" width="120" height="90"  /></td>
    <td width="115" class="table_content"><span class="style1"><? echo $row_list['title']; ?></span>
    </td> 
    </tr>
    </table>	
    </center>
    
    
    Code (markup):
    The code pulls 5 things from the database. The result of it puts them in a vertical column instead of a horizontal row.

    Any more ideas?

    Thanks.
     
    Jakobi, May 3, 2007 IP
  4. sarahk

    sarahk iTamer Staff

    Messages:
    28,838
    Likes Received:
    4,542
    Best Answers:
    123
    Trophy Points:
    665
    #4
    You need to read the code and experiment a little. Trust me, it's just a matter of not having so many rows.
     
    sarahk, May 3, 2007 IP
  5. Jakobi

    Jakobi Active Member

    Messages:
    291
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    #5
    Thanks for the response but I am stuck on this or lost.

    Here is what it looks like now:

    http://www.first-ward.com/videos/iframe2.php

    I need that to be horizontal and have tried a lot of things...

    I am not sure. Do you or anyone have some code suggestions?

    Thanks for any insight or help.
     
    Jakobi, May 3, 2007 IP
  6. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #6
    
    <?
    $assoc = array
    (
    	'name' => 'joe',
    	'age' => '21',
    	'legs' => 'yes',
    	'arms' => 'yes',
    	'head' => 'no'
    );
    
    echo "<table style='border: 1px solid black;'>\n<tr>\n";
    foreach( $assoc as $key => $value )
    {
    	echo "<td style='border: 1px solid black;'>$key : $value</td>\n";
    }
    echo "</tr>\n</table>\n";
    
    echo "<br /><br />";
    
    echo "<table style='border: 1px solid black;'>\n";
    foreach( $assoc as $key => $value )
    {
    	echo "<tr>\n<td style='border: 1px solid black;'>$key : $value</td>\n</tr>\n";
    }
    echo "</table>\n";
    
    PHP:
    Maybe that will explain what sarahk means
     
    krakjoe, May 4, 2007 IP
  7. Jakobi

    Jakobi Active Member

    Messages:
    291
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    #7
    Yea still confused. I tried to mold some of that code into my situation and had no luck with it. I am pretty new when it comes to this and need an easier explantion or reply.

    If anyone can help me....I beg of you.

    Thanks for all the replies so far and the attempts but I missing the connection or not getting what I am supposed to do.

    I figured I needed an array of some sort but not sure how to get to the finishline.

    Thanks.
     
    Jakobi, May 4, 2007 IP
  8. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #8
    paste the whole script, not just some of it, all of it.....
     
    krakjoe, May 6, 2007 IP
  9. sarahk

    sarahk iTamer Staff

    Messages:
    28,838
    Likes Received:
    4,542
    Best Answers:
    123
    Trophy Points:
    665
    #9
    Noooo! Attach the script to the post instead ;)
     
    sarahk, May 6, 2007 IP
  10. Jakobi

    Jakobi Active Member

    Messages:
    291
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    #10
    Ok. Thanks I attached it. I can use this for an example and will help me out in the future.
     

    Attached Files:

    Jakobi, May 6, 2007 IP
  11. Tibiacity

    Tibiacity Active Member

    Messages:
    190
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    73
    #11
    Not completely sure what you mean but try this:

    <?php
    require_once ('global.php');
    ?>
    
    <?
    if(isset($select)&&$select!=""){
    $select=$_GET['select'];
    }
    ?>
    
    <center>
    <table>
    <tr>
    
    
    <?
     $list=mysql_query("select * from files ORDER BY RAND() asc LIMIT 5");
     while($row_list=mysql_fetch_assoc($list)){
     ?>
     
    <td>
    <a href="URL/file.php?id=<? echo $row_list['file_id']; ?>"></a></td>
    <td>
    <img src="URL/thumbnails/<? echo $row_list['filename']; ?>.png" width="120" height="90"  /></td>
    <td width="115" class="table_content"><span class="style1"><? echo $row_list['title']; ?></span>
    </td> 
    
    <?
    }
    ?>
    
    </tr>
    </table>	
    </center>
    PHP:
     
    Tibiacity, May 8, 2007 IP
  12. plumsauce

    plumsauce Peon

    Messages:
    310
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #12
    just remove all occurences of [tr] and [/tr] from $list and then add one [tr] at the beginning and one [/tr] at the end.
     
    plumsauce, May 9, 2007 IP