Jump to content

Recommended Posts

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.

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....
}
?>

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!";
}
?>

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.