Announcement

Collapse
No announcement yet.

Anyone good with PHP here? I'm a bit stuck! :(

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Anyone good with PHP here? I'm a bit stuck! :(

    Basically I'm making a database for my games collection, got data submitting, sorting by letter, and displaying all nice looking. Only problem is the formatting.



    Currently you can see it's one single column list. I want it to be a two column list, like this:

    A | B
    C | D
    E | F
    G |H

    So basically the code goes "right, Chu Chu Rocket & Cosmic Smash in row one, then Crazy Taxi and Crazy Taxi 2 in the next row, etc etc...

    Here is my code:

    Code:
    <table width="550" border="0" cellpadding="0" cellspacing="0">
      <tr>
    	<td height="31" background="images/content_top.gif"><table width="530" border="0" align="right" cellpadding="0" cellspacing="0">
    	  <tr>
    		<td class="style1">Dreamcast Software Collection </td>
    	  </tr>
    	</table></td>
      </tr>
      <tr>
    	<td bgcolor="#E4E4E4"><table width="530" border="0" align="center" cellpadding="0" cellspacing="0">
    	  <tr>
    		<td><div align="center">Please select a letter: <br>
    		 [0] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] <br>
    		   [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] [Y] [Z] </div></td>
    	  </tr>
    	</table></td>
      </tr>
      <tr>
    	<td><img src="images/content_base.gif" width="550" height="15" /></td>
      </tr>
    </table>
    <br><?
    $username="*********";
    $password="*********";
    $database="MySega";
    
    mysql_connect(localhost,$username,$password);
    @mysql_select_db($database) or die( "Unable to select database");
    $query="SELECT * FROM dreamcast WHERE title LIKE 'C%'";
    $result=mysql_query($query);
    
    $num=mysql_numrows($result);
    
    mysql_close();
    
    $i=0;
    while ($i < $num) {
    
    $title=mysql_result($result,$i,"title");
    $developer=mysql_result($result,$i,"developer");
    $year=mysql_result($result,$i,"year");
    $region=mysql_result($result,$i,"region");
    $condition=mysql_result($result,$i,"condition");
    $rating=mysql_result($result,$i,"rating");
    $boxart=mysql_result($result,$i,"boxart");
    $notes=mysql_result($result,$i,"notes");
    
    echo "<table width='270' border='0' cellspacing='0' cellpadding='0'>
    					<tr>
    					  <td width='270' height='16' align='center' background='http://www.mysega.co.uk/images/db_top_title.gif'>$title</td>
    					</tr>
    					<tr>
    					  <td width='270' height='119' background='http://www.mysega.co.uk/images/db_back_info.gif'><table width='254' height='102' border='0' align='center' cellpadding='0' cellspacing='0'>
    						  <tr>
    							<td width='102' height='102' align='center'><table border='0' cellpadding='0' cellspacing='1' bgcolor='#000000'>
    							  <tr>
    								<td><img src='http://www.mysega.co.uk$boxart' /></td>
    							  </tr>
    							</table></td>
    							<td width='7' align='right'>&nbsp;</td>
    							<td width='145' valign='top'><table width='145' height='102' border='0' cellpadding='0' cellspacing='0'>
    								<tr>
    								  <td align='left'><img src='http://www.mysega.co.uk/images/db_regionbt.gif' width='68' height='7' /></td>
    								</tr>
    								<tr>
    								  <td><table width='145' border='0' cellspacing='0' cellpadding='0'>
    									  <tr>
    										<td width='50'><img src='http://www.mysega.co.uk/images/db_$region.gif' width='26' height='15' /></td>
    										<td width='95'>$developer</td>
    									  </tr>
    								  </table></td>
    								</tr>
    								<tr>
    								  <td><img src='http://www.mysega.co.uk/images/db_yearcondition.gif' width='139' height='11' /></td>
    								</tr>
    								<tr>
    								  <td height='12'><table width='145' height='12' border='0' cellpadding='0' cellspacing='0'>
    									  <tr>
    										<td width='50' class='SmallFontDark'>$year</td>
    										<td width='95'><img src='http://www.mysega.co.uk/images/db_$condition.gif' width='55' height='10' /></td>
    									  </tr>
    								  </table></td>
    								</tr>
    								<tr>
    								  <td><img src='http://www.mysega.co.uk/images/db_notes.gif' width='139' height='11' /></td>
    								</tr>
    								<tr>
    								  <td height='40' valign='top' class='SmallFontDark'>$notes</td>
    								</tr>
    							</table></td>
    						  </tr>
    					  </table></td>
    					</tr>
    					<tr>
    					  <td width='270'><img src='http://www.mysega.co.uk/images/db_base_$rating.gif' width='270' height='17' /></td>
    					</tr>
    				  </table><br>";
    
    $i++;
    }
    
    ?>
    How could I rewrite it so the PHP outputs it correctly? I've tried making tables to contian it, etc, but it won't work.

    Mark

    #2
    Try using DIVs rather than tables like this:

    Time Extension brings you the latest news and features from the world of retro gaming. Giving retro and classic games more time to shine and so much more.


    The images wrap themselves when they exceed their boundaries

    You could always go the cheap way and use flags in your code so you know when to write <tr><td>.....</td></tr> - that would mean you could encaptulate your returned rows in a table with 2 columns per row

    it's not a perfect solution, but better than sticking a beef bayonet up your bum!

    Comment


      #3
      Problem is, it's the way I use tables, each game isn't a image, it's some images, background images, and text data all put in place by a table.

      I tried the <tr><td>....</td></tr> container, it'll just still do one per row.

      Maybe I have to rewrite the php and the template? Dunno, I'm very new to this.

      Comment


        #4
        Wouldn't you need a counter (from 0 to 1) so it knew when to drop down a row? Not sure how you put that in the code without it messing up the html though.

        Comment


          #5
          Originally posted by SegaMark
          Problem is, it's the way I use tables, each game isn't a image, it's some images, background images, and text data all put in place by a table.

          I tried the <tr><td>....</td></tr> container, it'll just still do one per row.

          Maybe I have to rewrite the php and the template? Dunno, I'm very new to this.
          Just put your layout table in the DIV, let DIVs do the hard work of positioning columns, if you can crack this on a static mockup of your page it will be easy to get it working dynamically

          counters to write tables on the fly just make code look messy, best to be avoided imho

          Comment


            #6
            Its worth learning CSS, and using DIV's. Tables are pretty old hat - you should really try and avoid them whenever possible!


            However, if you are intent on tables, i'd go with charlesr, and use a counter - but my coding philosophy is - as long as it works, who cares how it looks?

            Comment


              #7
              I'm so crap at this I can't even think how I can manage it with DIVs... My strength lies in design, not code as you can maybe tell.. Haha...

              Does anyone minding me to MSN if they can help me? My ID is [email protected]

              Comment


                #8
                Maybe its already sorted, but - who cares

                Here's some CSS;


                #container {
                border: 1px solid;
                float: left;
                width: 200px;
                _width: 202px;
                }

                #entry {
                margin: 0;
                width: 100px;
                float: left;
                background-color: #ff00ff;
                }



                Basically, open the container, and throw the entries inside it;

                <div id="container">

                <div id="entry">
                game
                </div>

                <div id="entry">
                game
                </div>

                </div>


                ----------

                Basically, the container div is 200px wide, and the entry divs are 100px wide, thus allowing 2 per row - obviously these will need to be adjusted to your design.

                Thats how i'd do it anyway, though there may well be a better way!
                Last edited by supersmithy; 25-04-2006, 17:13. Reason: IE = not cool

                Comment


                  #9
                  Thanks AllYourBase!

                  Comment

                  Working...
                  X