Jump to content

how to post the data in a new div each loop?


thme01

Recommended Posts

i am trying to fit this php code to so when ever i upload a video link to the database it prints in the divs from left to right. ( i have made blank boxes for where the videos should be, so you guys can see what i mean. i will give you the code here.

 

<?php
$query = mysql_query("SELECT * FROM `G4V_Videos` ORDER BY `id` DESC") or die(mysql_error());

while ($data = mysql_fetch_array($query)) { 
?>
ID-nummer: <?php print $data['id']; ?> - Name: <?php print $data['navn']; ?> - 
<a href="/Video.php?id=<?php print $data['id']; ?>"><img src="http://i.ytimg.com/vi/<?php print $data['link'];?>/hqdefault.jpg" width="200" height="160" /></a><br /> 
<a href="/Video.php?=<?php print $data['id']; ?>">
<?php
}
?>

 

 

and the website is here, http://www.game4vids.com/index.php

 

and i also want it so once i have used up all the boxes it posts the new video in box one and overwrites the old one if you get what i mean.

 

This website is a great example of what i mean.

http://www.retardo.dk

 

and i also want it so once i have used up all the boxes it posts the new video in box one and overwrites the old one if you get what i mean.

No, I do not get what you meant. You can't overwrite content you have already generated (well, technically you can, but that is not appropriate here). Looking at your mock page you have a section for three "featured" videos and another section for up to 24 videos. You simply need to run the appropriate queries to get UP TO the number of videos you want. If you only want the newest videos then only get the 24 most recent videos.

 

As to how to output them, you simply have a series of divs - so just output the content in divs. Also, if you don't have it, create a new field in the table for the creation date. You can set it up so the value is automatically set when creating a new record. Sorting by the id to indicate date added is not correct methodology.

 

Example

$query = "SELECT *
          FROM `G4V_Videos`
          ORDER BY `date_added` DESC
          LIMIT 24";
$result = mysql_query($query);

if(!$result)
{
    echo "Error running query: " . mysql_error();
}
else
{
    while ($row = mysql_fetch_assoc($result))
    { 
        echo "<div id='Video_thumbnail'>";
        echo "ID-nummer: {$row['id']} - Name: {$row['navn']} - ";
        echo "<a href='/Video.php?id={$row['id']}'>";
        echo "<img src='http://i.ytimg.com/vi/{$row['link']}/hqdefault.jpg' width='200' height='160' /></a>";
        echo "<br>";
        echo "<a href='/Video.php?={$row['id']}'>";
        echo "</div>";
    }
}

If you are using PHPMYADMIN, on the form to set up a DB field there is a column for "Default Value" if the "type" of field is "timestamp" the deafult clumn will have a checkbox titled "CURRENT_TIMESTAMP". Check it.

 

Or you can run a query such as this:

ALTER TABLE `table_name` ADD `date_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.