Jump to content

Text and Images Interaction


xux

Recommended Posts

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>&lt;previous</strong></a>";
}

if($nextPage <= $availableNoOfPagesInDB){
echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"news.php?p=".($nextPage)."\"><strong>next&gt;</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
Link to comment
Share on other sites

[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
Link to comment
Share on other sites

[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
Link to comment
Share on other sites

[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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.