suttercain Posted March 31, 2007 Share Posted March 31, 2007 Hi everyone, I have an idea but before I start trying, I was wondering if it is even possible... Right now I am echoing a mysql_num_rows from the $result of the MySQL query. <?php $result = mysql_query( "SELECT * FROM messages" ); $comics = mysql_num_rows( $results ); ?> There are a total of <?php echo $comics ?> comic books in the database! Now, as you know, that just echos out the total comics: There are a total of 4781 comic books in the database! Is it possible to instead of echoing TEXT from $comics, can I echo images? Example Instead of 4781 I break up the numbers so instead of 4 I echo 4.jpg, instead of 7 I echo 7.jpg. That way I can have the result match my header. Does anyone know if this is possible? Would the switch statement work in this case? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/45076-solved-is-this-possible-switch-statement-maybe/ Share on other sites More sharing options...
MadTechie Posted March 31, 2007 Share Posted March 31, 2007 can't echo an image but a path to one ie echo "<img src='1.jpg' />" your also need to break the number into single numbers Quote Link to comment https://forums.phpfreaks.com/topic/45076-solved-is-this-possible-switch-statement-maybe/#findComment-218830 Share on other sites More sharing options...
suttercain Posted March 31, 2007 Author Share Posted March 31, 2007 So would it be something like... <?php switch ($comics) { case 0: echo "<img src='http:www.domain.com/images/00.jpg'"; break; case 1: echo "<img src='http:www.domain.com/images/01.jpg'"; break; case 2: echo "<img src='http:www.domain.com/images/02.jpg'"; break; etc.... } ?> Quote Link to comment https://forums.phpfreaks.com/topic/45076-solved-is-this-possible-switch-statement-maybe/#findComment-218833 Share on other sites More sharing options...
MadTechie Posted March 31, 2007 Share Posted March 31, 2007 suttercain you have " to many error here try this $x = the number and have images 0.jpg to 9.jpg in the same folder. <?php $x = "1234"; for($n=0;$n<strlen($x);$n++) { echo "<img src='".$x{$n}.".jpg' />"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/45076-solved-is-this-possible-switch-statement-maybe/#findComment-218835 Share on other sites More sharing options...
suttercain Posted March 31, 2007 Author Share Posted March 31, 2007 So should the code be: <?php $result = mysql_query( "SELECT * FROM messages" ); $comics = mysql_num_rows( $results ); $x = $comics; for($n=0;$n<strlen($x);$n++) { echo "There are a total of <img src='".$x{$n}.".jpg' /> comics in the database!"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/45076-solved-is-this-possible-switch-statement-maybe/#findComment-218836 Share on other sites More sharing options...
MadTechie Posted March 31, 2007 Share Posted March 31, 2007 Not exactly, try <?php $x = $comics; $numimage = ""; for($n=0;$n<strlen($x);$n++) { $numimage .= "<img src='".$x{$n}.".jpg' />"; } echo "There are a total of $numimage comics in the database!"; ?> thats should work Quote Link to comment https://forums.phpfreaks.com/topic/45076-solved-is-this-possible-switch-statement-maybe/#findComment-218839 Share on other sites More sharing options...
kenrbnsn Posted March 31, 2007 Share Posted March 31, 2007 No, if you do it that way you're going to get multiple lines, each with one image file in them, try this: <?php $x = "$comics"; // this method only works if the variable is a string echo 'There are a total of '; for ($i=0;$i<strlen($x);$i++) echo '<img src="' . $x[$i] . '.jpg" alt="' . $i . '" />'; echo ' comics in the database!'; ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/45076-solved-is-this-possible-switch-statement-maybe/#findComment-218840 Share on other sites More sharing options...
suttercain Posted March 31, 2007 Author Share Posted March 31, 2007 Thanks kenrbnsn!!! That works perfectly! Quote Link to comment https://forums.phpfreaks.com/topic/45076-solved-is-this-possible-switch-statement-maybe/#findComment-218843 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.