Database > General Database
regarding mysql_fetch_assoc()
(1/1)
chanu.sl:
I'm new to the PHP and I'm stuck in php code, because of mysql_fetch_assoc(). I used php POST method to retrieve data from html form and it works. But when I use that POST variable inside the mysql query it shows a warning.
here is the code.
--- PHP Code: ---
<?php
$con = mysql_connect("********","********","********");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
echo 'Welcome to village profile!!!';
mysql_select_db("smis", $con);
//$vo=$_REQUEST['vo'];
$vo=$_GET['vo'];
//$vog="$vo";
$district=mysql_query("SELECT district From basicinfo WHERE regname='$vo'");
$piu=mysql_query("SELECT piu From basicinfo WHERE regname='$vo'");
$dsd=mysql_query("SELECT dsd From basicinfo WHERE regname='$vo'");
$gnd=mysql_query("SELECT gnd From basicinfo WHERE regname='$vo'");
$batch=mysql_query("SELECT Batch From basicinfo WHERE regname='$vo'");
$regdate=mysql_query("SELECT reg_date From basic WHERE vo_name='$vo'");
$population=mysql_query("SELECT Population From basicinfo WHERE regname='$vo'");
$hhold=mysql_query("SELECT HH From basicinfo WHERE regname='$vo'");
$poor=mysql_query("SELECT poor From basic WHERE vo_name='$vo'");
$mostv=mysql_query("SELECT most_vul From basic WHERE vo_name='$vo'");
$middle=mysql_query("SELECT middle From basic WHERE vo_name='$vo'");
$rich=mysql_query("SELECT rich From basic WHERE vo_name='$vo'");
$youth=mysql_query("SELECT youth From basic WHERE vo_name='$vo'");
$vdp=mysql_query("SELECT vdp From basicinfo WHERE regname='$vo'");
$cbtotal=mysql_query("SELECT cbtotal From basicinfo WHERE regname='$vo'");
$idftotal=mysql_query("SELECT idftotal From basicinfo WHERE regname='$vo'");
$lsftotal=mysql_query("SELECT lsftotal From basicinfo WHERE regname='$vo'");
$cbf1=mysql_query("SELECT Insti_1 From basicinfo WHERE regname='$vo'");
$cbf2=mysql_query("SELECT Ins_2 From basicinfo WHERE regname='$vo'");
$cbf3=mysql_query("SELECT Ins_3 From basicinfo WHERE regname='$vo'");
$cbttl=mysql_query("SELECT (Insti_1+Ins_2+Ins_3) From basicinfo WHERE regname='$vo'");
$lsf1=mysql_query("SELECT lsf1 From basicinfo WHERE regname='$vo'");
$lsf2=mysql_query("SELECT lsf2 From basicinfo WHERE regname='$vo'");
$lsf3=mysql_query("SELECT lsf3 From basicinfo WHERE regname='$vo'");
$lsfttl=mysql_query("SELECT (lsf1+lsf2+lsf3) From basicinfo WHERE regname='$vo'");
$total=mysql_query("SELECT * From basicinfo,ifra WHERE regname='$vo'
AND basicinfo.Code=ifra.vcode");
$ins1=mysql_query("SELECT SUM(IN1) From basicinfo,ifra WHERE regname='$vo' AND basicinfo.Code=ifra.vcode");
$ins2=mysql_query("SELECT SUM(IN2) From basicinfo,ifra WHERE regname='$vo' AND basicinfo.Code=ifra.vcode");
$ins3=mysql_query("SELECT SUM(IN3) From basicinfo,ifra WHERE regname='$vo' AND basicinfo.Code=ifra.vcode");
$ins4=mysql_query("SELECT SUM(IN4) From basicinfo,ifra WHERE regname='$vo' AND basicinfo.Code=ifra.vcode");
$totdis=mysql_query("SELECT SUM(TOTDIS) From basicinfo,ifra WHERE regname='$vo' AND basicinfo.Code=ifra.vcode");
$totdis1=mysql_query("SELECT SUM(TOTDIS) From basicinfo,ifra WHERE regname='$vo' AND basicinfo.Code=ifra.vcode");
$vdfd=mysql_query("SELECT (cbtotal+SUM(TOTDIS)+lsftotal) From basicinfo,ifra WHERE regname='$vo' AND basicinfo.Code=ifra.vcode");
?>
<p> </p>
<p> </p>
<table width="690" height="506" border="2" align="center" cellspacing="1" bordercolor="#FFFF00" bgcolor="#FFFFFF">
<tr>
<td>
<img src="images/Bannernewmis copy.jpg" width="983" />
<h1 align="center" class="style1">Village Profile</h1>
<table width="985" border="0" cellspacing="1">
<tr>
<td bordercolor="#F0F0F0"> <div align="center" class="style2">General Information of <?php echo $vo;?></div></td>
</tr>
<tr>
<td><table width="982" height="224" border="1" cellspacing="1">
<tr>
<td width="178">District</td>
<td width="8"> <div align="center">:</div></td>
<td width="293"><?php $dst=mysql_fetch_assoc($district); echo $dst['district'];?></td>
<td width="480" rowspan="6" valign="top"><div align="center">Map</div></td>
</tr>
<tr>
<td>Field Operations Unit (HUB)</td>
<td><div align="center">:</div></td>
<td><?php $hub=mysql_fetch_assoc($piu); echo $hub['piu'];?></td>
</tr>
<tr>
<td>Divisional Secretary Division</td>
<td><div align="center">:</div></td>
<td><?php $ds=mysql_fetch_assoc($dsd); echo $ds['dsd'];?></td>
</tr>
<tr>
<td>GN Division</td>
<td><div align="center">:</div></td>
<td><?php $gn=mysql_fetch_assoc($gnd); echo $gn['gnd'];?></td>
</tr>
<tr>
<td>Batch of Implementation</td>
<td><div align="center">:</div></td>
<td><?php $bt=mysql_fetch_assoc($batch); echo $bt['Batch'];?></td>
</tr>
<tr>
<td height="40">Starting Date of Project</td>
<td><div align="center">:</div></td>
<td><?php $rd=mysql_fetch_assoc($regdate); echo $rd['reg_date'];?></td>
</tr>
</table></td>
</tr>
</table>
<p align="left" class="style1 style3">Village Information</p>
<table width="499" border="1" cellspacing="1">
<tr>
<td width="300">Population</td>
<td width="186"><?php $pop=mysql_fetch_assoc($population); echo $pop['Population'];?></td>
</tr>
<tr>
<td>Total No. of Households</td>
<td><?php $hh=mysql_fetch_assoc($hhold); echo $hh['HH'];?></td>
</tr>
<tr>
<td>Unemployment Youth Population</td>
<td> </td>
</tr>
<tr>
<td>Youth Population</td>
<td><?php $yu=mysql_fetch_assoc($youth); echo $yu['youth'];?></td>
</tr>
<tr>
<td>Samurdhi Beneficiaries</td>
<td> </td>
</tr>
<tr>
<td>Total Area (Sq Km)</td>
<td> </td>
</tr>
<tr>
<td>Monthly Average Income</td>
<td> </td>
</tr>
</table>
<p align="left" class="style1 style3 style4">Village Profile</p>
<table border="0" cellpadding="0">
<tr>
<td><p>According to the wealth ranking the households have been classified as follows: (The "Most Vulnerable" are included under "Poor")</p></td>
</tr>
</table>
<table width="400" border="0" cellspacing="1">
<tr>
<td width="286">1.Poor</td>
<td width="107"><?php $pr=mysql_fetch_assoc($poor); echo $pr['poor'];?></td>
</tr>
<tr>
<td>(Most Vulnerable</td>
<td> <?php $mv=mysql_fetch_assoc($mostv); echo $mv['most_vul'];?>)</td>
</tr>
<tr>
<td>2.Middle Income</td>
<td><?php $mdl=mysql_fetch_assoc($middle); echo $mdl['middle'];?></td>
</tr>
<tr>
<td>3.Rich</td>
<td><?php $rc=mysql_fetch_assoc($rich); echo $rc['rich'];?></td>
</tr>
</table>
<p class="style5">Village Development Funds Allocation</p>
<table width="643" border="0" cellspacing="1">
<tr>
<td width="452"> Total Investment of Village Development Plan </td>
<td width="36">Rs:</td>
<td width="145"><?php $vd=mysql_fetch_assoc($vdp); echo $vd['vdp'];?></td>
</tr>
<tr>
<td>The Capacity Building Fund</td>
<td>Rs:</td>
<td><?php $cb=mysql_fetch_assoc($cbtotal); echo $cb['cbtotal'];?></td>
</tr>
<tr>
<td>The Infrastructure Development Fund</td>
<td>Rs:</td>
<td><?php $id=mysql_fetch_assoc($idftotal); echo $id['idftotal'];?></td>
</tr>
<tr>
<td>The Livelihood Support Fund</td>
<td>Rs:</td>
<td><?php $ls=mysql_fetch_assoc($lsftotal); echo $ls['lsftotal'];?></td>
</tr>
</table>
<p class="style5 style6">Village Financial Information</p>
<p class="style5 style4">Fund Disbursement</p>
<table width="721" border="1" cellspacing="1">
<tr bgcolor="#CCCCCC">
<th width="165" scope="col"><div align="left">Fund</div></th>
<th width="116" scope="col"><div align="left">Installment 1 (Rs)</div></th>
<th width="109" scope="col"><div align="left">Installment 2 (Rs)</div></th>
<th width="98" scope="col"><div align="left">Installment 3 (Rs)</div></th>
<th width="100" scope="col"><div align="left">Total (Rs)</div></th>
<th width="114" scope="col"><div align="left">% (Up to now)</div></th>
</tr>
<tr>
<td><div align="left">Capacity Building Fund</div></td>
<td><div align="right">
<?php $cb1=mysql_fetch_assoc($cbf1); echo $cb1['Insti_1'];?>
</div>
</div></td>
<td><div align="right">
<?php $cb2=mysql_fetch_assoc($cbf2); echo $cb2['Ins_2'];?>
</div>
</div></td>
<td><div align="right">
<?php $cb3=mysql_fetch_assoc($cbf3); echo $cb3['Ins_3'];?>
</div></td>
<td><div align="right">
<?php $cbt=mysql_fetch_assoc($cbttl); echo $cbt['(Insti_1+Ins_2+Ins_3)'];?>
</div></td>
<td><div align="right"><?php echo round(($cbt['(Insti_1+Ins_2+Ins_3)']/$cb['cbtotal'])*100,2) ; ?>%</div></td>
</tr>
<tr>
<td><div align="left"> Livelihood Support Fund</div></td>
<td><div align="right">
<?php $ls1=mysql_fetch_assoc($lsf1); echo $ls1['lsf1'];?>
</div>
</div></td>
<td><div align="right">
<?php $ls2=mysql_fetch_assoc($lsf2); echo $ls2['lsf2'];?>
</div>
</div></td>
<td><div align="right">
<?php $ls3=mysql_fetch_assoc($lsf3); echo $ls3['lsf3'];?>
</div></td>
<td><div align="right">
<?php $lst=mysql_fetch_assoc($lsfttl); echo $lst['(lsf1+lsf2+lsf3)'];?>
</div></td>
<td><div align="right"><?php echo round(($lst['(lsf1+lsf2+lsf3)']/$ls['lsftotal'])*100,2) ; ?>%</div></td>
</tr>
</table>
<p class="style5 style4">Community Infrastructure and Social Services Development Fund</p>
<?php
echo "<table border='1'>
<tr>
<th>Project Name</th>
<th><div align='right'>Installment 1 (Rs)</th>
<th><div align='right'>Installment 2 (Rs)</th>
<th><div align='right'>Installment 3 (Rs)</th>
<th><div align='right'>Installment 4 (Rs)</th>
<th><div align='right'>Total (Rs)</th>
</tr>";
while($row = mysql_fetch_array($total))
{
echo "<tr>";
echo "<td>" . $row['PNAME'] . "</td>";
echo "<td>"."<div align='right'>" . $row['IN1'] . "</td>";
echo "<td>"."<div align='right'>" . $row['IN2'] . "</td>";
echo "<td>"."<div align='right'>" . $row['IN3'] . "</td>";
echo "<td>"."<div align='right'>" . $row['IN4'] . "</td>";
echo "<td>"."<div align='right'>" . $row['TOTDIS'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>
<table width="874" border="1" align="left" cellspacing="1">
<tr>
<th width="291" scope="col">Total</th>
<th width="120" scope="col">
<div align="right">
<?php $in1=mysql_fetch_assoc($ins1); echo $in1['SUM(IN1)'];?>
</div></th>
<th width="115" scope="col"> <div align="right">
<?php $in2=mysql_fetch_assoc($ins2); echo $in2['SUM(IN2)'];?>
</div></th>
<th width="123" scope="col"> <div align="right">
<?php $in3=mysql_fetch_assoc($ins3); echo $in3['SUM(IN3)'];?>
</div></th>
<th width="117" scope="col"> <div align="right">
<?php $in4=mysql_fetch_assoc($ins4); echo $in4['SUM(IN4)'];?>
</div></th>
<th width="75" scope="col"> <div align="right">
<?php $tt=mysql_fetch_assoc($totdis); echo $tt['SUM(TOTDIS)'];?>
</div></th>
</tr>
</table>
<p class="style5 style4"> </p>
<table width="677" border="1" cellspacing="1">
<tr>
<td width="288" rowspan="2" bgcolor="#CCCCCC"><span class="style7">Community Infrastructure and Social Services Development Fund Disbursement up to now</span></td>
<td width="180" bgcolor="#CCCCCC"><strong>Total (Rs)</strong></td>
<td width="191" bgcolor="#CCCCCC"><strong>% (Up to now)</strong></td>
</tr>
<tr>
<td><div align="right">
<?php $tt1=mysql_fetch_assoc($totdis1); echo $tt1['SUM(TOTDIS)'];?>
</div></td>
<td><div align="right"><?php echo round(($tt1['SUM(TOTDIS)']/$id['idftotal'])*100,2) ; ?>%</div></td>
</tr>
</table>
<table width="677" height="59" border="1" cellspacing="1">
<tr>
<td width="285" rowspan="2" bgcolor="#CCCCCC"><strong>Total Village Development Fund Disbursement up to now</strong></td>
<td width="181" bgcolor="#CCCCCC"><strong>Total (Rs)</strong></td>
<td width="193" bgcolor="#CCCCCC"><strong>% (Up to now)</strong></td>
</tr>
<tr>
<td><div align="right">
<?php $vfd=mysql_fetch_assoc($vdfd); echo $vfd['(cbtotal+SUM(TOTDIS)+lsftotal)'];?>
</div></td>
<td><div align="right"><?php echo round(($vfd['(cbtotal+SUM(TOTDIS)+lsftotal)']/$vd['vdp'])*100,2) ; ?>%</div></td>
</tr>
</table>
<p> </p>
<p class="style5 style4"> </p>
<p><img src="images/Footer copy.jpg" width="982" height="100" /></p>
<p align="center"> Powered by MIS Team.</p>
<div align="center"></div>
</td>
</tr>
</table>
--- End code ---
and here is the warning.
--- Quote ---Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\MIS\livelihood\village.php on line 108
--- End quote ---
There are several warnings displaying each line I used mysql_fetch_assoc() . Please help me to solve this.
OpzMaster: Please do not include database credentials in your code! Use ***** instead.
wilson382:
hello welcome to the forum,
first of all please don't include you user database username password i recommend you change your password now
the error you getting it means that the query is giving a Boolean value and mysql_fetch_assoc expect an array of associates names from the database and it only being give a boolean 0 or 1.
the error is in the query but i dont see any error so you need the do the following to help fix the error:
--- PHP Code: ---
$hhold=mysql_query("SELECT HH From basicinfo WHERE regname='$vo'") or die(mysql_error();)
--- End code ---
if you use this it will tell you what went wrong.
hope it helps
Navigation
[0] Message Index
Go to full version