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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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.