A community in which webmasters can ask for help with topics such as PHP coding , MySQL , IT jobs, web design, IT security.
Current location:homephp forumphp talk in 2009 yearDisplay database contents? PHP / MySQL - page 1
User InfoPosts
Display database contents? PHP / MySQL#1
So I have a chatroom type of database where the text that a user inserts gets stored into a databse as their username in one field and their message in the other. I want to have my page output the database info, so that people can see each others messages.
How do I do this?

Also, is it possible to make a for loop that checks to see if the database has been updated with a new message, therefore it reloads the page? (Then the page outputs the database info again to update everyones messages)

Please help.. i(m so confused.

posted date: 2009-04-07 05:04:00

Re: Display database contents? PHP / MySQL#2
I had made out the solution of this problem. click to view my topic...

hope that hepls.

posted date: 2009-04-07 05:04:01

Re: Display database contents? PHP / MySQL#3
Take a look at MySQL functions in PHP manual. You need to connect to the server/database and run a select query to get the data from tables.As for the loop: you could use JavaScript setInterval function and combine that with AJAX call to periodically poll for new records.

posted date: 2009-04-07 05:07:00

Re: Display database contents? PHP / MySQL#4
To read anything from a mysql database you would use the mysql_connect() and the mysql_query() functionseg: $link = mysql_connect((localhost(, (root(, (();$results = mysql_query((select * from messages();while($row = mysql_fetch_array($results)){ echo $row[(username(] . (: ( . $row[(message(].(<br />(;}To display new messages the best way would be to use AJAX and poll the database from there, either loading a separate page into a DIV or getting XML back and placing into HTML tags. I would recommend using JQuery for these kinds of tasks. Check http://www.sitepoint.com/article/ajax-jquery/ for an example.

posted date: 2009-04-07 05:13:00

Re: Display database contents? PHP / MySQL#5
well, it's normal to be confused when the challenge is higher than the momentary skills... the good thing is, you'll learn a lot if you keep going. maybe you should start with something easier, if it makes you too anxious. what have you done so far with php/mysql?

posted date: 2009-04-07 05:18:00

Re: Display database contents? PHP / MySQL#6
Like the others have said, you will want to connect to your database and then query the table that you have the data in.while($row = mysql_fetch_assoc($results)){ echo $row[(username(] . " said: " . $row[(message(] . "<br />";}I use mysql_fetch_assoc() instead of mysql_fetch_array() since the arrays are associative arrays (not indexed by integers, but rather by names (associations))As for displaying the update on the page dynamically, that involves AJAX. Basically what that means is that your page will call out to a background script to get the new records from the database. This would require a new field in your (messages( table, something like (msg_delivered( that you could set to (1( when it has been fetched.You should check out this if you are interested in making an AJAX chat client: http://htmltimes.com/javascript-chat-client-in-jquery.php

posted date: 2009-04-07 07:16:00

select page: « 1 »
Copyright ©2008-2017 www.momige.com, all rights reserved.