Jump to content

auto refresh if updates occur on database


overmind

Recommended Posts

hi everybody.. i hope you can all understand my problem.. i have an inventory system written in vb6 with mysql as backend. i have also created a webpage that uses the same database as my vb6 application. now my problem is i want my page to automatically refresh everytime some changes in the database occur. Im still a newbie in web based programming so please bear with me.. i dont know where to start or if i should use a scripting language embedded in my page to make this work.. please help. any example or link will do.. thanks in advance.

You would simply use for example PHP to fetch the information from your database and display it to your visitors. You don't really have to worry about "automatically refreshing every time some changes in the database occur" because you will always be fetching the current / present data from y our database...

 

www.yoursite.com/products.php

<?php
// Connect to your MySQL database - from php.net
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$link) {
    die('Could not connect: ' . mysql_error());
}

// Query your database
$get_products = mysql_query("SELECT id, name, price FROM products");

?>

<html>
<head>
    <title>Your new dynamic website</title>
</head>

<body>

<?php
// Display the results of your query
while($row = mysql_fetch_array($get_products) {
         echo "ID: " . $row['id'];
         echo "Name: " . $row['name'];
         echo "Price: " . $row['price];
}

?>
</body>
</html>

 

That's really the basics of what you need to do. Simply connect to your existing database, make some queries and display the result along with the rest of your webpage. When someone goes to www.yoursite.com/products.php they will see the newest items in your database :)

 

Of course the above is a bare minimum of what you need to do - have a look at some PHP / MySQL tutorials:

 

http://www.php-mysql-tutorial.com/

 

 

Wuhtzu

Web servers and any server side script running on a web server are passive and are request based (they wait for a request from a browser.) They cannot cause anything to happen in a browser.

 

If you have a database that can be updated from different sources and you want new or changed information to automatically appear in a browser, you will need to cause that browser to periodically request the page from the server.

He said he had a mysql / vb6 backend and that he want his website to display data from the database.

 

My guess is the thought that each time he update, delete or write to his database he would have some script / mechanism recreate all .html files with the new information (updated db records). He could do that, not with php, but some other language / software. However it would be a "stupid way around" since he can just make a few scripts fetch the information each time a browser / user requests it.

 

I think that's what I said in my previous post.

 

 

hi.. it seems i should continuously check if there are changes in the database.. but i want it to be done in the shadows. i've heard ajax should do the trick here. but the problem is i dont know how to do it.. can anybody show me the ropes? thanks..

hi.. it seems i should continuously check if there are changes in the database.. but i want it to be done in the shadows. i've heard ajax should do the trick here. but the problem is i dont know how to do it.. can anybody show me the ropes? thanks..

 

Yes.

 

I suggest jheartbeat for this. as simple as it gets.

I think we should here more about what you are trying to accomplish. Because if you are trying to show users / customers browsing to your website with their webbrowser you do not have to concern your self with checking the database for changes and whether it's done in the shadows or not. They _will_ always see the newest database records because when they request www.yoursite.com/somepage.php it will pull the records the database currently hold (which must be the newest)....

 

If the above is not what you are trying please explain in greater detail.

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.