thme01 Posted October 19, 2011 Share Posted October 19, 2011 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 Quote Link to comment Share on other sites More sharing options...
Psycho Posted October 19, 2011 Share Posted October 19, 2011 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>"; } } Quote Link to comment Share on other sites More sharing options...
thme01 Posted October 19, 2011 Author Share Posted October 19, 2011 what i mean is, that out of the 24 boxes. Box number 1. ( top left box ) is always going to be the newest, followed by the box to the right of it which will be the second newest and so on But thanks for the reply it is very useful! Quote Link to comment Share on other sites More sharing options...
thme01 Posted October 19, 2011 Author Share Posted October 19, 2011 and if you would be ever so kind to tell me how to make the field input the value automatically after creating a new record, i cant seem to figure it out.. Quote Link to comment Share on other sites More sharing options...
Psycho Posted October 19, 2011 Share Posted October 19, 2011 and if you would be ever so kind to tell me how to make the field input the value automatically after creating a new record, i cant seem to figure it out.. No idea what you are talking about. What field input? Quote Link to comment Share on other sites More sharing options...
litebearer Posted October 19, 2011 Share Posted October 19, 2011 I believe he wants to know how to auto-fill the date_created db field Quote Link to comment Share on other sites More sharing options...
Psycho Posted October 19, 2011 Share Posted October 19, 2011 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 Quote Link to comment 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.