Jump to content

A weird while loop problem !


etdsbastar

Recommended Posts

Hello there,

 

I am making a function to execute every time with a new demand no. in the while loop below. Every thing goes fine for the first time when the page loads, all the taxes come perfectly and each record is being read with the function calculateTaxes($demandno). But, when I press the search button with blank entries... All the entries come with only the first record. Means, the calculateTaxes function is not being loaded again and again with the loop when the press the search button.

 

Please help.

 

Please have a look in the below given code:

 

<?php
function renderform($wardno, $demandno, $name)
{
	include_once $_SERVER['DOCUMENT_ROOT'].'/npms/header.php';
	include_once $_SERVER['DOCUMENT_ROOT'].'/npms/config/config.php';
	include_once $_SERVER['DOCUMENT_ROOT'].'/npms/functions/functions.php';
	include_once $_SERVER['DOCUMENT_ROOT'].'/npms/functions/connect-db.php';
	extract($GLOBALS);

	if ($demandno == '' && $wardno == '' && $name == '') // all empty.
	{
		$result = mysql_query("SELECT * FROM sform where paid=false order by wardno, id, demandno limit 0,$maxrecords") or die(mysql_error());
	}
	if ($demandno != '' && $wardno != '' && $name != '') // all full.
	{
		$result = mysql_query("SELECT * FROM sform where demandno='$demandno' and wardno='$wardno' and (name like '%$name%') and paid=false order by wardno, id, demandno") or die(mysql_error());
	}
	if ($demandno != '' && $wardno == '' && $name == '') // demand full else empty.
	{
		$result = mysql_query("SELECT * FROM sform where demandno='$demandno' and paid=false order by wardno, id, demandno") or die(mysql_error());
	}
	if ($demandno != '' && $wardno != '' && $name == '') // demand and ward full else empty.
	{
		$result = mysql_query("SELECT * FROM sform where demandno='$demandno' and wardno='$wardno' and paid=false order by wardno, id, demandno") or die(mysql_error());
	}
	if ($demandno == '' && $wardno != '' && $name == '') // ward full else empty.
	{
		$result = mysql_query("SELECT * FROM sform where wardno='$wardno' and paid=false order by wardno, id, demandno") or die(mysql_error());
	}
	if ($demandno == '' && $wardno != '' && $name != '') // ward and name full else empty.
	{
		$result = mysql_query("SELECT * FROM sform where wardno='$wardno' and (name like '%$name%') and paid=false order by wardno, id, demandno") or die(mysql_error());
	}
	if ($demandno == '' && $wardno == '' && $name != '') // name full else empty.
	{
		$result = mysql_query("SELECT * FROM sform where (name like '%$name%') and paid=false order by wardno, id, demandno") or die(mysql_error());
	}
	if ($demandno != '' && $wardno == '' && $name != '') // demand and name full else empty.
	{
		$result = mysql_query("SELECT * FROM sform where demandno='$demandno' and (name like '%$name%') and paid=false order by wardno, id, demandno") or die(mysql_error());
	}

	usleep(200000);			// wait for 2 seconds
?>
<link rel=stylesheet HREF="/npms/css/sp.css" type="text/css" media="screen">
<div id="content">
	<div id="labelopt"></div>
	<h2>okMZokj ukxfjdksa dh lwph</h2>
	<div id="list">
	<form name="spsearchform" action="" method="post">
		<table border="1" cellpadding="2px">
			<tr>
				<td id="labelmust" width="10%">fM- dz- %</td>
				<td><input class="english" type="text" size="15%" name="demandno" maxlength="40" value="<?php echo $demandno; ?>" /></td>
				<td id="labelmust" width="10%">okMZ dz- %</td>
				<td><input class="english" size="20%" type="text" size="15%" name="wardno" maxlength="3" value="<?php echo $wardno; ?>"/></td>
				<td id="labelmust" width="10%">uke %</td>
				<td><input class="hindi" size="30%" type="text" name="name" maxlength="100" value="<?php echo $name; ?>"/></td>
				<td><input type="submit" value="Search" name="btnsearch" /></td>
			</tr>
		</table>
	</form>
	<div style="color: red;"><small><cite>List is limited to <? echo $maxrecords; ?> records. For precise searching, use the search options above.</small></cite></div>

	<table border="1" cellpadding="2px">
		<tr>
			<td colspan="8" id="english"><div style="float: right; color: red; text-align: right; margin-right: 10px;"><small><cite><strong><? echo mysql_num_rows($result); ?> records</strong> dumped.</cite></small></div></td>
		</tr>

		<tr>
			<td id="labelcenter">okMZ dz-</td>
			<td id="labelcenter">fMeka.M dzekad</td>
			<td id="labelcenter">uke</td>
			<td id="labelcenter">irk</td>
			<td id="labelcenter">'kq} dj</td>
			<td id="labelcenter">dj fooj.k</td>
			<td id="labelcenter">fu;kstu</td>
			<td id="labelcenter">feVk;sa</td>
		</tr>

		<?php
			if (mysql_num_rows($result) > 0) {
				while($row = mysql_fetch_array( $result ))
				{
					echo "<tr>";
					echo "<td id='english'><center>" . $row['wardno'] . "</center></td>";
					echo "<td id='english'><center>" . $row['demandno'] . "</center></td>";
					echo "<td id='hindi'>" . $row['name'] . "</td>";
					echo "<td id='hindi'>" . $row['address'] . "</td>";
					$taxes = calculateTaxes($row['demandno']);
					echo "<td id='english' align='right'>" . number_format($taxes['grosstax'],2) . "</td>";
	                echo '<td><center><a href="payments/taxreport.php?demandno=' . $row['demandno'] . '"><img src="../images/payment.jpeg" width="15" height="15" /></center></a></td>';
					echo '<td><center><a href="spedit.php?demandno=' . $row['demandno'] . '"><img src="../images/edit.gif" width="15" height="15" /></center></a></td>';
					echo '<td><center><a href="spdelete.php?demandno=' . $row['demandno'] . '"><img src="../images/delete.jpeg" width="15" height="15" /></center></a></td>';
				}
			}
			else
			{
				echo "<tr>";
				echo "<td colspan='7' align='center'><blink><strong>lwph miyC/k ugha gS A</strong></blink></td>";
				echo "</tr>";
			}
		?>
		</tr>
	</table>
	</div>
	<div id="menu">
	<table>
		<tr>
			<td>
				<input type="button" value="New" name="btnnew" onclick="location.href='spnew.php';" />
				<input type="button" value="Back" name="btnspback" onclick="location.href='../sp.php';" />
			</td>
		</tr>
	</table>
	</div>
</div>

<?php include_once $_SERVER['DOCUMENT_ROOT'].'/npms/footer.php';
}
include_once $_SERVER['DOCUMENT_ROOT'].'/npms/functions/connect-db.php';
include_once $_SERVER['DOCUMENT_ROOT'].'/npms/functions/functions.php';
if(isset($_POST['btnsearch']))
{
	$wardno = mysql_real_escape_string(htmlspecialchars($_POST['wardno']));
	$name = mysql_real_escape_string(htmlspecialchars($_POST['name']));
	$demandno = mysql_real_escape_string(htmlspecialchars($_POST['demandno']));

	renderform($demandno, $wardno, $name);
}
else
{
	renderform('', '', '');
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.