Jump to content

error with code plz help


Ameslee

Recommended Posts

<?php
			$hostname = localhost;
			$username = ;
			$password = ;


			$conn = mysql_connect($hostname, $username, $password) or die(mysql_error());
			$connection = mysql_select_db("greenac_VORNExpo", $conn);


			$query = "SELECT * FROM news";
			$mysql_result=mysql_query($query,$conn);
			$nothingInDatabase= true;
			$i=1;
			while($row = mysql_fetch_array($mysql_result) && ($i<=2)){
			if ($nothingInDatabase) $nothingInDatabase = false;
			$row[1] = wordwrap($row[1], 80, '<br />', true);

			echo("<table width=100%>");
			echo "<tr>";
			echo "<td>$row[1]</td></tr>";
			echo "<hr>";
			$i++;
			}
			if ($nothingInDatabase == true) {
				echo "Please check back later for entries";
				}
			?>

 

can anyone work out why i am getting this error: Warning: Cannot use a scalar value as an array in /home/greenac/public_html/events.php on line 255

 

hope someone can help, thanks.

Link to comment
https://forums.phpfreaks.com/topic/38114-error-with-code-plz-help/
Share on other sites

Hi Ameslee

 

This error means that you are using a variable as an array which actually is not an array. which leads me to believe that $row isnt being set properly

 

try this

 

while(($row = mysql_fetch_array($mysql_result)) && ($i<=2)){

 

just added a couple more braces to definatley separate out the two condition sin the while statement

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.