Jump to content

[SOLVED] Problems trying to generate HTML data for a 2-column layout


Englyst

Recommended Posts

Hi folks.

 

My first post here ever :) I'm not the best at coding but I try at the best of my ability. So please beware any obvious blunders coming!

 

My problem is:

 

I've got a bunch of articles from a database that needs to get distributed into a 2 column layout. But it seems my code only processes the first record and then stops.

 

The first part:

Generate HTML code for a 2-column layout based on articles from a database. In this case there are 2 articles but only one shows up. Seems like the while doesn't loop. It only processes the first record

 

bLeft is for switching from putting an article in the left or right HTML variable.

 

while ($row_rs_artikler)
{
if($bLeft == 1)
{
	$LeftHTML .= '<tr><td>';
	if (($row_rs_artikler['filename']) != "")
		{
		$LeftHTML .= '<img src="images/articleimages/'.$row_rs_artikler['filename'].'" alt="'.$row_rs_artikler['imagedescription'].'" class="image" /><br /><br />';
		}
	$LeftHTML .= $row_rs_artikler['description'].'<br /><br ></td></tr>';
	$bLeft = 0;
} else {
	$RightHTML .= '<tr><td>';
	if (($row_rs_artikler['filename']) != "")
		{
		$RightHTML .= '<img src="images/articleimages/'.$row_rs_artikler['filename'].'" alt="'.$row_rs_artikler['imagedescription'].'" class="image" /><br /><br />';
		}
	$RightHTML .= $row_rs_artikler['description'].'<br /><br /></td></tr>';
	$bLeft = 1;
	}
} ?>

 

Heres the code for outputting the generated HTML nested in a master table with 2 columns:

 

<table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
    <td class="article">
     	<table width="100%" border="0" cellpadding="0" cellspacing="0">
        	<tr>
        	<td>
        		<?php echo $LeftHTML; ?>
    		</td>
    		</tr>
        </table>
    </td>
    <td class="article">
      	<table width="100%" border="0" cellpadding="0" cellspacing="0">
    		<tr>
    		<td>
            	<?php echo $RightHTML; ?>
            </td>
            </tr>
        </table>
    </td>
    </tr>
</table>

 

I have been staring at this for too long and there's probably a MUCH better way at doing this. If anyone can help me out I'd be a happy camper. I haven't been using arrays or such very much so in some areas I'm drawing a blank :P

 

You can see a working version of this code here: http://carpenta.englyst.eu/konceptet.php

 

Thanks!

 

/ Michael Englyst

I would suggest something like:

$query = mysql_query("SELECT * FROM table");
while ($row_rs_artikler = mysql_fetch_array($query))
{
if($bLeft == 1)
{
	$LeftHTML .= '<tr><td>';
	if (($row_rs_artikler['filename']) != "")
		{
		$LeftHTML .= '<img src="images/articleimages/'.$row_rs_artikler['filename'].'" alt="'.$row_rs_artikler['imagedescription'].'" class="image" /><br /><br />';
		}
	$LeftHTML .= $row_rs_artikler['description'].'<br /><br ></td></tr>';
	$bLeft = 0;
} else {
	$RightHTML .= '<tr><td>';
	if (($row_rs_artikler['filename']) != "")
		{
		$RightHTML .= '<img src="images/articleimages/'.$row_rs_artikler['filename'].'" alt="'.$row_rs_artikler['imagedescription'].'" class="image" /><br /><br />';
		}
	$RightHTML .= $row_rs_artikler['description'].'<br /><br /></td></tr>';
	$bLeft = 1;
	}
} ?>

 

I don't know exactly how you have done the rest of your code because this is clearly not all of it.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.