Hi,
Here I trying to retrieve a data from MYSQL database, but when run the PHP code there have some message like
[text]Notice: Undefined index: startLimit in C:\Program_files\wamp\www\working_with_databases\customers2\list.php on line 8
Notice: Undefined index: rows in C:\Program_files\wamp\www\working_with_databases\customers2\list.php on line 9
Notice: Undefined index: sortBy in C:\Program_files\wamp\www\working_with_databases\customers2\list.php on line 10
Notice: Undefined index: sortOrder in C:\Program_files\wamp\www\working_with_databases\customers2\list.php on line 11
Notice: Undefined variable: orderByQuery in C:\Program_files\wamp\www\working_with_databases\customers2\list.php on line 38
SELECT * FROM customers LIMIT 0,10
Notice: Undefined index: startLimit in C:\Program_files\wamp\www\working_with_databases\customers2\list.php on line 61
[/text](please see the atached JPEG file "20-04-2010-1.jpg)
and the if i press next 10 link the the errors are display as
[text]Notice: Undefined index: rows in C:\Program_files\wamp\www\working_with_databases\customers2\list.php on line 9
Notice: Undefined variable: orderByQuery in C:\Program_files\wamp\www\working_with_databases\customers2\list.php on line 38
SELECT * FROM customers LIMIT 10,10
[/text](please see the attached JPG "20-04-2010-2.jpg")
here this is the PHP code i have
<?php echo $_SERVER['SCRIPT_NAME']."<BR>"; ?>
<?php
include_once("include/db_connection.php");
$initStartLimit = 0;
$limitPerPage = 10;
/LINE8 $startLimit = $_REQUEST['startLimit'];
/LINE9 $numberOfRows = $_REQUEST['rows'];
/LINE10 $sortBy = $_REQUEST['sortBy'];
/LINE11 $sortOrder = $_REQUEST['sortOrder'];
if ($startLimit=="")
{
$startLimit = $initStartLimit;
}
if ($numberOfRows=="")
{
$numberOfRows = $limitPerPage;
}
if ($sortOrder=="")
{
$sortOrder = "DESC";
}
if ($sortOrder == "DESC") { $newSortOrder = "ASC"; } else { $newSortOrder = "DESC"; }
$limitQuery = " LIMIT ".$startLimit.",".$numberOfRows;
$nextStartLimit = $startLimit + $limitPerPage;
$previousStartLimit = $startLimit - $limitPerPage;
if ($sortBy!="")
{
$orderByQuery = " ORDER BY ".$sortBy." ".$sortOrder;
}
/LINE_38 $sql = "SELECT * FROM customers".$orderByQuery.$limitQuery;
echo $sql."<br>";
$result = MYSQL_QUERY($sql);
$numberOfRows = MYSQL_NUM_ROWS($result);
if ($numberOfRows==0) {
?>
Sorry. No records found !!
<?php
}
else if ($numberOfRows>0) {
$i=0;
?>
<br>
<?php
/LINE_61 if ($_REQUEST['startLimit'] != "")
{
?>
<a href="<?php echo $_SERVER['PHP_SELF']; ?>?startLimit=<?php echo $previousStartLimit; ?>&limitPerPage=<?php echo $limitPerPage; ?>&sortBy=<?php echo $sortBy; ?>&sortOrder=<?php echo $sortOrder; ?>">Previous <?php echo $limitPerPage; ?> Results</a>....
<?php } ?>
<?php
if ($numberOfRows == $limitPerPage)
{
?>
<a href="<?php echo $_SERVER['PHP_SELF']; ?>?startLimit=<?php echo $nextStartLimit; ?>&limitPerPage=<?php echo $limitPerPage; ?>&sortBy=<?php echo $sortBy; ?>&sortOrder=<?php echo $sortOrder; ?>">Next <?php echo $limitPerPage; ?> Results</a>
<?php } ?>
<br><br>
<TABLE CELLSPACING="0" CELLPADDING="3" BORDER="0" WIDTH="100%">
<TR>
<TD>
<a href="<?php echo $PHP_SELF; ?>?sortBy=customer_id&sortOrder=<?php echo $newSortOrder; ?>&startLimit=<?php echo $startLimit; ?>&rows=<?php echo $limitPerPage; ?>">
<B>Customer_id</B>
</a>
</TD>
<TD>
<a href="<?php echo $PHP_SELF; ?>?sortBy=fname&sortOrder=<?php echo $newSortOrder; ?>&startLimit=<?php echo $startLimit; ?>&rows=<?php echo $limitPerPage; ?>">
<B>Fname</B>
</a>
</TD>
<TD>
<a href="<?php echo $PHP_SELF; ?>?sortBy=mname&sortOrder=<?php echo $newSortOrder; ?>&startLimit=<?php echo $startLimit; ?>&rows=<?php echo $limitPerPage; ?>">
<B>Mname</B>
</a>
</TD>
<TD>
<a href="<?php echo $PHP_SELF; ?>?sortBy=lname&sortOrder=<?php echo $newSortOrder; ?>&startLimit=<?php echo $startLimit; ?>&rows=<?php echo $limitPerPage; ?>">
<B>Lname</B>
</a>
</TD>
<TD>
<a href="<?php echo $PHP_SELF; ?>?sortBy=company&sortOrder=<?php echo $newSortOrder; ?>&startLimit=<?php echo $startLimit; ?>&rows=<?php echo $limitPerPage; ?>">
<B>Company</B>
</a>
</TD>
<TD>
<a href="<?php echo $PHP_SELF; ?>?sortBy=title&sortOrder=<?php echo $newSortOrder; ?>&startLimit=<?php echo $startLimit; ?>&rows=<?php echo $limitPerPage; ?>">
<B>Title</B>
</a>
</TD>
<TD>
<a href="<?php echo $PHP_SELF; ?>?sortBy=address1&sortOrder=<?php echo $newSortOrder; ?>&startLimit=<?php echo $startLimit; ?>&rows=<?php echo $limitPerPage; ?>">
<B>Address1</B>
</a>
</TD>
<TD>
<a href="<?php echo $PHP_SELF; ?>?sortBy=address2&sortOrder=<?php echo $newSortOrder; ?>&startLimit=<?php echo $startLimit; ?>&rows=<?php echo $limitPerPage; ?>">
<B>Address2</B>
</a>
</TD>
<TD>
<a href="<?php echo $PHP_SELF; ?>?sortBy=address3&sortOrder=<?php echo $newSortOrder; ?>&startLimit=<?php echo $startLimit; ?>&rows=<?php echo $limitPerPage; ?>">
<B>Address3</B>
</a>
</TD>
<TD>
<a href="<?php echo $PHP_SELF; ?>?sortBy=city&sortOrder=<?php echo $newSortOrder; ?>&startLimit=<?php echo $startLimit; ?>&rows=<?php echo $limitPerPage; ?>">
<B>City</B>
</a>
</TD>
<TD>
<a href="<?php echo $PHP_SELF; ?>?sortBy=state_province&sortOrder=<?php echo $newSortOrder; ?>&startLimit=<?php echo $startLimit; ?>&rows=<?php echo $limitPerPage; ?>">
<B>State_province</B>
</a>
</TD>
<TD>
<a href="<?php echo $PHP_SELF; ?>?sortBy=country&sortOrder=<?php echo $newSortOrder; ?>&startLimit=<?php echo $startLimit; ?>&rows=<?php echo $limitPerPage; ?>">
<B>Country</B>
</a>
</TD>
<TD>
<a href="<?php echo $PHP_SELF; ?>?sortBy=postal_code&sortOrder=<?php echo $newSortOrder; ?>&startLimit=<?php echo $startLimit; ?>&rows=<?php echo $limitPerPage; ?>">
<B>Postal_code</B>
</a>
</TD>
<TD>
<a href="<?php echo $PHP_SELF; ?>?sortBy=phone&sortOrder=<?php echo $newSortOrder; ?>&startLimit=<?php echo $startLimit; ?>&rows=<?php echo $limitPerPage; ?>">
<B>Phone</B>
</a>
</TD>
<TD>
<a href="<?php echo $PHP_SELF; ?>?sortBy=fax&sortOrder=<?php echo $newSortOrder; ?>&startLimit=<?php echo $startLimit; ?>&rows=<?php echo $limitPerPage; ?>">
<B>Fax</B>
</a>
</TD>
</TR>
<?php
while ($i<$numberOfRows)
{
if (($i%2)==0) { $bgColor = "#FFFFFF"; } else { $bgColor = "#C0C0C0"; }
$thisCustomer_id = MYSQL_RESULT($result,$i,"customer_id");
$thisFname = MYSQL_RESULT($result,$i,"fname");
$thisMname = MYSQL_RESULT($result,$i,"mname");
$thisLname = MYSQL_RESULT($result,$i,"lname");
$thisCompany = MYSQL_RESULT($result,$i,"company");
$thisTitle = MYSQL_RESULT($result,$i,"title");
$thisAddress1 = MYSQL_RESULT($result,$i,"address1");
$thisAddress2 = MYSQL_RESULT($result,$i,"address2");
$thisAddress3 = MYSQL_RESULT($result,$i,"address3");
$thisCity = MYSQL_RESULT($result,$i,"city");
$thisState_province = MYSQL_RESULT($result,$i,"state_province");
$thisCountry = MYSQL_RESULT($result,$i,"country");
$thisPostal_code = MYSQL_RESULT($result,$i,"postal_code");
$thisPhone = MYSQL_RESULT($result,$i,"phone");
$thisFax = MYSQL_RESULT($result,$i,"fax");
?>
<TR BGCOLOR="<?php echo $bgColor; ?>">
<TD nowrap><?php echo $thisCustomer_id; ?></TD>
<TD nowrap><?php echo $thisFname; ?></TD>
<TD nowrap><?php echo $thisMname; ?></TD>
<TD nowrap><?php echo $thisLname; ?></TD>
<TD nowrap><?php echo $thisCompany; ?></TD>
<TD nowrap><?php echo $thisTitle; ?></TD>
<TD nowrap><?php echo $thisAddress1; ?></TD>
<TD nowrap><?php echo $thisAddress2; ?></TD>
<TD nowrap><?php echo $thisAddress3; ?></TD>
<TD nowrap><?php echo $thisCity; ?></TD>
<TD nowrap><?php echo $thisState_province; ?></TD>
<TD nowrap><?php echo $thisCountry; ?></TD>
<TD nowrap><?php echo $thisPostal_code; ?></TD>
<TD nowrap><?php echo $thisPhone; ?></TD>
<TD nowrap><?php echo $thisFax; ?></TD>
<TD><a href="edit.php?customer_idField=<?php echo $thisCustomer_id; ?>">Edit</a></TD>
<TD><a href="confirm_delete.php?customer_idField=<?php echo $thisCustomer_id; ?>">Delete</a></TD>
</TR>
<?php
$i++;
} // end while loop
?>
</TABLE>
<p> </p>
<table width="550" border="0" cellpadding="2" cellspacing="2" bgcolor="#000000">
<tr>
<td><table width="550" border="0" cellpadding="1" cellspacing="0" bgcolor="#FFFFFF">
<?php
$i = 0;
while ($i<$numberOfRows)
{
if (($i%2)==0) { $bgColor = "#FFFFFF"; } else { $bgColor = "#CCCCCC"; }
$thisCustomer_id = MYSQL_RESULT($result,$i,"customer_id");
$thisFname = MYSQL_RESULT($result,$i,"fname");
$thisMname = MYSQL_RESULT($result,$i,"mname");
$thisLname = MYSQL_RESULT($result,$i,"lname");
$thisCompany = MYSQL_RESULT($result,$i,"company");
$thisTitle = MYSQL_RESULT($result,$i,"title");
$thisAddress1 = MYSQL_RESULT($result,$i,"address1");
$thisAddress2 = MYSQL_RESULT($result,$i,"address2");
$thisAddress3 = MYSQL_RESULT($result,$i,"address3");
$thisCity = MYSQL_RESULT($result,$i,"city");
$thisState_province = MYSQL_RESULT($result,$i,"state_province");
$thisCountry = MYSQL_RESULT($result,$i,"country");
$thisPostal_code = MYSQL_RESULT($result,$i,"postal_code");
$thisPhone = MYSQL_RESULT($result,$i,"phone");
$thisFax = MYSQL_RESULT($result,$i,"fax");
?>
<tr>
<td width="12" bgcolor="<?php echo $bgColor ?>"> </td>
<td width="399" bgcolor="<?php echo $bgColor ?>"><span style="font-weight: bold; font-size: 15px;"><?php echo $thisCustomer_id; ?> -</span> <span style="color: #000099; font-weight: bold;"><?php echo $thisFname." ".$thisMname." ".$thisLname; ?> (<?php echo $thisTitle; ?>)<br>
<span style="color: #000099; font-weight: bold;"><?php echo $thisCompany; ?></span></span><br>
<?php echo $thisAddress1; ?> <?php echo $thisAddress2; ?> <?php echo $thisAddress3; ?> <br>
<?php echo $thisCity; ?>, <?php echo $thisState_province; ?><br>
<?php echo $thisCountry; ?> <?php echo $thisPostal_code; ?><br>
Phone: <?php echo $thisPhone; ?> Fax: <?php echo $thisFax; ?><br></td>
<td width="111" valign="top" bgcolor="<?php echo $bgColor ?>"><a href="edit.php?customer_idField=<?php echo $thisCustomer_id; ?>"><br>
Edit</a><br>
<a href="confirm_delete.php?customer_idField=<?php echo $thisCustomer_id; ?>">Delete</a></td>
</tr>
<?php
$i++;
} // end while loop
?>
</table></td>
</tr>
</table>
<p> <?php
if ($_REQUEST['startLimit'] != "")
{
?>
<a href="<?php echo $_SERVER['PHP_SELF']; ?>?startLimit=<?php echo $previousStartLimit; ?>&limitPerPage=<?php echo $limitPerPage; ?>&sortBy=<?php echo $sortBy; ?>&sortOrder=<?php echo $sortOrder; ?>">Previous <?php echo $limitPerPage; ?> Results</a>....
<?php } ?>
<?php
if ($numberOfRows == $limitPerPage)
{
?>
<a href="<?php echo $_SERVER['PHP_SELF']; ?>?startLimit=<?php echo $nextStartLimit; ?>&limitPerPage=<?php echo $limitPerPage; ?>&sortBy=<?php echo $sortBy; ?>&sortOrder=<?php echo $sortOrder; ?>">Next <?php echo $limitPerPage; ?> Results</a>
<?php } ?>
<br>
<br>
<?php
} // end of if numberOfRows > 0
?>
</p>
<ul>
<li>
<div align="left"><a href="enter_new.php">Enter New customers</a></div>
</li>
<li>
<div align="left"><a href="list.php">List All customers</a></div>
</li>
<li>
<div align="left"><a href="search_form.php">Power Search customers</a></div>
</li>
</ul>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p></p>
Please help me to find out what is the wrong/error.
Thank you
Data retriving problem
Moderator: General Moderators
Data retriving problem
- Attachments
-
- 20-04-2010-2.JPG (55.65 KiB) Viewed 72 times
-
- 20-04-2010-1.JPG (102.63 KiB) Viewed 72 times
Re: Data retriving problem
Your first problem, you did not read Posting Code in the Forums
Second problem, your checking to see if values exist AFTER you have set them.
Should be something like:
Second problem, your checking to see if values exist AFTER you have set them.
Code: Select all
$startLimit = $_REQUEST['startLimit'];
if ($startLimit==""){
$startLimit = $initStartLimit;
}
Code: Select all
isset($_REQUEST['startLimit']) ? $startLimit = $_REQUEST['startLimit'] : $startLimit = 0;