I need a break!

Discussion in 'PHP' started by Drew007, Jan 9, 2007.

  1. #1
    Hey guys. I am not a programmer and would appreciate some help. The code below shows 10 video thumbnails in a row. I just need to add a break so it create 2 rows of 5 instead of 1 row of 10. Thanks in advance.

    <?
    				$result=mysql_query("select * from videos order by id DESC limit 10");
    				while($data=mysql_fetch_array($result)) {
    					$then=strtotime($data[date]);
    					$now = time();
    					$timediff = $then - $now;
    					$dayspassed = intval(abs(((($timediff/60)/60)/24)));
    			
    					if ($dayspassed == 0) { $dayspassed="added today"; }
    					elseif ($dayspassed == 1) { $dayspassed="added yesterday"; }
    					else { $dayspassed="added $dayspassed days ago"; }
    					
    					if($data['th_default']) {
    						if($data[scatid]) {
    							$img_src = "/thumbs/default/s$data[scatid].jpg";
    						} else {
    							$img_src = "/thumbs/default/$data[catid].jpg";
    						}
    					}
    					else $img_src = "/thumbs/$data[id].jpg";
    					
    				?>
            <td width="120" align="center"><a href="/view.php?a=v&amp;t=<?=$data[id]?>"> <img alt="<?=$data[title]?> <?=$dayspassed?>" width="100" height="82" src="<?=$img_src?>" border="0" class="bgbox" /></a><br />
                <? if (strlen($data[title]) > 15) { echo substr($data[title],0,15)."..."; } else { echo $data[title]; } ?>
            </td>
            <?
    				}
    				?>
          </tr>
        </table>
    PHP:
     
    Drew007, Jan 9, 2007 IP
  2. matthewrobertbell

    matthewrobertbell Peon

    Messages:
    781
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Increment a variable by one every time eg $x = $x++; then if ($x == 5) { echo "<br> or <p>";} to make a new line?
     
    matthewrobertbell, Jan 9, 2007 IP
  3. Drew007

    Drew007 Peon

    Messages:
    310
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I have no idea what you just said. Should I paste this code somewhere?
     
    Drew007, Jan 9, 2007 IP
  4. rays

    rays Active Member

    Messages:
    563
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    58
    #4
    replace your code with this and test it, let me know if it works fine


     
    rays, Jan 9, 2007 IP
  5. Drew007

    Drew007 Peon

    Messages:
    310
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thanks thus far. Here is the error I receive:

    The entire line 64 is just one character }. I tried removing that and I had no luck.
     
    Drew007, Jan 10, 2007 IP
  6. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #6
    
    <?
    $result=mysql_query("select * from videos order by id DESC limit 10");
    $i = 0;
    while($data=mysql_fetch_array($result))
    {
    $then=strtotime($data[date]);
    $now = time();
    $timediff = $then - $now;
    $dayspassed = intval(abs(((($timediff/60)/60)/24)));
    
    if ($dayspassed == 0) { $dayspassed="added today"; }
    elseif ($dayspassed == 1) { $dayspassed="added yesterday"; }
    else { $dayspassed="added $dayspassed days ago"; }
    
    if($data['th_default']) {
    if($data[scatid]) {
    $img_src = "/thumbs/default/s$data[scatid].jpg";
    } else {
    $img_src = "/thumbs/default/$data[catid].jpg";
    }
    }
    else $img_src = "/thumbs/$data[id].jpg";
    if ($i == 5) {
    echo "</tr></tr>";
    }
    ?>
    <td width="120" align="center"><a href="/view.php?a=v&amp;t=<?=$data[id]?>"> <img alt="<?=$data[title]?> <?=$dayspassed?>" width="100" height="82" src="<?=$img_src?>" border="0" class="bgbox" /></a><br />
    <? if (strlen($data[title]) > 15) { echo substr($data[title],0,15)."..."; } else { echo $data[title]; } ?>
    </td>
    <?
    $i++;
    }
    ?>
    </tr>
    </table>
    
    PHP:
    I haven't looked at the code properly, but the error is

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

    the line above the one in the error, it almost always is with syntax errors, it means the line before isn't finished yet and it's expecting ; before the closing }
     
    krakjoe, Jan 10, 2007 IP
  7. Drew007

    Drew007 Peon

    Messages:
    310
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #7
    That works! Thank you so much!
     
    Drew007, Jan 10, 2007 IP
  8. rays

    rays Active Member

    Messages:
    563
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    58
    #8
    I am sorry i just forgot to put ;

    Its been a while i am working on ruby on rails and was missing with some syntax issues.


    Any ways nice to see your problem is resolved
     
    rays, Jan 10, 2007 IP