1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Help with MySQL query and PHP

Discussion in 'PHP' started by CLMMafia, Feb 28, 2012.

  1. #1
    Hello,

    I want to echo a mysql query and place a result in a <td> and 2 <td>'s per <tr>.

    All I've been able to do is this:
    
    $sql = mysql_query("SELECT * FROM files");
    $num = ceil(@mysql_num_rows($sql) / 2);
    $left = mysql_query("SELECT * FROM files LIMIT 0, {$num}");
    $right = mysql_query("SELECT * FROM files LIMIT {$num}, {$num}");
    
    echo '<div class="row">
    <div class="span11">
    <h2>File\'s</h2>
    <table>
    <tbody>
    <tr>
    <td>
    ';
    while($row = mysql_fetch_array($left)){
    echo '<div class="search_result"><a style="color: #1111cc;" href="/files/'.$row['rand'].'/"><span>'.$row['name'].'</span></a><br>'.$row['description'].'</div>
    ';
    }
    echo '
    </td>
    <td>
    ';
    while($row = mysql_fetch_array($right)){
    echo '<div class="search_result"><a style="color: #1111cc;" href="/files/'.$row['rand'].'/"><span>'.$row['name'].'</span></a><br>'.$row['description'].'</div>
    ';
    }
    echo '
    </td>
    </tr>
    </tbody>
    </table>
    </div>
    <div class="span3">
    '.span3().'
    </div>
    </div>';
    
    PHP:
    Thanks,
    CLM
     
    CLMMafia, Feb 28, 2012 IP
  2. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #2
    
    for ($x = 0; $x < $items; $x++)
    {
        $l = mysql_fetch_assoc($query);
    
        if ($x % 2) { echo '</tr><tr>'; }
        echo '<td>' . $l['field'] . '</td>';
    }
    
    
    Code (markup):
     
    EricBruggema, Feb 29, 2012 IP