Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP Databases
| Search | Today's Posts | Mark Forums Read
PHP Databases Using PHP in conjunction with databases. PHP questions not specific to databases should be directed to one of the other PHP forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 25th, 2006, 11:13 AM
Registered User
 
Join Date: Feb 2006
Location: paris, other, France.
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default [PAMWD]Definitive source

Hi,
I can't find a [code] tag, so I just paste this script as is.
It's in chapter 4, movie details reviews.
it takes a lot of cut and paste to get it going, so I thought I'd upload my working version:

*--------------------- movie_details.php -----------------------*

<?php
// movie_details.php
// computes profit or loss and returns value in green, red or blue

$link = mysql_connect("localhost", root, '')
    or die( mysql_error());

mysql_select_db("moviesite")
    or die( mysql_error());

// function
function calculate_differences( $takings, $cost )
{
    $difference = $takings - $costs;

    if ( $difference < 0 )
    {
        $difference = substr($difference, 1);
        $font_color = 'red';
        $profit_or_loss = '$' . $difference . "m";
    } // end if
    elseif ( $difference > 0 )
    {
        $font_color = 'green';
        $profit_or_loss = '$' . $difference . "m";
    } // end elseif
    else
    {
        $font_color = 'blue';
        $profit_or_loss = "Broke Even";
    } // end else

    return"" . $profit_or_loss . "";

} // end function c_d


// get the director name from the people table
function get_director()
{
global $movie_director;
global $director;

$query_d = "select people_fullname " .
            "from people " .
            "where people_id = '$movie_director'";
$results_d = mysql_query($query_d)
    or die(mysql_error());
$row_d = mysql_fetch_array($results_d);
extract($row_d);
$director = $people_fullname;
} // end function getdirector



// function get_leadactor
function get_leadactor()
{
global $movie_leadactor;
global $leadactor;

$query_a = "select people_fullname " .
            "from people " .
            "where people_id = '$movie_leadactor'";
$results_a = mysql_query($query_a)
    or die(mysql_error());
$row_a = mysql_fetch_array($results_a);
extract($row_a);
$leadactor = $people_fullname;
} // end function getdirector

// function g_r
function generate_ratings( $review_rating )
{
    $movie_rating = '';
    for( $i=0; $i<$review_rating; $i++ )
    {
        $movie_rating .= "<img src=\"grade_a.gif\">&nbsp;";
    } // end for
    return $movie_rating;
} // end function

$movie_query = "select * from movie where movie_id ='" . $_GET['movie_id'] . "'";

$movie_result = mysql_query( $movie_query, $link )
    or die( mysql_error());
while ( $row = mysql_fetch_array( $movie_result ) )
{
    $movie_name = $row['movie_name'];
     $movie_director = $row['movie_director'];
     $movie_leadactor = $row['movie_leadactor'];
    $movie_year = $row['movie_year'];
    $movie_running_time = $row['movie_running_time']." mins";
    $movie_takings = $row['movie_takings'];
    $movie_cost = $row['movie_cost'];

get_director();
get_leadactor();
} //end while


$movie_table_headings=<<<EOD
    <tr>
    <th>Movie Title</th>
    <th>Year of Release</th>
    <th>Movie Director</th>
    <th>Movie Lead Actor</th>
    <th>Movie Running Time</th>
    <th>Movie Health</th>
    </tr>
EOD;

$review_table_headings=<<<EOD
    <tr>
    <th>Date of Review</th>
    <th>Review Title</th>
    <th>Reviewer Name</th>
    <th>Movie Review Comments</th>
    <th>Ratings</th>
    </tr>
EOD;

// page 130
$review_query = "select * from reviews " .
                " where review_movie_id ='" . $_GET['movie_id'] . "' " .
                " ORDER by review_date DESC";

$review_result = mysql_query( $review_query, $link )
    or die( mysql_error());


while ( $review_row = mysql_fetch_array( $review_result ) )
{
    $review_flag = 1;
     $review_title[] = $review_row['review_name'];
     $reviewer_name[] = ucwords($review_row['review_reviewer_name']);
    $review[] = $review_row['review_comment'];
    $review_date[] = $review_row['review_date'];
    $review_rating[] = generate_ratings($review_row['review_rating']);
}

$movie_health = calculate_differences( $movie_takings, $movie_cost);

$page_start=<<<EOD
<html>
    <head>
        <title>Details and Review for: $movie_name</title>
    </head>
        <body>
EOD;

$movie_details=<<<EOD
<table width="70%" border="2" cellpadding="2"
        cellspacing="2" align="center">
    <tr>
    <th colspan="6">[u]<h2>$movie_name: Details</h2></u></th>
    </tr>
    $movie_table_headings
    <tr>
        <td width="33%" align="center">$movie_name</td>
        <td align="center">$movie_year</td>
        <td align="center">$director</td>
        <td align="center">$leadactor</td>
        <td align="center">$movie_running_time</td>
        <td align="center">$movie_health</td>
    </tr>
</table>
<br>
<br>
EOD;


// page 132

$i = 0;
$review_details ='';
while ( $i<sizeof($review) )
{
$review_details .=<<<EOD
<tr>
<td width="20%" valign="top" align = "center">$review_date[$i]</td>
<td width="15%" valign="top">$review_title[$i]</td>
<td width="10%" valign="top">$reviewer_name[$i]</td>
<td width="45%" valign="top">$review[$i]</td>
<td width="10%" valign="top" align = "center">$review_rating[$i]</td>
</tr>
EOD;
$i++;
}

if ($review_flag)
{
$movie_details .=<<<EOD
<table width="95%" border="0" cellspacing="1" cellpadding="10" align="center">
$review_table_headings
$review_details
</table>
EOD;
} // end if

$page_end=<<<EOD
</body>
</html>
EOD;

$detailed_movie_info =<<<EOD
$page_start
$movie_details
EOD;

echo $detailed_movie_info;
mysql_close();
echo "This is the last line" . "</body>" . "</html>";

?>
 *------------------ End Of Script ---------------------------*

P.S.
If you want to create a .jpg image that fits in the details table, the width should be 0.31 " and the height 0.15






Similar Threads
Thread Thread Starter Forum Replies Last Post
SOLVED - VBA Help For Row Source and Record Source eusanpe Access VBA 4 May 13th, 2008 11:58 AM
data source hastikeyvan ASP.NET 1.0 and 1.1 Basics 4 April 4th, 2008 11:13 PM
Disable View>Source (disable html source) kazmughal44 HTML Code Clinic 11 December 11th, 2007 11:53 AM
TWO Binding Source fazee Visual Basic 2005 Basics 0 October 27th, 2007 03:42 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.