regarding mysql_fetch_assoc()

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]

<?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"); ?>

 

 

Village Profile

General Information of <?php echo $vo;?>
District
:
<?php $dst=mysql_fetch_assoc($district); echo $dst['district'];?>
Map
Field Operations Unit (HUB)
:
<?php $hub=mysql_fetch_assoc($piu); echo $hub['piu'];?>
Divisional Secretary Division
:
<?php $ds=mysql_fetch_assoc($dsd); echo $ds['dsd'];?>
GN Division
:
<?php $gn=mysql_fetch_assoc($gnd); echo $gn['gnd'];?>
Batch of Implementation
:
<?php $bt=mysql_fetch_assoc($batch); echo $bt['Batch'];?>
Starting Date of Project
:
<?php $rd=mysql_fetch_assoc($regdate); echo $rd['reg_date'];?>

Village Information

Population <?php $pop=mysql_fetch_assoc($population); echo $pop['Population'];?>
Total No. of Households <?php $hh=mysql_fetch_assoc($hhold); echo $hh['HH'];?>
Unemployment Youth Population  
Youth Population <?php $yu=mysql_fetch_assoc($youth); echo $yu['youth'];?>
Samurdhi Beneficiaries  
Total Area (Sq Km)  
Monthly Average Income  

Village Profile

According to the wealth ranking the households have been classified as follows: (The "Most Vulnerable" are included under "Poor")

1.Poor <?php $pr=mysql_fetch_assoc($poor); echo $pr['poor'];?>
(Most Vulnerable <?php $mv=mysql_fetch_assoc($mostv); echo $mv['most_vul'];?>)
2.Middle Income <?php $mdl=mysql_fetch_assoc($middle); echo $mdl['middle'];?>
3.Rich <?php $rc=mysql_fetch_assoc($rich); echo $rc['rich'];?>

Village Development Funds Allocation

Total Investment of Village Development Plan Rs: <?php $vd=mysql_fetch_assoc($vdp); echo $vd['vdp'];?>
The Capacity Building Fund Rs: <?php $cb=mysql_fetch_assoc($cbtotal); echo $cb['cbtotal'];?>
The Infrastructure Development Fund Rs: <?php $id=mysql_fetch_assoc($idftotal); echo $id['idftotal'];?>
The Livelihood Support Fund Rs: <?php $ls=mysql_fetch_assoc($lsftotal); echo $ls['lsftotal'];?>

Village Financial Information

Fund Disbursement

Fund
Installment 1 (Rs)
Installment 2 (Rs)
Installment 3 (Rs)
Total (Rs)
% (Up to now)
Capacity Building Fund
<?php $cb1=mysql_fetch_assoc($cbf1); echo $cb1['Insti_1'];?>
<?php $cb2=mysql_fetch_assoc($cbf2); echo $cb2['Ins_2'];?>
<?php $cb3=mysql_fetch_assoc($cbf3); echo $cb3['Ins_3'];?>
<?php $cbt=mysql_fetch_assoc($cbttl); echo $cbt['(Insti_1+Ins_2+Ins_3)'];?>
<?php echo round(($cbt['(Insti_1+Ins_2+Ins_3)']/$cb['cbtotal'])*100,2) ; ?>%
Livelihood Support Fund
<?php $ls1=mysql_fetch_assoc($lsf1); echo $ls1['lsf1'];?>
<?php $ls2=mysql_fetch_assoc($lsf2); echo $ls2['lsf2'];?>
<?php $ls3=mysql_fetch_assoc($lsf3); echo $ls3['lsf3'];?>
<?php $lst=mysql_fetch_assoc($lsfttl); echo $lst['(lsf1+lsf2+lsf3)'];?>
<?php echo round(($lst['(lsf1+lsf2+lsf3)']/$ls['lsftotal'])*100,2) ; ?>%

Community Infrastructure and Social Services Development Fund

<?php echo "";

while($row = mysql_fetch_array($total))
{
echo “

”;
echo “”;
echo “”;
echo “”;
echo “”;
echo “”;
echo “”;
echo “”;
}
echo “
Project Name
Installment 1 (Rs)
Installment 2 (Rs)
Installment 3 (Rs)
Installment 4 (Rs)
Total (Rs)
” . $row[‘PNAME’] . “”."
" . $row[‘IN1’] . “
”."
" . $row[‘IN2’] . “
”."
" . $row[‘IN3’] . “
”."
" . $row[‘IN4’] . “
”."
" . $row[‘TOTDIS’] . “
”;

mysql_close($con);
?>

Total
<?php $in1=mysql_fetch_assoc($ins1); echo $in1['SUM(IN1)'];?>
<?php $in2=mysql_fetch_assoc($ins2); echo $in2['SUM(IN2)'];?>
<?php $in3=mysql_fetch_assoc($ins3); echo $in3['SUM(IN3)'];?>
<?php $in4=mysql_fetch_assoc($ins4); echo $in4['SUM(IN4)'];?>
<?php $tt=mysql_fetch_assoc($totdis); echo $tt['SUM(TOTDIS)'];?>
<p class="style5 style4">&nbsp;</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>%&nbsp;(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>%&nbsp;(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>&nbsp;</p>
<p class="style5 style4">&nbsp;</p>
<p><img src="images/Footer copy.jpg" width="982" height="100" /></p>

Powered by MIS Team.

[/php]

and here is the warning.

Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\MIS\livelihood\village.php on line 108

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.

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]
$hhold=mysql_query(“SELECT HH From basicinfo WHERE regname=’$vo’”) or die(mysql_error():wink:
[/php]

if you use this it will tell you what went wrong.

hope it helps

Sponsor our Newsletter | Privacy Policy | Terms of Service