Jump to content
  • Advertisement
Sign in to follow this  
Meres

[web] im lost - how can i accomplish this?

This topic is 3000 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

im creating a webgame with fairly specific needs. when a user clicks on a button on the ui, i need a box to popup, (over the main page not in a new window), the popup needs to have scroll bars, and needs to update regularily with queries from the database. Think of it like a list of current users in their location. Then the user can close this box. I know ill use php to access the database. but what about the display of the box and updating it from database? ajax?

thanks.

Share this post


Link to post
Share on other sites
Advertisement
You can use CSS to position the box in a fixed location on the screen, and to give it's content scroll bars.

You can use javascript async requests (aka AJAX) to update the content.

Share this post


Link to post
Share on other sites
You can do it with javascript.


What you do is create your html page and then create a DIV that is positioned where you want it and is hidden and the z-index is higher than everything else.


<DIV style="display:none;z-index:1">

<A id="updateMe"> Test Data </A>

</DIV>






When you want to display the item you create some javascript that shows the div and updates the text.


<SCRIPT>

function showBox() {

var updateText = document.getElementById("updateMe");

updateText.style.display = "block";

getData(updateText);

}

function getData(e) {

if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
}
else {// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}

var url = "get_data_from_my_database.php";

var params = "name=updateMe";

xmlhttp.open("POST", url, true);

xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

xmlhttp.onreadystatechange = function () {

// This is where the text gets updated,
// just bear in mind that it will only update when it gets
// a response so you may want some default 'Loading' text
// in the <A> tag
e.innerHTML = xmlhttp.responseText;

}

xmlhttp.send(params);

}

</SCRIPT>






Then you have a PHP file called "get_data_from_my_database.php" that has this...:


<?php

$value=$_POST["value"];
$name=$_POST["name"];


/// INSERT ALL YOUR DATABASEY STUFF HERE!!!

echo("I am returning anything I found in the database");

?>




Share this post


Link to post
Share on other sites
thanks for the help.

so ive made my elements separate divs, and set them all to visibility: none in my css. now im trying to make them visible through javascript. the javascript will be called by a php function which finds which location the user is currently in.

my javascript isnt making the div visible. this is the code currently:

<SCRIPT language=javascript>
function showBox(name) {

var updateText = document.getElementById(name);

updateText.style.display = "block";

}

<?php
echo "<script language=javascript>showBox(\"home_bg\");</script>";
?>

home_bg is the name of one the hidden divs. this is bypassing the php function, just to make sure that the javascript showBox function is working.

Share this post


Link to post
Share on other sites
By the way, to avoid reinventing the wheel and running into all sort of cross browser quirks, you might want to look in to popular libraries like jQuery. They can make life a lot easier.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!