Hello, Im trying to show my images with a limit of 2 but the while loop show the codes correctly in the source on the browser but the items are not showing on the web page..

How can i fix this issues...

HERE is the codes

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Sayfalama</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>

<body>  

<?php     
     $host = "localhost";
     $data = "lgmsevze_sunbrite";
     $pass = "";
     $user = "root";
     
      $db = mysql_connect ($host, $user, $pass);
      mysql_select_db($data, $db);
      
      $query = "SELECT * FROM lgmsevze_sunbrite.webtemps LIMIT 0, 2";
      $sql = mysql_query($query);
      
      ?>
      
      <ul>
   <?php
     
      while ($item = mysql_fetch_array($sql))
      {
        echo "<li><img src='localhost/sbd/".$item['image']."'></li>";
      }
      

?>    </ul>

</body>
</html>

mysql_fetch_array() returns an array with indexes, not field names.

You can pass the optional paramater MYSQL_ASSOC like so, mysql_fetch_array($result, MYSQL_ASSOC)

or you may use mysql_fetch_assoc() and that will return the array with field names.

Hope it helps.

Actually, mysql_fetch_array can return a result row as an associative array, a numeric array, or both! http://php.net/manual/en/function.mysql-fetch-array.php
Although I usually use mysql_fetch_assoc() as it's easier to determine the result resource.

Are you receiving any errors?

Instead of this:

$query = "SELECT * FROM lgmsevze_sunbrite.webtemps LIMIT 0, 2";
      $sql = mysql_query($query);

Do this:

$query = mysql_query("SELECT * FROM lgmsevze_sunbrite.webtemps LIMIT 0,2") or die(mysql_error());
?>
 
      <ul>
   <?php
 
      while ($item = mysql_fetch_array($query))
      {
        echo "<li><img src='localhost/sbd/".$item['image']."'></li>";
      }

And tell us if you get an error

Ok thank, I got it working the only issue was I need to (CODE IS BELOW)

I had to make it be html instead of echo php.

<ul>
	<?php
		while($item = mysql_fetch_array($result))
		{
	?>
		<li><img src="<?php echo $item['image']; ?>"</li>
	<?php
		}
	?>
	
</ul>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.