Jump to content

I've got some questions about PHP/MySQL-scripts (DVD database)


DaKiNdo

Recommended Posts

Hi there!

Here's my code for my DVD database:

<?
      mysql_connect('localhost','dvddb','XXX');
         @mysql_select_db('dvddb') or die("Can't locate database");
         switch ( $page ) {
         default:
            $resultat = mysql_query("SELECT * FROM dvd ORDER BY id DESC");
         break;
         case "oldest":
            $resultat = mysql_query("SELECT * FROM dvd ORDER BY LCASE(oldest) DESC, id ASC");
         break;
	 case "rating":
            $resultat = mysql_query("SELECT * FROM dvd ORDER BY LCASE(rating) ASC, rating DESC");
         break;
	 case "brating":
            $resultat = mysql_query("SELECT * FROM dvd ORDER BY LCASE(rating) DESC, rating ASC");
         break;
         case "page":
            $resultat = mysql_query("SELECT * FROM dvd ORDER BY id DESC LIMIT " . $_GET['start'] .",25");
         $last = ( $_GET['start']-25 );
         if ($last < 0 ) $last = 0;
         break;
      }
?>
<? echo mysql_error() ?>
<img src="<? echo $myrow['pic'] ?>.jpg" border="0" alt="<? echo $myrow['title'] ?>" />
<h2><? echo $myrow['title'] ?></h2>
<p><span class="what">Added:</span> <? echo $myrow['added'] ?></p>
<p><span class="what">Rating:</span> <img src="<? echo $myrow['rating'] ?>.jpg" border="0" alt="<? echo $myrow['rating'] ?>" /></p>
<p><span class="what">IMDb:</span> <a href="http://www.imdb.com/title/<? echo $myrow['imdb'] ?>" target="_blank"><? echo $myrow['title'] ?></a></p>
<p><span class="what">Review:</span> <a href="#">Read review</a></p>

I've got four questions:

  • How can I let the script make new div's for each row in the db? This only adds one of the time.
  • Does this script show 25 rows only when sorting by id? If so - how to make it shows 25 anytime?
  • I was thinking about making a edit script. So how can I make a input- (and submit-button) where I could write the DVD's ID, and when pressing submit - it should show the row values in input columns.
  • I haven't made a review for all of the DVD's I've seen. I've got a input called "reviewyesno", and I wan't to post "<p><span class="what">Review:</span> <a href="<? echo $myrow['review'] ?>">Read review</a></p>" - IF the value of reviewyesno is 1. If the value is 0, I wan't it to post "<p><!-- No review //--> </p>".

 

It would be awsome if someone could help me out here!

Link to comment
Share on other sites

This is how you can put a div for each entry:

while ($myrow = mysql_fetch_assoc($resultat))
{
   echo "<div>".$myrow['Content']."</div>
}

Ordering won't affect how many rows are returned.
To make an edit page, you would do it the same way you display the information, but put the information inside input tags.

To display if there is a review or not, inside the while loop above put something like:
[code]
if ($myrow['reviewyesno'])
   echo "There is a review";
else
   echo "There is no review";

 

Good luck![/code]

Link to comment
Share on other sites

This is how you can put a div for each entry:

while ($myrow = mysql_fetch_assoc($resultat))
{
   echo "<div>".$myrow['Content']."</div>
}

Ordering won't affect how many rows are returned.
To make an edit page, you would do it the same way you display the information, but put the information inside input tags.

To display if there is a review or not, inside the while loop above put something like:
[code]
if ($myrow['reviewyesno'])
   echo "There is a review";
else
   echo "There is no review";

 

Good luck![/code]

How to make this Content?

 

You didn't answer my actual question about edit-page. Because I wan't to make a input where the DVD's ID should be. When pressing submit, the info about that ID should appear beneath it - in inputs.

 

That script you posted for the review wouldn't work, would it? Wouldn't this work better?

if($myrow['reviewyesno'] == '1'){
    echo 'XX';
}
else{
    echo 'XX';
}

Link to comment
Share on other sites

Nice BBCode Lemmin

Woops  :D

 

 

For the edit page, along with all of the inputs just put a hidden input that contains the dvd id:

echo "<input type=HIDDEN name=\"id\" value=\"$id\">";

 

 

That script you posted for the review wouldn't work, would it? Wouldn't this work better?

 

What you posted is the exact same thing. Since a value of '0' means that there is no review, "if (0)" evaluates to false. Any other value will evaluate to true.

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.