Hello guys,

So I wrote this code that fetch data from mysql table:

while($row = mysql_fetch_array($result))
{
$src = '';
switch( $row['speed'] ) {
case 'fast':
$src = 'fast.png';
break;
case 'slow':
$src = 'slow.png';
break;
default:
$src = 'default.jpg';}

}
}

echo "<tr>";
echo "<td><a href='http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF'])."/hits.php?id=".$row['id'] . "'>".$row['proxy']."</a></td>";
echo "<td>" . $row['hits'] . "</td>";
echo "<td>" . $row['age'] . "</td>";
echo "<td>" . $row['country'] . "</td>";
echo "<td><img src=\"". $src."\" /></td>";
echo "</tr>";
}
echo "</table>";

Now I need to add one more column called "icons" and i don't know how to implement it inside of that WHILE loop.

It should be something like:

while($row = mysql_fetch_array($result))
{
$src = '';
switch( $row['speed'] ) {
case 'fast':
$src = 'fast.png';
break;
case 'slow':
$src = 'slow.png';
break;
default:
$src = 'default.jpg';}
{
$ico = '';
switch( $row['icon'] ) {
case 'icon1':
$ico = 'icon1.png';
break;
case 'icon2':
$ico = 'icon2.png';
break;
default:
$ico = 'icondefault.jpg';}

}
}

echo "<tr>";
echo "<td><a href='http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF'])."/hits.php?id=".$row['id'] . "'>".$row['proxy']."</a></td>";
echo "<td>" . $row['hits'] . "</td>";
echo "<td>" . $row['age'] . "</td>";
echo "<td>" . $row['country'] . "</td>";
echo "<td><img src=\"". $src."\" /></td>";
echo "<td><img src=\"". $ico."\" /></td>";
echo "</tr>";
}
echo "</table>";

So , variable $src does work but variable $ico doesn't work and Im not even sure if is possible to use that $ico variable but i hope you can help me.
I hope you can help me and sorry for huge code but that's simplest way I could explain my problem

Thanks in advance!

I think on second verision of your code line no 13,25,26 is having un wanted paranthesis. Your effort is in right direction, but I think you need to do proper code indentation as I did below

while($row = mysql_fetch_array($result))
{
	$src = '';
	switch( $row['speed'] ) 
	{
		case 'fast':
			$src = 'fast.png';
			break;
		case 'slow':
			$src = 'slow.png';
			break;
		default:
			$src = 'default.jpg';
	}
	
	
	$ico = '';
	switch( $row['icon'] ) 
	{
		case 'icon1':
			$ico = 'icon1.png';
			break;
		case 'icon2':
			$ico = 'icon2.png';
			break;
		default:
			$ico = 'icondefault.jpg';
	}
	



	echo "<tr>";
	echo "<td><a href='http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF'])."/hits.php?id=".$row['id'] . "'>".$row['proxy']."</a></td>";
	echo "<td>" . $row['hits'] . "</td>";
	echo "<td>" . $row['age'] . "</td>";
	echo "<td>" . $row['country'] . "</td>";
	echo "<td><img src=\"". $src."\" /></td>";
	echo "<td><img src=\"". $ico."\" /></td>";
	echo "</tr>";
}
echo "</table>";


?>

Also You may write mysql case statment in your query, so that you need not to use switch statment for displaying dynamic images.

Wohoo :D

You made my day man, thanks a lot <3

May God bless your family!

commented: correcting mistaken neg rep given in another thread - sorry about that! +12

Dear arsenalfun, MARK IT SOLVED, so that others do not trouble them.

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.