My code below don't show me any name and address (only show <d> ) :

<html>
<body>

<H1>Testing</H1>

<table border="1">
<tr bgcolor="Blue">

<th>Name</th>
<th>Address</th>
</tr>

<?php 


$db = array(
    array("Binladen","los anger"),
	array("Harry","NY"),
	array("Ghost","lust caution")
	);


	
/**
 * return string
 * params int $i
 * return 'white' even and 'yellow' for odd numbers
 * */	

function rowColor($i)
{
	$bgcolor1 = "white";
	$bgcolor2 = "yellow";
	
	if (($i%2) == 0)
	{
		return $bgcolor1;
	}else {
		return $bgcolor2;
	}	
}


function show()
{
	global $db;
	
	for($i=0,$n=count($db);$i < $n; $i++) {
		
		$nv = $db[i] ;
		
		$nv_name = $nv[0];
		$nv_ad = $nv[1];
		
		print " <tr bgcolor=\"".rowColor($i)."\">\n";
		print " <td> $nv_name <\td> \n";
		print " <td> $nv_ad <\td> \n";
		print " </tr>\n";		
	}	
}
show();

?>

</table>
</body>
</html>

Recommended Answers

All 3 Replies

I work on Zend Studio

Here,I have edited your code by using a while condition:Enjoy!

<html>
<body>

<H1>Testing</H1>
<table border="1">
<tr bgcolor="Blue">
<th>Name</th>
<th>Address</th>
</tr>


<?php 


$db = array(array("Binladen","los anger"),
	  array("Harry","NY"),
	  array("Ghost","lust caution"));

/**
 * return string
 * params int $i
 * return 'white' even and 'yellow' for odd numbers
 * */	

function rowColor($i)
{
	$bgcolor1 = "white";
	$bgcolor2 = "yellow";
	
	if (($i%2) == 0)
	{
		return $bgcolor1;
	}else {
		return $bgcolor2;
	}	
}


function show()
{
	global $db;
	$num=count($db);
	$i=0;

	while ($i<$num)
	{
		print " <tr bgcolor=\"".rowColor($i)."\">";
		print "<td>";
		print_r($db[$i][0]);
		print "</td>";
		print "<td>";
		print_r($db[$i][1]);
		print "</td>";
		print " </tr>";	
	$i++;	
	}

}
show();	
?>

</table>
</body>
</html>
<html>
<body>

<H1>Testing</H1>

<table border="1">
<tr bgcolor="Blue">

<th>Name</th>
<th>Address</th>
</tr>

<?php 
global $db;

$db = array(
    "Binladen"=> "los anger",
    "Harry"=> "NY",
    "Ghost"=> "lust caution"
    );



/**
 * return string
 * params int $i
 * return 'white' even and 'yellow' for odd numbers
 * */   

function rowColor($i)
{

}

function show($db)
{
    $db;
    $bgcolor1 = "white";
    $bgcolor2 = "yellow";
    foreach($db as $key => $value){
        if (($i%2) == 0)
        {
            echo"<tr bgcolor='$bgcolor2'>";
        }else {
            echo"<tr bgcolor='$bgcolor1'>";
        }
        print " 
         <td> $key</td>
         <td> $value</td>
         </tr>";     
        }
}
show($db);
?>


</table>
</body>
</html>
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.