xux Posted November 6, 2006 Share Posted November 6, 2006 Hi, I am trying to implement a page,whereby if images is available it will be displayed but if not it wont display it.My codes are working but with a little bug,if image is not supply it will leave show the image placeholder (the kind that is shown if the image is not available).here are my codes[code]<div class="mainContent"> <p><h2 align="center" style="color: #330099;"><u>News and Events</u></h2></p> <?php $pageNo = $HTTP_GET_VARS['p'];//the page number $displayLength = 5;//the number of news to display per page @$db = mysql_pconnect('localhost', '', ''); if(!$db){ echo "<p style=\"color: #CC0000;\" align=\"center\"><b>ERROR: </b>Could not connect to database. Please try again later</p><p align=\"center\"> Please refresh this page and if the problem persists, contact <a href=\"mailto:webmaster@smeresources.org\">webmaster</a>. Thank you<br /></p>"; exit; } mysql_select_db('DB') ; $query = "SELECT title, picture, content FROM news ORDER BY expiry_date DESC LIMIT ".($pageNo*$displayLength).", ".$displayLength; $result = mysql_query($query); $query1 = "select count(*) from news"; if($result){ for($a=0;$a<$displayLength;$a++){ $row = mysql_fetch_array($result); $title = $row['title']; $picture_url = $row['picture']; $content = $row['content']; //print the news if($title){ echo "<p style=\"color: rgb(147, 3, 187); font-weight: bold;\"><u>$title</u></p>"; if($picture_url) echo "<img src=\"$picture_url\" alt=\"Picture\" align=\"right\" border=\"0\" hspace=\"5\" vspace=\"5\">\n"; echo $content; }else{ break; } } $query = "SELECT count(*) FROM news"; $result1 = mysql_query($query); $row = mysql_fetch_array($result1); $dbSize = $row[0]; $availableNoOfPagesInDB = $dbSize/$displayLength; $nextPage = $pageNo+1; $previousPage = $pageNo-1; echo "<p align=\"right\">"; if($previousPage >= 0){ echo "<a href=\"news.php?p=".($previousPage)."\"><strong><previous</strong></a>"; } if($nextPage <= $availableNoOfPagesInDB){ echo " <a href=\"news.php?p=".($nextPage)."\"><strong>next></strong></a>"; } echo "</p>"; } ?> [/code]and it is giving this error message[code]Parse error: syntax error, unexpected T_ELSE in /home/sm/public_html/news.php on line 41[/code]Thanks Quote Link to comment Share on other sites More sharing options...
trq Posted November 6, 2006 Share Posted November 6, 2006 Sorry, but the formatting applied to your code makes it near impossible to read. Please take the time to make your post clear. Quote Link to comment Share on other sites More sharing options...
xux Posted November 6, 2006 Author Share Posted November 6, 2006 [code] <?php $pageNo = $HTTP_GET_VARS['p'];//the page number $displayLength = 5;//the number of news to display per page @$db = mysql_pconnect('localhost', '', ''); if(!$db){ echo" ERROR: </b>Could not connect to database. Please try again later"; exit; } mysql_select_db('DB') ; $query = "SELECT title, picture, content FROM news ORDER BY expiry_date DESC LIMIT ".($pageNo*$displayLength).", ".$displayLength; $result = mysql_query($query); $query1 = "select count(*) from news"; if($result){ for($a=0;$a<$displayLength;$a++){ $row = mysql_fetch_array($result); $title = $row['title']; $picture_url = $row['picture']; $content = $row['content']; //print the news if($title){ echo "<p style=\"color: rgb(147, 3, 187); font-weight: bold;\"><u>$title</u></p>"; if($picture_url) echo "<img src=\"$picture_url\" alt=\"Picture\" align=\"right\" border=\"0\" hspace=\"5\" vspace=\"5\">\n"; echo $content; }else{ break; } } $query = "SELECT count(*) FROM news"; $result1 = mysql_query($query); $row = mysql_fetch_array($result1); $dbSize = $row[0]; $availableNoOfPagesInDB = $dbSize/$displayLength; $nextPage = $pageNo+1; $previousPage = $pageNo-1; echo "<p align=\"right\">"; ?> [/code]Thanks,I have stripped it of the formating Quote Link to comment Share on other sites More sharing options...
intrigue Posted November 6, 2006 Share Posted November 6, 2006 whats at line 41?matt Quote Link to comment Share on other sites More sharing options...
trq Posted November 6, 2006 Share Posted November 6, 2006 [quote]Thanks,I have stripped it of the formating[/quote]Your code still starts almost off the page. Make it easy for us to help you. Quote Link to comment Share on other sites More sharing options...
xux Posted November 6, 2006 Author Share Posted November 6, 2006 [code]<?php$pageNo = $HTTP_GET_VARS['p'];//the page number $displayLength = 5;//the number of news to display per page @$db = mysql_pconnect('localhost', '', ''); if(!$db){ echo" ERROR: </b>Could not connect to database. Please try again later"; exit; } mysql_select_db('DB') ; $query = "SELECT title, picture, content FROM news ORDER BY expiry_date DESC LIMIT ".($pageNo*$displayLength).", ".$displayLength; $result = mysql_query($query); $query1 = "select count(*) from news"; if($result){ for($a=0;$a<$displayLength;$a++){ $row = mysql_fetch_array($result); $title = $row['title']; $picture_url = $row['picture']; $content = $row['content']; //print the news if($title){ echo "<p style=\"color: rgb(147, 3, 187); font-weight: bold;\"><u>$title</u></p>"; if($picture_url) echo "<img src=\"$picture_url\" alt=\"Picture\" align=\"right\" border=\"0\" hspace=\"5\" vspace=\"5\">\n"; echo $content; }else{ break; } } $query = "SELECT count(*) FROM news"; $result1 = mysql_query($query); $row = mysql_fetch_array($result1); $dbSize = $row[0]; $availableNoOfPagesInDB = $dbSize/$displayLength; $nextPage = $pageNo+1; $previousPage = $pageNo-1; echo "<p align=\"right\">"; ?> [/code]Thanks,I appreciate Quote Link to comment Share on other sites More sharing options...
xux Posted November 6, 2006 Author Share Posted November 6, 2006 [code]<?php$pageNo = $HTTP_GET_VARS['p'];//the page number $displayLength = 5;//the number of news to display per page @$db = mysql_pconnect('localhost', '', ''); if(!$db){ echo" ERROR: </b>Could not connect to database. Please try again later"; exit; } mysql_select_db('DB') ; $query = "SELECT title, picture, content FROM news ORDER BY expiry_date DESC LIMIT ".($pageNo*$displayLength).", ".$displayLength; $result = mysql_query($query); $query1 = "select count(*) from news"; if($result){ for($a=0;$a<$displayLength;$a++){ $row = mysql_fetch_array($result); $title = $row['title']; $picture_url = $row['picture']; $content = $row['content']; //print the news if($title){ echo "<p style=\"color: rgb(147, 3, 187); font-weight: bold;\"><u>$title</u></p>"; if($picture_url) echo "<img src=\"$picture_url\" alt=\"Picture\" align=\"right\" border=\"0\" hspace=\"5\" vspace=\"5\">\n"; echo $content; }else{ break; } } $query = "SELECT count(*) FROM news"; $result1 = mysql_query($query); $row = mysql_fetch_array($result1); $dbSize = $row[0]; $availableNoOfPagesInDB = $dbSize/$displayLength; $nextPage = $pageNo+1; $previousPage = $pageNo-1; echo "<p align=\"right\">"; ?> [/code] 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.