Go Back   CodingForums.com > :: Server side development > MySQL

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-24-2012, 02:10 PM   PM User | #1
jawittdesigns
New Coder

 
Join Date: Sep 2012
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
jawittdesigns is an unknown quantity at this point
Need Help with database Queries in HTML tables

Hi,

I having problems displaying queries from a mySQL database. I want to display images and descriptions in a html table four columns wide.

so far I cam up with this.

PHP Code:
while ($row mysql_fetch_array$result )){
$entry_name $row['entry_name'];
$entry_submition $row['entry_filename'];
$entry_pic '<div class="display-img"> <img src="../photos/'.$row['entry_filename'].'"></div>';
$count=4;
echo 
"<table>";
  
   echo 
'<tr>';
   for (
$counter=0$counter <$count$counter++){
        echo 
'<td>'.$entry_name.'<br>'.$entry_pic.'<td>';
   } 
  echo 
'</tr>';
echo 
"</table>";

This displays the table correctly, but it shows each item four times in each row.

What I need it to show each item once.

If any one can help. That would be great
jawittdesigns is offline   Reply With Quote
Old 09-24-2012, 09:11 PM   PM User | #2
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,165
Thanks: 59
Thanked 3,992 Times in 3,961 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
PHP Code:
$count 0;
echo 
"<table>\n";
while (
$row mysql_fetch_array$result ))
{
    if ( 
$count == ) { echo "<tr>\n"; }
    
$entry_name $row['entry_name'];
    
$entry_submition $row['entry_filename'];
    
$entry_pic '<div class="display-img"> <img src="../photos/'.$row['entry_filename'].'"></div>';

    echo 
'<td>'.$entry_name.'<br>'.$entry_pic.'<td>\n';

    ++
$count;
    if ( 
$count == 
    {
        echo 
"</tr>\n";
        
$count 0;
    }
}
echo 
"</table>\n"
Untested. I don't use PHP. But I use this technique with other languages and it works.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is online now   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:39 PM.


Advertisement
Log in to turn off these ads.