1.11M Members

php adding a button/analysing

 
0
 

i have a db that stores film and film reviews and using php i have created a system where the user can search for a review and then a list of reviews appear, i want to create a button with each review so that when selected the individual review can be analysed this will search the review to see how many positive and negative words it has
this is the code for my review.php

<?php

    $searching=$_POST['searching'];
    $searchfilm=$_POST['searchfilm'];


//If form is submitted 
    if ($searching =="yes")
    {
        echo "<h2>Film Review</h2><p>";


//If field is empty send a message 
    if ($searchfilm == "")
    {
        echo "<p>You forgot to enter a search term";
        echo
        exit;
    }


//Connect to database
    mysql_connect("nmnm", "jkjk", "mnm") or die(mysql_error());
    mysql_select_db("nmnnm") or die(mysql_error());


//Filter search
    $searchfilm = strtoupper($searchfilm);
    $searchfilm = strip_tags($searchfilm);
    $searchfilm = trim ($searchfilm);


//Qyery database
    $data = mysql_query("SELECT film.filmname, review.filmreview, review.reviewtitle FROM film, review WHERE film.filmid = review.filmid AND filmname = '$searchfilm'");  

    //$result = mysql_query($data) or die(mysql_error()); 


//Display film title searched for 
    echo "<b>Film Name:</b> " .$searchfilm;
    echo "<p>"; 


//Display results 
    while($row = mysql_fetch_array($data))
    {
        // echo $row['filmname'];
        // echo "<b>Film Name:</b> " .$searchfilm;
        echo "<table border=\"2\" align=\"left\">";
        echo "<tr><td>";
        echo "<b>Review Title:</b> " .$row['reviewtitle'];
        echo "<tr><td>";
        echo $row['filmreview'];
        echo "<p>";
        echo "<form method='post' action='analyse.php'>";
        echo "<tr><td><input type='submit' name='analyse' value='Analyse'/></td></tr>";
        echo "</form>";
        echo "</table>";
    }



//If result doesn't exist give an error message 
    $anymatches = mysql_num_rows($data);
    if ($anymatches == 0)
    {
        echo "Your request could not be processed, please enter a valid search<br><br>";
    }

}

?>

i am unsure is i have added the button correctly to the display results section too

any help would be appreciated

 
0
 

Hi,

next time place your codes between the [CODE} tags... just like what I did to your codes below.

<?php

$searching=$_POST['searching'];
$searchfilm=$_POST['searchfilm'];


//If form is submitted
if ($searching =="yes")
{
echo "<h2>Film Review</h2><p>";


//If field is empty send a message
if ($searchfilm == "")
{
echo "<p>You forgot to enter a search term";
echo
exit;
}


//Connect to database
mysql_connect("nmnm", "jkjk", "mnm") or die(mysql_error());
mysql_select_db("nmnnm") or die(mysql_error());


//Filter search
$searchfilm = strtoupper($searchfilm);
$searchfilm = strip_tags($searchfilm);
$searchfilm = trim ($searchfilm);


//Qyery database
$data = mysql_query("SELECT film.filmname, review.filmreview, review.reviewtitle FROM film, review WHERE film.filmid = review.filmid AND filmname = '$searchfilm'");

//$result = mysql_query($data) or die(mysql_error());


//Display film title searched for
echo "<b>Film Name:</b> " .$searchfilm;
echo "<p>";


//Display results
while($row = mysql_fetch_array($data))
{
// echo $row['filmname'];
// echo "<b>Film Name:</b> " .$searchfilm;
echo "<table border=\"2\" align=\"left\">";
echo "<tr><td>";
echo "<b>Review Title:</b> " .$row['reviewtitle'];
echo "<tr><td>";
echo $row['filmreview'];
echo "<p>";
echo "<form method='post' action='analyse.php'>";
echo "<tr><td><input type='submit' name='analyse' value='Analyse'/></td></tr>";
echo "</form>";
echo "</table>";
}



//If result doesn't exist give an error message
$anymatches = mysql_num_rows($data);
if ($anymatches == 0)
{
echo "Your request could not be processed, please enter a valid search<br><br>";
}

}

?>

It hurts the eyes, and I have to take some break for now..

 
0
 

Are you getting any error messages? Please post.

Thanks.

Also, on line 45, I usual add in MYSQL_ASSOC just for completeness - may not make a difference but it's good practice.

 
0
 

im not getting any error messages but unsure of adding a button that would allow each review to be analysed

 
0
 

no don't make a button for the search list view, it's much better if you just make them clickable, wrap them with anchors <a>, add id to link so upon clicking them, you will be redirected to it's detail view, where there you can display your positive and negative comments

 
0
 

the reason for the button is so that when selected the individual review is analysed by finding the number of negative and positive words to determine the type of review and these words are stored in my db

 
0
 

why button when you can just click them directly? well it's up to you

 
0
 

this is because its a system for a user therefore they wouldn't know to click the review its easier to have a button

 
0
 

does any body know how the button can created to be unique with each review ?

 
0
 

The link associated with the button would need to have a unique identifier - FILM ID maybe? I noticed there was a column called that in your SQL query.

 
0
 

as the filmreview needs analysing would this not be it ? as the film id would just identify the review against the film ?

 
0
 

something like this:

echo "<tr><td>" . "<form action='tabletest.php' method='post' onsubmit='return confirmSubmit()'>" . "<input type='hidden' value='" . $row['filmreview'] . "' name='film'>" . "<input type='submit' value='Analyse'>" . "</form>" . "</td></tr>";
You
This article has been dead for over six months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: