davinci Posted March 7, 2006 Share Posted March 7, 2006 Want to insert this HTML header:[code]<div class="title">Videos</div>[/code]Into this script without it repeating in the loop:[code]<?phpinclude 'library/config.php';include 'library/opendb.php';$id = $_GET['id'];if ($id == "") {$rowsPerPage = 6;$pageNum = 1; if(isset($_GET['page'])){ $pageNum = $_GET['page'];}$offset = ($pageNum - 1) * $rowsPerPage; $query = "SELECT id, name, path, title, thumbnail, playcount, DATE_FORMAT(entry_date, '%M %D %Y') FROM upload2 ORDER BY id DESC LIMIT $offset, $rowsPerPage";$result = mysql_query($query) or die('Error, query failed');while($row = mysql_fetch_array($result)) { ?><div align="center"><table cellpadding="2" width="75%" border="0" cellspacing="0" cellpadding="0"><tr><td width="50%"><a href="<?php echo $_SERVER['PHP_SELF'] ?>?id=<?= $row['id'];?>"><IMG BORDER="0" img src="media/thumbs/<?=$row['thumbnail'];?>" height="80" width="80"><p></a></td><td width="50%"><a href="<?php echo $_SERVER['PHP_SELF'] ?>?id=<?= $row['id'];?>"><b><?php echo $row['title'];?></b></a><br>Added on <?=$row['date'];?><br>Plays: <?=$row['playcount'];?> </td></tr></table><? } ?>[/code]Can someone show me how to insert this code as a heading rather than a repeated element? Quote Link to comment Share on other sites More sharing options...
davinci Posted March 7, 2006 Author Share Posted March 7, 2006 Solved it...!This seemed to do the trick:[code]<?phpinclude 'library/config.php';include 'library/opendb.php';$id = $_GET['id'];if ($id == "") {$heading = '<div class="title">Video Archive</div><p>';$rowsPerPage = 6;$pageNum = 1; if(isset($_GET['page'])){ $pageNum = $_GET['page'];}$offset = ($pageNum - 1) * $rowsPerPage; echo $heading;$query = "SELECT id, name, path, title, thumbnail, playcount, DATE_FORMAT(entry_date, '%M %D %Y') FROM upload2 ORDER BY id DESC LIMIT $offset, $rowsPerPage";$result = mysql_query($query) or die('Error, query failed');while($row = mysql_fetch_array($result)) { ?>[/code] Quote Link to comment Share on other sites More sharing options...
PWD Posted March 7, 2006 Share Posted March 7, 2006 Just place it before your while() loop:[code]<?phpinclude 'library/config.php';include 'library/opendb.php';$id = $_GET['id'];if ($id == "") {$rowsPerPage = 6;$pageNum = 1;if(isset($_GET['page'])){ $pageNum = $_GET['page'];}$offset = ($pageNum - 1) * $rowsPerPage;$query = "SELECT id, name, path, title, thumbnail, playcount, DATE_FORMAT(entry_date, '%M %D %Y') FROM upload2 ORDER BY id DESC LIMIT $offset, $rowsPerPage";$result = mysql_query($query) or die('Error, query failed');?><div class="title">Videos</div><?phpwhile($row = mysql_fetch_array($result)) { ?>/*Your Other HTML Markup for your loop*//*Then close your loop*/<?php}?>[/code] Quote Link to comment Share on other sites More sharing options...
davinci Posted March 7, 2006 Author Share Posted March 7, 2006 Your way makes more sense! I've changed it to what you told me and now I have a better understanding of why it works the way it does. Thank you very much. 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.