Jump to content


Photo

display images in two columns


  • Please log in to reply
10 replies to this topic

#1 cheesecake86

cheesecake86

    Newbie

  • New Members
  • Pip
  • 1 posts

Posted 10 February 2013 - 03:38 PM

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>&nbsp;</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&amp;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&amp;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>

#2 Jessica

Jessica

    This is not my name.

  • Gurus
  • 8,982 posts
  • LocationDallas, TX
  • Age:26

Posted 10 February 2013 - 03:49 PM

You're mixing tables and div, you have the logic but you're printing new table rows, and you're not using table cells. Clean up your HTML.
My goal in replying to posts is to help you become a better programmer, including learning how to debug your own code and research problems. For that reason, rather than posting the solution, I reply with tips and hints on how to find the solution yourself. See below for useful links when you get stuck.

How to Get Good Help: How to Ask Questions | Don't be a help vampire
Debugging Your Code: Debugging your SQL | What does a php function do? | What does a term mean? | Don't see any errors?
Things You Should Do: Normalize Your Data | use print_r() or var_dump()
Lulz: "Functions should not have side effects." - trq

Please take a look at my new PHP/Web Dev blog: The Web Mason - Thanks!!

#3 Tychonaut

Tychonaut

    Newbie

  • Members
  • Pip
  • 8 posts

Posted 10 February 2013 - 09:34 PM

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>

#4 Jessica

Jessica

    This is not my name.

  • Gurus
  • 8,982 posts
  • LocationDallas, TX
  • Age:26

Posted 10 February 2013 - 11:24 PM

PHP variable names cannot contain -, that will produce a lot of errors.
My goal in replying to posts is to help you become a better programmer, including learning how to debug your own code and research problems. For that reason, rather than posting the solution, I reply with tips and hints on how to find the solution yourself. See below for useful links when you get stuck.

How to Get Good Help: How to Ask Questions | Don't be a help vampire
Debugging Your Code: Debugging your SQL | What does a php function do? | What does a term mean? | Don't see any errors?
Things You Should Do: Normalize Your Data | use print_r() or var_dump()
Lulz: "Functions should not have side effects." - trq

Please take a look at my new PHP/Web Dev blog: The Web Mason - Thanks!!

#5 Tychonaut

Tychonaut

    Newbie

  • Members
  • Pip
  • 8 posts

Posted 11 February 2013 - 07:11 AM

You are of course right. Thats why I said the silly var names are for "educational purposes only" .. I just wanted them to be self explanatory, and I find the font spacing here reeeeeeaaallllly tiny, so I spaced the names out a bit. I_should_have_used_underscores.

#6 Jessica

Jessica

    This is not my name.

  • Gurus
  • 8,982 posts
  • LocationDallas, TX
  • Age:26

Posted 11 February 2013 - 09:40 AM

The problem is it's not educational to use something that flat out will not work. Yes, underscores will work. 
My goal in replying to posts is to help you become a better programmer, including learning how to debug your own code and research problems. For that reason, rather than posting the solution, I reply with tips and hints on how to find the solution yourself. See below for useful links when you get stuck.

How to Get Good Help: How to Ask Questions | Don't be a help vampire
Debugging Your Code: Debugging your SQL | What does a php function do? | What does a term mean? | Don't see any errors?
Things You Should Do: Normalize Your Data | use print_r() or var_dump()
Lulz: "Functions should not have side effects." - trq

Please take a look at my new PHP/Web Dev blog: The Web Mason - Thanks!!

#7 Tychonaut

Tychonaut

    Newbie

  • Members
  • Pip
  • 8 posts

Posted 11 February 2013 - 11:56 AM

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". :)

#8 Jessica

Jessica

    This is not my name.

  • Gurus
  • 8,982 posts
  • LocationDallas, TX
  • Age:26

Posted 11 February 2013 - 12:09 PM

We have code tags for that. You might want to review our rules and guidelines.

OP, I'm marking this solved unless you come back and have a problem still.
My goal in replying to posts is to help you become a better programmer, including learning how to debug your own code and research problems. For that reason, rather than posting the solution, I reply with tips and hints on how to find the solution yourself. See below for useful links when you get stuck.

How to Get Good Help: How to Ask Questions | Don't be a help vampire
Debugging Your Code: Debugging your SQL | What does a php function do? | What does a term mean? | Don't see any errors?
Things You Should Do: Normalize Your Data | use print_r() or var_dump()
Lulz: "Functions should not have side effects." - trq

Please take a look at my new PHP/Web Dev blog: The Web Mason - Thanks!!

#9 sid0972

sid0972

    Advanced Member

  • Members
  • PipPipPip
  • 50 posts

Posted 11 February 2013 - 12:58 PM

i doubt OP's coming back now

#10 Tychonaut

Tychonaut

    Newbie

  • Members
  • Pip
  • 8 posts

Posted 11 February 2013 - 03:30 PM

Reeeeeeeaaaaallly not so easy to find the "Forum Rules" link way down there.

But I got it.

Edited by Tychonaut, 11 February 2013 - 03:31 PM.


#11 Jessica

Jessica

    This is not my name.

  • Gurus
  • 8,982 posts
  • LocationDallas, TX
  • Age:26

Posted 11 February 2013 - 03:44 PM

At least it's there now ;) I just asked them to add it last week, it was missing for a while!
My goal in replying to posts is to help you become a better programmer, including learning how to debug your own code and research problems. For that reason, rather than posting the solution, I reply with tips and hints on how to find the solution yourself. See below for useful links when you get stuck.

How to Get Good Help: How to Ask Questions | Don't be a help vampire
Debugging Your Code: Debugging your SQL | What does a php function do? | What does a term mean? | Don't see any errors?
Things You Should Do: Normalize Your Data | use print_r() or var_dump()
Lulz: "Functions should not have side effects." - trq

Please take a look at my new PHP/Web Dev blog: The Web Mason - Thanks!!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com