Chezshire Posted July 30, 2009 Share Posted July 30, 2009 Hello - I'm currently taking classes in PHP (finally and loving it!) Currently I'm having the following error trying to do a 'paging class' for a project The error is as follows: Error in file: '/home/classes/jstein11/public_html/x280/x5c.foto_list.php' on line: 30 Error message: Undefined variable: myPager Line #30: print '<div align="center">We have a total of ' . $myPager->showTotal() . ' muffins!</div>'; Here is the code: <?php define('HIDE_PAGE_ERRORS', FALSE); # FALSE = CURRENTLY ENABLING VISIBILITY OF PAGE ERRORS $PageTitle = 'Gotta Whole Lot of Photographs by Shauntee Willis!'; # SQL statement $selSQL = "select FotoName, FotoID, Price from tblFotos"; //END CONFIG AREA ---------------------------------------------------------- require_once '/home/classes/jstein11/inc_itc280/config_inc.php'; require_once 'include/header_inc.php'; ?> <h3 align="center">x5c.Foto_list.php</a></h3> <p align="center"> <img height="100px" "src="images/x5_foto.jpg" /><br /><br />This <a href="x5c.foto_list.php">'List'</a>, along with the subsequent <a href="x5c.foto_view.php">'View'</a> pages,<br /> demonstrate a List/View relationship in a <br />web-ication/environment!</p> <p align="center">This is version 2.0 of x5b_list.php, now called 'x5c_list.php', which incorporates the <em>Pager class</em> to span records over multiple web pages.</p> <?php # create connection to MySQL $myConn = conn(); # $myData stores data object in memory $result = mysql_query($selSQL,$myConn) or die(trigger_error(mysql_error(), E_USER_ERROR)); if (mysql_num_rows($result) > 0)//at least one record! {//show results print '<div align="center">We have a total of ' . $myPager->showTotal() . ' muffins!</div>'; while ($row = mysql_fetch_assoc($result)) { // Changed 'Foto_view.php' to 'x5c.Foto_view.php' to fit my NAV paradyne/convention - i hope thats ok Bill echo '<div align="center"><a href="x5c.foto_view.php?id=' . dbOut($row['FotoID']) . '">' . dbOut($row['FotoName']) . '</a>'; echo ' <i>only</i> <font color="red">$' . dbOut($row['Price']) . '</font></div>'; } print $myPager->showNav(); }else{//no records print "<div align=center>What! No Photos? There must be a mistake!!</div>"; } @mysql_free_result($result); # clears resources @mysql_close($myConn); # close db connection //Check with Bill - had to change line's path // require_once INCLUDE_PATH . 'footer_inc.php'; require_once 'include/footer_inc.php'; ?> [code] Any help would be greatly appreciated! Thank you!! Link to comment https://forums.phpfreaks.com/topic/168166-solved-help-undefined-variable-mypager-newb-here/ Share on other sites More sharing options...
TeNDoLLA Posted July 30, 2009 Share Posted July 30, 2009 You have not created an instance of your pager anywhere in. You have to create the pager object first before you can use it. <?php $myPager = new Pager(); Link to comment https://forums.phpfreaks.com/topic/168166-solved-help-undefined-variable-mypager-newb-here/#findComment-886940 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.