Jump to content

display images in two columns


cheesecake86

Recommended Posts

Can anybody help me get this code to a two column page

now its

1

2

3

4

instead of

12

34

 

 

<div id="welcome">

<H3> </H3>

</div>

<div id="homeCols">

<div id="catCol">

<div>

<b class="orageBG">

<b class="orageBG5"></b>

<b class="orageBG4"></b>

<b class="orageBG3"></b>

<b class="orageBG2"></b>

<b class="orageBG1"></b></b>

<div id="catCol2">

<h3>Categories</h3>

<div> <b class="orageBG"> <b class="orageBG1"></b> <b class="orageBG2"></b> <b class="orageBG3"></b> <b class="orageBG4"></b> <b class="orageBG5"></b></b>

<div class="orageBGfg">

<?

$sql = "SELECT DISTINCT category FROM forsale_content ORDER BY category ASC";

$result = mysql_query($sql);

while ($record = mysql_fetch_object($result)) {

$query = "SELECT COUNT(*) FROM forsale_content WHERE category='$record->category' AND status='online'";

$numentries = mysql_query($query) or die("Select Failed!");

$numentry = mysql_fetch_array($numentries);

?>

<div id="cat"><a href="?q=cat-view&category=<? echo"$record->category";?>"><? echo "$record->category";?></a> (<? echo $numentry[0]; ?>)</div>

<?

}

?>

</div>

<b class="orageBG"> <b class="orageBG5"></b> <b class="orageBG4"></b> <b class="orageBG3"></b> <b class="orageBG2"></b> <b class="orageBG1"></b></b> </div>

</div>

</div>

 

 

</div>

 

<div id="newestCol">

 

<h3>Newest Listings</h3>

<?

$sql = "SELECT * FROM forsale_content WHERE status='online' ORDER BY id DESC LIMIT 15";

$result = mysql_query($sql);

echo "<table><tr>";

$count = 1;

 

while ($record = mysql_fetch_object($result)) {

?>

<div id="newestBlock">

<div id="newTitle">

<a href="?q=detail&id=<? echo "$record->id";?>">

<img src="<? echo "$record->photo";?>" width="300" />

<?php if($record->price != "") { ?>

<?php } ?>

<?

if ($count++ % 2 == 0) {

echo "</tr><tr>";

}

}

echo "</tr></table>";

?>

 

 

 

</div>

</div>

<div id="newDate"></div>

</div>

</div>

 

</div>

Link to comment
Share on other sites

Ugh. Getting a headache looking at the code. I'm not sure exactly what you are trying to do, but you could also use this idea maybe? Basically build your 2 columns *beforehand* ... and then deposit each item one by one, switching back and forth with your modulo operator.

 

(Silly var names for educational purposes only)

 

<?php

 

// set up your empty column HTML string holders

$col-A-html-string = "";

$col-B-html-string = "";

 

while ($record = mysql_fetch_object($result)) {

// build each item (we are staying inside PHP here)

$item-html-string = "";

 

$item-html-string .= "<h2>" . $record->title . "</h2>";

$item-html-string .= "<p>" . $record->info . "</p>";

..etc...

 

// flip flop and deposit each item into one or other of the holders

if ($count++ % 2 == 0) {

$col-B-html-string .= $item-html-string;

} else{

$col-A-html-string .= $item-html-string;

}

 

}

?>

 

// finally drop the column string vars into the appropriate locations

<div class="col-A"><?php echo col-A-html-string ?></div>

<div class="col-B"><?php echo col-B-html-string ?></div>

Link to comment
Share on other sites

I wasn't sure that all posted code had to be useable *as is*. I will watch for that in the future. I guess my uncommented ".. etc .." was a baddie as well? Sorry.. I'm new here.

 

Of course, it wouldn't be hard to get monospace code formatting going on the posts, right? On a site for code t'would be a nice "extra". :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.