Jump to content

PHP to show images on page, depending on co-ordinates?


leachus2002

Recommended Posts

Hi All,

 

I am trying to develop an application that show's where PC's are located in an office. Basically, what I want to be able to do, is to overlay avatar-like images over a main floorplan layout, and place them in a position, depending on thier x/y co-ordinates, which would be retreived from a database.

 

Is this possible using PHP at all?

 

Thanks in advance

Matt

Yep easy peasy I think :)

 

You have a big image of the floorplan with all the computers.

Then you have all of the avatar like things printing out their co-ordinates on the image with CSS inline styles

 

<div style="position:relative;">
       <img src="floorplan.jpg" alt="" style="position:absolute;top:0;left:0;" />
        <?php 
           // Grab the co-ordinates from where-ever they are and then loop through each of them
          foreach($coords as $coord){
                echo '<img src="avatar-dom.jpg" alt="" style="position:absolute; top:' . $coord['x'] . '; left:' . $coord['y'] . ';" />';
          } 
          ?>
</div> 

 

This way you have the floorplan and then store the X/Y of each avatar in the database and loop through each of them placing them on top of the floorplan where needed.

Superb! Thanks for that!

 

Can you just confirm the variable i need to put for my select statement? Would it be something like:

 

$coord = mssql_query = "select x,y from database"
<div style="position:relative;">
<img src="floorplan.jpg" alt="" style="position:absolute;top:0;left:0;" />
<?php            // Grab the co-ordinates from where-ever they are and then loop through each of them
foreach($coords as $coord){
echo '<img src="avatar-dom.jpg" alt="" style="position:absolute; top:' . $coord['x'] . '; left:' . $coord['y'] . ';" />';          }
?></div> 

 

Cheers

Matt

Superb! Thanks for that!

 

Can you just confirm the variable i need to put for my select statement? Would it be something like:

 

$coord = mssql_query = "select x,y from database"
<div style="position:relative;">
<img src="floorplan.jpg" alt="" style="position:absolute;top:0;left:0;" />
<?php            // Grab the co-ordinates from where-ever they are and then loop through each of them
foreach($coords as $coord){
echo '<img src="avatar-dom.jpg" alt="" style="position:absolute; top:' . $coord['x'] . '; left:' . $coord['y'] . ';" />';          }
?></div> 

 

Cheers

Matt

 

Mmm I've not used mssql before, I use mysql but looking at the php manual I can see its just about the same :)

I think something like this

 

<div style="position:relative;">
<img src="floorplan.jpg" alt="" style="position:absolute;top:0;left:0;" />
<?php           
// Grab the co-ordinates from where-ever they are and then loop through each of them
$res = mssql_query("SELECT x,y FROM database"); 
while ($row = mysql_fetch_array($res, MYSQL_ASSOC)) { 
        $left = $row["x"]; 
        $top = $row["y"]; 
        echo '<img src="avatar-dom.jpg" alt="" style="position:absolute; top:' . $top . '; left:' . $left . ';" />';
}
?>
</div>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.