-3

i have this code:

     <?
        $sql = mysql_query("SELECT * FROM VIDEOS ORDER BY ID DESC");
        while($rs = mysql_fetch_assoc($sql)){
     ?>
            <img src="<?echo $rs['V_LOGO'];?>" width="150px" height="150px" />
            <p><a href="view.php?v=<?echo $rs['ID'];?>"><?echo $rs['V_TITLE'];?></a></p><br />
            <p><?echo $rs['V_DESC'];?></p>
    <?}?>

and I want to show videos next to each other, and every five videos in a new line, How I can do that??

user1404047
  • 61
  • 1
  • 5
  • i have not tried any thing !! – user1404047 Aug 28 '12 at 14:52
  • 3
    It may not help answer your question, but you should stop using `mysql_*` functions. They're being deprecated. Instead use [PDO](http://php.net/manual/en/book.pdo.php) (supported as of PHP 5.1) or [mysqli](http://php.net/manual/en/book.mysqli.php) (supported as of PHP 4.1). If you're not sure which one to use, [read this article](http://www.deprecatedphp.com/mysql_/). – Matt Aug 28 '12 at 14:53
  • 1
    @user1404047 Then how did you get this code, if you didn't try anything at all? ) I'm asking, because I still don't understand what's 'show **videos** next to each other' means, when you apparently deal with images here. – raina77ow Aug 28 '12 at 14:55
  • 1
    Hello and welcome to StackOverflow. While you may be having trouble with your program, we highly encourage (and insist) that you give it your best shot before asking the community for help. When it's clear that you're running into issues with code that you've tried, we're glad to help! If you don't put any effort into designing your own solutions, we tend to down-vote your question and close it. You *must* at least attempt a solution first. *Never* ask someone else to write code in lieu of an honest effort. – Matt Aug 28 '12 at 14:56
  • @Matt --> thank's for information – user1404047 Aug 28 '12 at 14:56

4 Answers4

0

first.. if content of your database is not sanitized - use htmlspecialchars to avoid injection of unwanted javascript/html code.

you can loop like this:

<?
$i=0;
while(..){
if($i%5==0)echo "<p>";

echo "<a href=\"....>";

if($i%5==4)echo "</p>";
$i++;
}

if($i%5!=4)echo "</p>";
Community
  • 1
  • 1
pQd
  • 116
  • 4
  • 20
0

I've had to do this a lot.

Try Something like this

<?
  $sql = mysql_query("SELECT * FROM VIDEOS ORDER BY ID DESC");
  $count = 0;
  while($rs = mysql_fetch_assoc($sql)){
?>
    <div class="image-wrapper row-<?echo (int)$count/5;?> col-<?echo (int)$count%5;?>">
      <img src="<?echo $rs['V_LOGO'];?>" width="150px" height="150px" />
      <p><a href="view.php?v=<?echo $rs['ID'];?>"><?echo $rs['V_TITLE'];?></a></p><br />
      <p><?echo $rs['V_DESC'];?></p>
    </div>
<?
    $count++;
  }
?>

then use the css code:

.image-wrapper {
  float: left;
  width: 160px;
  height: 150px;
}

.image-wrapper .col-0 {
  clear: left;
}
danielson317
  • 3,121
  • 3
  • 28
  • 43
0

This is related to how you style your video using CSS. Create block contents for videos and floating them to left until you reach 5 videos then go to a new line. For example,

<div class='wrapper'>
   <?
        $sql = mysql_query("SELECT * FROM VIDEOS ORDER BY ID DESC");
        while($rs = mysql_fetch_assoc($sql)){
     ?>
        <div class='block'>
            <img src="<?echo $rs['V_LOGO'];?>" width="150px" height="150px" />
            <p><a href="view.php?v=<?echo $rs['ID'];?>"><?echo $rs['V_TITLE'];?></a></p><br />
            <p><?echo $rs['V_DESC'];?></p>
        </div>
    <?}?>
</div>

For example, your wrapper container is 960px width, then you would style your block content like this:

.block {
   width: 150px;
   height: 150px;
   margin-right: 20px;
}
Tepken Vannkorn
  • 9,648
  • 14
  • 61
  • 86
0
<?php
    $i = 1;
    $sql = mysql_query("SELECT * FROM VIDEOS ORDER BY ID DESC");
    while($rs = mysql_fetch_assoc($sql))
    {
        if ($i == 1)
            echo '<div>';
        echo '<img src="'.$rs['V_LOGO'].'" width="150px" height="150px" />
        <p><a href="view.php?v='.$rs['ID'].'">'.$rs['V_TITLE'].'</a></p><br />
        <p>'.$rs['V_DESC'].'</p>';
        if ($i % 5 == 0)
        {
            echo '</div>';
            $i = 1;
        }
        $i++;
    }
?>

There you go. I also fixed your crappy php code.

JRunner
  • 1,437
  • 2
  • 10
  • 10