Click to See Complete Forum and Search --> : how to show news if I have ID number in table


toplisek
03-16-2006, 10:32 AM
I need help with PHP code.

How to read in right format (from table on server) if there is content on server and when user clicks on news link, it will show ali content (each news will have its own ID number

I have format for HTML code and PHP code:


<!-- Table News -->
<table cellspacing="0" cellpadding="0" border="0" class="news_field">

<tr>
<td valign="top" class="news_headline"><b>News</b></td>
</tr>
<tr>
<td valign="top" class="text1">

<?PHP


// <!--Start News1 -->
echo '<table border="0" cellspacing="0" cellpadding="0">';
echo'<tr>';

echo '<td colspan=4><IMG alt="" border="0" width="1" height="1" hspace="0" src="images/image12.gif"></td>
</tr>';

echo '<tr>';
echo '<td width="60" align="left" valign="top" nowrap class="news_content1a">';
echo '<a href="" class="news_content1a">11.10.2005:</a></span><br></td>';

echo '<td width="5" align="left" valign="middle"><IMG alt="" border="0" width="3" height="1" hspace="0" src="images/image12.gif"></td>';
echo '<td width="100%" align="left" valign="top">';
echo '<span class="news_content1a">News Source1</span><br>';
echo '<span class="news_content2a">News Headline1</span><br><br></td>';

echo '</tr>';
echo '</table>';
/* <!-- End News1 -->

<!--Start News2 --> */
echo '<table border="0" cellspacing="0" cellpadding="0">';
echo'<tr>';

echo '<td colspan=4><IMG alt="" border="0" width="1" height="1" hspace="0" src="images/image12.gif"></td>
</tr>';

echo '<tr>';
echo '<td width="60" align="left" valign="top" nowrap class="news_content1a">';
echo '<a href="" class="news_content1a">11.10.2005:</a></span><br></td>';

echo '<td width="5" align="left" valign="middle"><IMG alt="" border="0" width="3" height="1" hspace="0" src="images/image12.gif"></td>';
echo '<td width="100%" align="left" valign="top">';
echo '<span class="news_content1a">News Source2</span><br>';
echo '<span class="news_content2a">News Headline2</span><br><br></td>';

echo '</tr>';
echo '</table>';
/* <!-- End News2 -->

echo '</td></tr>';
echo ' </table>';
echo '<table>';
echo '<tr>';
echo '<td ><span class="text3"><b>News</b>&nbsp;more</span>';
echo '</a>';
echo '</td></tr>';
echo '</table>';



Need help. It is difficult question, but I hope you can help.

LiLcRaZyFuZzY
03-16-2006, 11:36 AM
Is the content from a database?

PS: Wenn es für dich zu schwer ist auf english zu erklären, kannst du es mir auf deutsch sagen.

toplisek
03-16-2006, 11:54 AM
I have stored content on server (articles and news).
On server there is
Date/time of input article on server
ID
Title
Date of article
Summary
Full article

Now I have to retrieve this and publish if user would decide.

LiLcRaZyFuZzY
03-16-2006, 01:17 PM
in a database?

toplisek
03-17-2006, 01:52 PM
Yes it is in database on server stored in table with fields. In this case there are not separated files. I would like to do management system for publishing news.

Sheldon
03-17-2006, 02:12 PM
You would access the page with links like http://www.toplisek.com/article.php?id=100

then article.php would be like this


<?php

ob_start("ob_gzhandler"); //make pages faster

session_start(); // dont need the session but hey, why not?

//connect to your datbase
$conx = mysql_connect ("localhost",
"username",
"password")
or die('I cannot connect to the database because: ' . mysql_error());

mysql_select_db("database");

//now check if the article to view is set
if(!isset($_GET['id'])){
echo("You must select and article");
}else{
$article = $_GET['id'];
//article is set so pull article info from the database

$q = "SELECT * FROM articles WHERE id = '".$article."' ";
$s = mysql_query($q);
echo(mysql_error()); //echo error if we have one with the database

while($r = mysql_fetch_assoc($s)){
// now all mySQL results will have the var $r['field_name'];


//start the page
?>

<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd\">

<html>

<head>

<title>Toplisek's News <?php echo($r['title']); ?></title>

</head>

<body>

<h1><?php echo($r['title']); ?></h1>

<p><?php echo($r['article_text']); ?></p>

</body>

</html>

<?php

} //close the while

}//close the if/else statement that checks if we have an article.

?>

toplisek
03-19-2006, 05:32 AM
I would like to read all articles in rows with help form your code.

Do you know why it gives me error
Warning: link(): Permission denied in ...read_article.php on line 55
Line 55 is:

echo '<td><A HREF="'.link("article.php", "ID=".$_GET['id']).'"><B>'.$rec[$i].'</B></A></td>';



code is:

<?

# Param 1 : MySQL Host Name
# Param 2 : MySQL Username
# Param 3 : MySQL Password
# Param 4 : MySQL Database
# Param 5 : SQL Statement (SELECT)

show_table("localhost","...","...","...","SELECT * FROM articles");

function show_table($hostName,$userName,$passWord,$dataBase,$sqlQuery)
{
# Connect to MySQL
$conn=mysql_connect("...", "...", "...");
# Select Database
mysql_select_db($dataBase,$conn);
# Validate SQL Statement
$array=explode(" ORDER",$sqlQuery);
$sqlQuery=$array[0];
if(!strstr($sqlQuery,"SELECT"))
die("Invalid Query : SQL statement should be a SELECT statement.");
# ORDER records by requested column
if($_GET['order'])
$sqlQuery=$sqlQuery." ORDER BY ".$_GET['order'];
# Execute SQL query
$result=mysql_query($sqlQuery) or die("Invalid Query : ".mysql_error());
$row=mysql_fetch_array($result);
# Check whether NULL records found
if(!mysql_num_rows($result))
die("No records found.");

echo "<table border=1><tr>";
# Make the row for table column names
while (list($key, $value) = each($row))
{
$i++;
if(!($i%2))
echo "<td><b><a href='?order=$key'>$key</a></td>";
}
echo "</tr>";
$result=mysql_query($sqlQuery);

// Make rows for records
while($rec=mysql_fetch_array($result))
{
echo "<tr>";
for($i=0;$i<count($rec);$i++)
{
if($rec[$i])
echo '<td><A HREF="'.link("article.php", "ID=".$_GET['id']).'"><B>'.$rec[$i].'</B></A></td>';

}
echo "</tr>";
}
echo "</table>";
}
?>