Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
|
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP 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 August 23rd, 2012, 08:35 AM
Registered User
 
Join Date: Aug 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default problem : extract function

Hello,
i m beginner in PHP, i m learning PHP & MySQL with WROX Book ''PHP6, Apache, MySQL Web Development''.
My Problem is this i have created a page with database connection according to chapter 4 but i found the following error :
Warning: extract() [function.extract]: First argument should be an array
i am not founding any type of solution for this problem. I m including my code also Here
<?php
//take the id of director for full name of Director
function get_director($director_id)
{
global $db;
$query = 'SELECT
people_fullname
FROM
people
WHERE
people_id = '. $director_id;
$result=mysql_query($query, $db) or die (mysql_error ($db));
$row = mysql_fetch_assoc($result);
extract($row);

return $people_fullname;
}
//take in the id of a lead actor and return his/her full name
function get_leadactor($leadactor_id){
global $db;
$query = 'SELECT
people_fullname
FROM
people
WHERE
people_id ='. $leadactor_id;
$result=mysql_query($query, $db) or die (mysql_error($db));
$row=mysql_fetch_assoc($result);
extract($row);
return $people_fullnanme;

}
//take the id of movietype and return this textfull name
function get_movietype($type_id)
{
global $db;
$query = 'SELECT
movietype_label
FROM
movietype
WHERE
movietype_id='. $type_id;
$result=mysql_query($query, $db) or die (mysql_error($db));
$row=mysql_fetch_assoc($result);
return $movietype_label;

}
//connect to mysql
$db = mysql_connect('localhost', 'bp6am', 'bp6ampass') or die ('Unable to Connect the Server. Check Your connection parameters');
//make sure we are using the right database
mysql_select_db('moviesite', $db) or die (mysql_error($db));
//retrive the informtion
$query = 'SELECT
movie_name, movie_year, movie_director, movie_leadactor, movie_type
FROM
movie
ORDER BY
movie_name ASC,
movie_year DESC';
//ASC mean ascending order
//DESC means descending order
$result=mysql_query($query, $db) or die(mysql_error($db));
//determine number of rows in returned result
$num_movies = mysql_num_rows($result);
$table = <<<ENDHTML
<div style="text-align:center;">
<h2>Movie Review Database</h2>
<table border="1" cellpadding="2" cellspacing="2" style="width:70%; margin-left:auto; margin-right:auto;">
<tr>
<th>Movie Title</th>
<th>Year of Release</th>
<th>Movie Director</th>
<th>Movie Lead Actor</th>
<th>Movie Type</th>
</tr>
ENDHTML;
while ($row = mysql_fetch_assoc($result))
{
extract($row);
$director=get_director($movie_director);
$leadactor=get_leadactor($movie_leadactor);
$movietype=get_movietype($movie_type);
$table .=<<<ENDHTML
<tr><td>$movie_name</td>
<td>$movie_year</td>
<td>$director</td>
<td>$leadactor</td>
<td>$movietype</td></tr>
ENDHTML;
}
$table .=<<<ENDHTML
</table>
<p>$num_movies Movies</p>
</div>
ENDHTML;
echo $table;
?>


plz help me to solve this problem.





Similar Threads
Thread Thread Starter Forum Replies Last Post
problem function lejka Java Basics 1 August 20th, 2009 02:53 AM
function problem lejka Java Basics 0 August 7th, 2009 02:31 AM
function problem in php rapraj PHP How-To 7 December 11th, 2007 05:38 AM
Problem with function mat41 Classic ASP Basics 3 July 16th, 2005 01:19 AM
extract function - Now answered Thank You thegooner BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 3 June 11th, 2004 06:44 AM





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