0
votes

I'm trying to do something different where i need to know if it is possible to work on. I have 2 mysql tables inside a database.

One has random numbers that will connect to another table with ID = number. On the other table I have ID , name , link , height, width.

This height, width is the starting position to a sprites image. Every image inside that sprite has 48px height and width.

So i got the information and i need to work on the data. First try i did this

echo "<img class='small' src=$row2[link] height=$row2[height] width=$row2[width]>";

with no sucess because i forgot that height and width its the actual info for height and width.

I have to do this some times . For my test i have to try 255 times. So it is possible to get the proper image?

for the html i have only this:

<small style="height:48px;width:48px;">

I need to switch the starting position to the css side no?

   <?php

        $dsn = "mysql:host=localhost;dbname=tournament;charset=utf8";
            $opt = array(
                     PDO::ATTR_ERRMODE            => PDO::ERRMODE_EXCEPTION,
                     PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC
                        );
            $pdo = new PDO($dsn,'root','', $opt);


            $stmt = $pdo->prepare("SELECT * FROM table1");
            $stmt->execute();
            while($row = $stmt->fetch()) {
                foreach ($row as $value) {
                       $stmt2 = $pdo->prepare("SELECT link , height, width FROM table2 WHERE id = :id");
                       $stmt2->bindValue(':id', $value);
                       $stmt2->execute();                  
                       while($row2 = $stmt2->fetch()){
                            echo "<img class='small' src=$row2[link] $row2[height] $row2[width]>";
                        }
                    }
                }


    ?>

Best Regards, Paulo

2
you can not give start parameter in simple img tag , you will need some css for this - ddw147
ok thanks. will try and find a solution - Paulo Cardoso
i had given answer below try it - ddw147

2 Answers

0
votes

do this it will help ypu , but for this you will need transparent image

<img   src="img_trans.gif" style ="background: url(<?php echo $imagepath ?>) <?php echo $imgleft?> <?php echo $imgtop ?>; width: <?php echo $width?>px; height: <?php echo $width?>px;"  >

img_trans.gif is transparent image so that bg image will visible

imagepath - your image path imgleft - left start
imgtop - image top start

and other are width and height

here i use embed php tag in HTML you can build php string for html if you need

0
votes
echo '<div style=width:48px;height:48px;background:url('.$row2['link'].');background-position-x:-'.$row2['height'].'px;background-position-y:-'.$row2['width'].'px;";></div>';

This works. if u think that there is a better way send me a message.

Cheers