0

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!

Edited by arsenalfun: n/a

2
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by urtrivedi
0

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.

Edited by urtrivedi: n/a

1

Wohoo :D

You made my day man, thanks a lot <3

May God bless your family!

Votes + Comments
correcting mistaken neg rep given in another thread - sorry about that!
0

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

Edited by urtrivedi: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.