1,105,534 Community Members

php adding a button/analysing

Member Avatar
cr7489
Junior Poster in Training
53 posts since Dec 2011
Reputation Points: 15 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
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

Member Avatar
veedeoo
Veteran Poster
1,016 posts since Oct 2011
Reputation Points: 314 [?]
Q&As Helped to Solve: 166 [?]
Skill Endorsements: 17 [?]
 
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..

Member Avatar
phper
Posting Whiz in Training
209 posts since Nov 2006
Reputation Points: 9 [?]
Q&As Helped to Solve: 19 [?]
Skill Endorsements: 0 [?]
 
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.

Member Avatar
cr7489
Junior Poster in Training
53 posts since Dec 2011
Reputation Points: 15 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Member Avatar
vaultdweller123
Posting Pro
577 posts since Sep 2009
Reputation Points: 32 [?]
Q&As Helped to Solve: 84 [?]
Skill Endorsements: 2 [?]
 
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

Member Avatar
cr7489
Junior Poster in Training
53 posts since Dec 2011
Reputation Points: 15 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
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

Member Avatar
vaultdweller123
Posting Pro
577 posts since Sep 2009
Reputation Points: 32 [?]
Q&As Helped to Solve: 84 [?]
Skill Endorsements: 2 [?]
 
0
 

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

Member Avatar
cr7489
Junior Poster in Training
53 posts since Dec 2011
Reputation Points: 15 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
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

Member Avatar
cr7489
Junior Poster in Training
53 posts since Dec 2011
Reputation Points: 15 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Member Avatar
phper
Posting Whiz in Training
209 posts since Nov 2006
Reputation Points: 9 [?]
Q&As Helped to Solve: 19 [?]
Skill Endorsements: 0 [?]
 
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.

Member Avatar
cr7489
Junior Poster in Training
53 posts since Dec 2011
Reputation Points: 15 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Member Avatar
cr7489
Junior Poster in Training
53 posts since Dec 2011
Reputation Points: 15 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
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 three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: