cheesecake86 Posted February 10, 2013 Share Posted February 10, 2013 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> Quote Link to comment https://forums.phpfreaks.com/topic/274305-display-images-in-two-columns/ Share on other sites More sharing options...
Jessica Posted February 10, 2013 Share Posted February 10, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/274305-display-images-in-two-columns/#findComment-1411576 Share on other sites More sharing options...
Tychonaut Posted February 11, 2013 Share Posted February 11, 2013 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> Quote Link to comment https://forums.phpfreaks.com/topic/274305-display-images-in-two-columns/#findComment-1411657 Share on other sites More sharing options...
Jessica Posted February 11, 2013 Share Posted February 11, 2013 PHP variable names cannot contain -, that will produce a lot of errors. Quote Link to comment https://forums.phpfreaks.com/topic/274305-display-images-in-two-columns/#findComment-1411677 Share on other sites More sharing options...
Tychonaut Posted February 11, 2013 Share Posted February 11, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/274305-display-images-in-two-columns/#findComment-1411709 Share on other sites More sharing options...
Jessica Posted February 11, 2013 Share Posted February 11, 2013 The problem is it's not educational to use something that flat out will not work. Yes, underscores will work. Quote Link to comment https://forums.phpfreaks.com/topic/274305-display-images-in-two-columns/#findComment-1411730 Share on other sites More sharing options...
Tychonaut Posted February 11, 2013 Share Posted February 11, 2013 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". Quote Link to comment https://forums.phpfreaks.com/topic/274305-display-images-in-two-columns/#findComment-1411773 Share on other sites More sharing options...
Jessica Posted February 11, 2013 Share Posted February 11, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/274305-display-images-in-two-columns/#findComment-1411777 Share on other sites More sharing options...
sid0972 Posted February 11, 2013 Share Posted February 11, 2013 i doubt OP's coming back now Quote Link to comment https://forums.phpfreaks.com/topic/274305-display-images-in-two-columns/#findComment-1411790 Share on other sites More sharing options...
Tychonaut Posted February 11, 2013 Share Posted February 11, 2013 (edited) Reeeeeeeaaaaallly not so easy to find the "Forum Rules" link way down there. But I got it. Edited February 11, 2013 by Tychonaut Quote Link to comment https://forums.phpfreaks.com/topic/274305-display-images-in-two-columns/#findComment-1411828 Share on other sites More sharing options...
Jessica Posted February 11, 2013 Share Posted February 11, 2013 At least it's there now I just asked them to add it last week, it was missing for a while! Quote Link to comment https://forums.phpfreaks.com/topic/274305-display-images-in-two-columns/#findComment-1411832 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.