Hello Everyone,
I'm quiet new to PHP, and I'm making a news portal practicing the language.
I have an index page where the news are posted in an order-> www.fundis.hu/index.php
I have a results page, where is a search engine -> www.fundis.hu/results.php
In the index page I used dynamic links
<?php
if ($_POST['title'] <> "")$filter = "where title = '".$_POST['title']."'";else $filter = "";
include 'dbs.php';
mysql_select_db('fundis_phplogin');
$query = "select * from news ".$filter." order by id DESC LIMIT 5";
$images = mysql_query($query) or die ('Error in query1: $query.' .mysql_error());
$query = "select distinct title from news order by title";
$sections = mysql_query($query) or die ('Error in query: $query.' .mysql_error());
while($row = mysql_fetch_row($images))
{
echo '<table><a href="results.php?'. $row[0].'">'. $row[1].'</a>' . '<br />';
echo '</td></tr><tr><td>Szerző:</td><td>'. $row[2].'</td></tr><tr><td>Hír:</td><td>'. $row[3].'</td></tr></table>';
}
mysql_free_result($images);
mysql_free_result($sections);
mysql_close($connection);
?>
So I want to echo the rows by the dynamic link. I want to search for the id which we posted to the results.php?(id). How can I do that? Here is my results.php -->
<?php
include 'db.php';
// create short variable names
$searchtype=$_POST['searchtype'];
$searchterm=trim($_POST['searchterm']);
if (!$searchtype || !$searchterm) {
echo 'You have not entered search details. Please go back and try again.';
}
if(!get_magic_quotes_gpc()){
$searchtype = addslashes($searchtype);
$searchterm = addslashes($searchterm);
}
if (mysqli_connect_errno()) {
echo 'Error: Could not connect to database. Please try again later.';
exit;
}
$query = "select * from news where ".$searchtype." like '%".$searchterm."%'";
$result = $db->query($query);
$num_results = $result->num_rows;
echo "<p>Number of news found: ".$num_results."</p>";
for ($i=0; $i <$num_results; $i++) {
$row = $result->fetch_assoc();
echo "<p><strong>".($i+1).". Title: ";
echo htmlspecialchars(stripslashes($row['title']));
echo "<br />Created: ";
echo stripslashes($row['date']);
echo "</p>";
echo "</strong><br />Author: ";
echo stripslashes($row['author']);
echo "<br />";
echo "<br />";
echo stripslashes($row['text']);
}
$result->free();
$db->close();
?>