Jump to content

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given


.chester

Recommended Posts

It's one of those questions again.

 

I'm getting Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given on line 12, the one with the while() statement:

 

$sqlTranzactii="select id_tranzactie, DATE_FORMAT(data_tranzactie,'%d-%m-%y') as data_tranzactie, nume_cumparator, adresa_cumparator from tranzactii where comanda_onorata=0";
$resursaTranzactii=mysql_query($sqlTranzactii);
while($rowTranzactie=mysql_fetch_array($resursaTranzactii))
form action="prelucrare_comenzi.php" method="post">
	Data comenzii:
	 <b><?php echo $rowTranzactie['data_tranzactie']?></b>
	 <div style="width:500px; border:1px solid #ffffff; background-color:#c0c0c0; padding:5px">
	 	<b><?php echo $rowTranzactie['nume_cumparator']?></b><br>
	 	<?php echo $rowTranzactie['adresa_cumparator']?>

 

I tried googling the issue, but I haven't found anything exactly like my problem. I'm sure it's something trivial that I'm missing, though. Any ideas?  :-[

Link to comment
Share on other sites

I've tried adding mysql_error() as explained by some other forumites, the page stays exactly the same, with the same error on line 12 (even though line 12 isn't even relevant anymore, as it contains the mysql_error() code).

 

I've tried running the query directly in the mysql window, it works perfectly and returns what it should. I'm stumped. :(

Link to comment
Share on other sites

UPDATE:

 

<?php
include("autorizare.php");
include("admin_top.php");
mysql_connect("localhost", "root", "");
mysql_select_db("anticariat");
?>
<h1>Comenzi</h1>
<b>Comenzi inca neonorate</b><br>
<?php
/* afisam lista comenzilor neonorate*/
$sqlTranzactii="select id_tranzactie, data_tranzactie, nume_cumparator, adresa_cumparator from tranzactii where comanda_onorata=0";
$resursaTranzactii=mysql_query($sqlTranzactii) or die(mysql_error());
print mysql_error();
while($rowTranzactie=mysql_fetch_array($resursaTranzactii))
print_r($sqlTranzactii);
print_r($resursaTranzactii);
{
?>
<form action="prelucrare_comenzi.php" method="post">
	Data comenzii:
	 <b><?php echo $rowTranzactie['data_tranzactie']?></b>
	 <div style="width:500px; border:1px solid #ffffff; background-color:#c0c0c0; padding:5px">
	 	<b><?php echo $rowTranzactie['nume_cumparator']?></b><br>
	 	<?php echo $rowTranzactie['adresa_cumparator']?>
	 	<table border="1" cellpadding="4" cellspacing="0">
	 		<tr>
	 			<td align="center"><b>Carte</b></td>
	 			<td align="center"><b>Nr. Buc</b></td>
	 			<td align="center"><b>Pret</b></td>
	 			<td align="center"><b>Total</b></td>
	 		</tr>
	 		<?php
	 		$sqlCarti="select titlu, nume_autor, pret, nr_buc from vanzari, carti, autori where carti.id_carte=vanzari.id_carte and carti.id_autor=autori.id_autor and id_tranzactie=".$rowTranzactie['id_tranzactie'];
			$resursaCarti=mysql_query($sqlCarti);
			while($rowCarte=mysql_fetch_array($resursaCarti))
			{
				print '<tr><td>'.$rowCarte['titlu'].' de '.$rowCarte['nume_autor'].'</td> <td align="right">'.$rowCarte['nr_buc'].'</td> <td align="right">'.$rowCarte['pret'].' </td>';
				$total=$rowCarte['pret'] * $rowCarte['nr_buc'];
				print '<td align="right">'.$total.'</td></tr>';
				$totalGeneral=$totalGeneral+$total;
			}
			?>
			<tr>
				<td colspan="3" align="right">Total comanda:</td><td><?php echo $totalGeneral?> lei</td>
			</tr>
	 	</table>
	 	<input type="hidden" name="id_tranzactie" value="<?php echo $rowTranzactie['id_tranzactie']?>">
	 	<input type="submit" name="comanda_onorata" value="Comanda onorata!">
	 	<input type="submit" name="anuleaza_comanda" value="Anuleaza comanda">
	 </div>
</form>
<?php
}
?>
</body>
</html>

 

I worked on it some more and there's a wee bit of progress. At least the table is showing now. I also added print_r() to $sqlTranzactii and $resursaTranzactii. The result:

 

28v8zyh.png

 

I don't know what to make of what print_r() is displaying. Is there no data being extracted from the database?

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.