I have 2 php files name Homepage.php and Highlights.php
Homepage.php
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Code: Select all
<?php
$link = mysqli_connect('localhost','newsbookuser', 'password', 'assignment1');
$S_sql = "SELECT newsTitle FROM news WHERE newsCategory LIKE '%Singapore%' ORDER BY newsDate DESC";
$W_sql = "SELECT newsTitle FROM news WHERE newsCategory LIKE '%World%' ORDER BY newsDate DESC";
$B_sql = "SELECT newsTitle FROM news WHERE newsCategory LIKE '%Business%' ORDER BY newsDate DESC";
$S_result = mysqli_query($link, $S_sql) or die(mysqli_error($link));
$W_result = mysqli_query($link, $W_sql) or die(mysqli_error($link));
$B_result = mysqli_query($link, $B_sql) or die(mysqli_error($link));
$S_counter = 0;
$W_counter = 0;
$B_counter = 0;
echo "<h3><U>Singapore</U></h3>";
while($S_row=mysqli_fetch_array($S_result)){
$S_counter = $S_counter + 1;
if ($S_counter <=3){
echo "<form name=\"F1\" action=\"Highlights.php\" method=\"POST\">";
echo "<input type=\"hidden\" name=\"SRow\" value=\"$S_row[0]\">";
echo "<p><input name=\"btnsubmit\" class=\"submit\" type=\"submit\" value=\"$S_row[0]\" style=\"cursor: pointer;border: 0; text-decoration: underline; background: transparent; color: blue;\"</p>";
echo "</form>";
}
}
echo "<h3><U>World</U></h3>";
while($W_row=mysqli_fetch_array($W_result)){
$W_counter = $W_counter + 1;
if ($W_counter <=3){
echo "<form name=\"F2\" action=\"Highlights.php\" method=\"POST\">";
echo "<input type=\"hidden\" name=\"WRow\" value=\"$W_row[0]\">";
echo "<p><input name=\"btnsubmit\" class=\"submit\" type=\"submit\" value=\"$W_row[0]\" style=\"cursor: pointer;border: 0; text-decoration: underline; background: transparent; color: blue;\"</p>";
echo "</form>";
}
}
echo "<h3><U>Business</U></h3>";
while($B_row=mysqli_fetch_array($B_result)){
$B_counter = $B_counter + 1;
if ($B_counter <=3){
echo "<form name=\"F3\" action=\"Highlights.php\" method=\"POST\">";
echo "<input type=\"hidden\" name=\"BRow\" value=\"$B_row[0]\">";
echo "<p><input name=\"btnsubmit\" class=\"submit\" type=\"submit\" value=\"$B_row[0]\" style=\"cursor: pointer;border: 0; text-decoration: underline; background: transparent; color: blue;\"</p>";
echo "</form>";
}
}
?>
Everything in the homepage works i cant seem to figure out a way to complete the codes for highlights.php
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Highlights.php
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Code: Select all
<?php
$srow = $_POST['SRow'];
$wrow = $_POST['WRow'];
$brow = $_POST['BRow'];
$link = mysqli_connect('localhost','newsbookuser', 'password', 'assignment1');
$sql1 = "SELECT * FROM news WHERE newsTitle LIKE '%$srow%'";
$sql2 = "SELECT * FROM news WHERE newsTitle LIKE '%$wrow%'";
$sql3 = "SELECT * FROM news WHERE newsTitle LIKE '%$brow%'";
$result = mysqli_query($link, $sql) or die(mysqli_error($link));
$row=mysqli_fetch_array($result);
echo "<b><I>Category</I></b>: $row[0]<br/><br/>";
echo "<b><I>Headline</I></b>: $row[1]<br/><br/>";
echo "<b><I>Writer</I></b>: $row[2]<br/><br/>";
echo "<b><I>Source</I></b>: $row[3]<br/><br/>";
echo "<b><I>Date</I></b>: $row[4]<br/><br/>";
echo "<b><I>Story</I></b>: $row[5]<br/><br/>";
echo "<br /><hr>";
mysqli_close($link);
?>
My idea here was to when the user clicked on the 'hyperlink' ( submit button ) in the homepage, the newstitle of the homepage will be posted of to the highlights.php. From there i will be using the sql statements to search through my database to print out all the details having that newstitle. I tried many methods which i could but i could not print out the details of the particular news title.
Can anyone provide me with some help ? Really appreciate if you do so