Jump to content

questing about php mysql query and clearing a form


scriptjet

Recommended Posts

$genre = $_POST['listMovies'];
$result = mysql_query("SELECT * FROM  movieTable SORT BY title");
$column = 1; define("COLUMNS", 2);
$movieCounter = 0;
echo "<h1>by " .$genre ."</h1><table>";	
while ($info = mysql_fetch_array($result)) {
	$genre1 = $info['genre1'];
	$genre2 = $info['genre2'];
	$genre3 = $info['genre3'];
	$title =  $info['title'];
        $link = $info['imdbLink'];

        
	if ($genre == $genre1 || $genre == $genre2 || $genre == $genre3) {
	$movieCounter++;

                if ($column == 1) {echo "<tr>";}
			echo "<td><a href='" .$link ."'>".$title ."</a></td>";
			$column++;
			if ($column > COLUMNS) {
				echo "</tr>";
				$column = 1;
			}             
	}
}

echo "<table><tr><td>" .$movieCounter ." movies found.</td></tr></table>";
if ($column > 1 && $column <= COLUMNS) {
while ($column++ <= COLUMNS) echo "<td></td>";
echo "</tr>";
}
echo "</table>";
$genre = "";

 

now that you have the code, i have 2 questions about this.  first one is this.  whenever i first load this code everything is empty as it should be.  then i select from a form a movie genre and everything work lovely.  the problem is that the movies that are loaded are still there when i come back to the page.  i need a way to clearing this out everytime the code is run, while still displaying the movies.

 

also .. this is just a php noob question here.  why is that when i run a query like this

 

 

$result = mysql_query("SELECT * FROM  movieTable SORT BY title");

 

i cannot use mysql_fetch_array or mysql_fetch_row? 

 

but it works when i do it like this

 

$result = mysql_query("SELECT * FROM  movieTable");

 

like i said that's just a noob question that i cannot for the life of me figure out. 

 

thanks for the help, this forum has been the biggest help to me learning php.

 

 

Link to comment
Share on other sites

yeah thanks for the ORDER BY -- not really sure what i was thinking there.  I was getting the error, but it was just saying invalid argument in the search. 

 

and i'm not really sure what to ask about the clearing the form.  it's not really a form that needs to be cleared.  perhaps it might be better if you went to the site to see it in action. 

 

http://www.projectscriptjet.com/drupal/node/18

 

the first time you go there it works right, but as soon as you choose a genre from the menu on the left it's like it keeps the movies in a holder.  i want it to be blank every time the page opens, i know it's gotta be some if statement but i'm not sure what it would be. 

 

i'm thinking that maybe i should set the if to be an isset of the buttons from the menu? 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.