Page 1 of 1

Urgent little help needed :(

Posted: Sat Nov 27, 2010 9:45 am
by x3Harts
Hi there,
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 :(

Re: Urgent little help needed :(

Posted: Sun Nov 28, 2010 7:26 pm
by x3Harts
Anyone can help ? or was it too hard for you guys ? :mrgreen:

Re: Urgent little help needed :(

Posted: Sun Nov 28, 2010 8:11 pm
by Jonah Bron
Please edit your post and place all code into

Code: Select all

 tags, and indent your code.  That will make it much more readable and easier for people to help you :)

Okay, here we go.  You do not want to pass the news title to the highlights page to get the details.  Pass it's table index instead and use that to look it up.

Re: Urgent little help needed :(

Posted: Sun Nov 28, 2010 9:44 pm
by x3Harts
Hi there, i dun really know how to post the table index over. not really good with php coding.
My idea was to post over the news title over to the highlights.php and use the sql statement to print out all the details having that unique title.
The news title was successfully posted over into srow wrow and brow .
How i am going to do a loop so that the program will automatically recognize whether which category did the user click and choose to use which (srow, brow, wrow) as well as the 3 sql statements to use ? If the user choose to show the world news instead then the wrow and the sql statement for wrow would be used. Help pls :(