Problem in Listing/view the all data

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dhammikai
Forum Newbie
Posts: 11
Joined: Thu Mar 25, 2010 4:53 am

Problem in Listing/view the all data

Post by dhammikai »

Hi,
Here I followed a tutorial of list the all data that entered into the MYSQL database. But when running the code the following error msg is displayed

"Parse error: parse error in C:\Program_files\wamp\www\working_with_databases\customers\list.php on line 268"

The code as follows

Code: Select all

<?php  echo $_SERVER['SCRIPT_NAME']."<BR>"; ?>
<?php
include_once("include/db_connection.php");

$initStartLimit = 0;
$limitPerPage = 10;

$startLimit = $_REQUEST['startLimit'];
$numberOfRows = $_REQUEST['rows'];
$sortBy = $_REQUEST['sortBy'];
$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;
}


$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>
<?
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>&nbsp;</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 ?>">&nbsp;</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>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p></p>
Someone plase help me for view all the data in MySql database.

Thank you very much.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Problem in Listing/view the all data

Post by requinix »

I don't know where line 268 is, and there's no way I'm going to count the lines myself.

Post the code within 10 lines of that location, and clearly mark which line is #268.
dhammikai
Forum Newbie
Posts: 11
Joined: Thu Mar 25, 2010 4:53 am

Re: Problem in Listing/view the all data

Post by dhammikai »

Hi,
Here I attached the line 268 with JPEG file, any way following the code includes the line 268 (with bold letter )

Code: Select all

</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
[b]} // end of if numberOfRows > 0 [/b]
 ?>
</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>
Attachments
JPEG file with line 268
JPEG file with line 268
php268.JPG (59.74 KiB) Viewed 331 times
eskio
Forum Commoner
Posts: 66
Joined: Tue Apr 01, 2008 1:00 am

Re: Problem in Listing/view the all data

Post by eskio »

Hi,
According to your code the" }" at line 268 is extra. Remove it.
dhammikai
Forum Newbie
Posts: 11
Joined: Thu Mar 25, 2010 4:53 am

Re: Problem in Listing/view the all data

Post by dhammikai »

Hi eskio,
Thanks for the reply and help. Nowmy coding is working, but some of errors are again display. (the display fies are attached herewith). This view of data can have page by page each page have 10 records and then it continues with next page. In first page display following errors

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


And then press the next page tab the following mesgs are view

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

after the above mesgs the records are viewd. Please help me to solve the above errors. Thanks
Attachments
Code
Code
phplist-3.JPG (56.06 KiB) Viewed 322 times
Page 02
Page 02
phplist-2.JPG (68.65 KiB) Viewed 326 times
Page 01 and 02
Page 01 and 02
phplist-1.JPG (84.15 KiB) Viewed 326 times
Post Reply