sirio Posted February 11, 2007 Share Posted February 11, 2007 Hi all. In the main page i've got a block which shows the x last posts. The problem is that if you want to check for new posts, you have to refresh the whole page. But I wanted to refresh ONLY that part using AJAX, by using a "Refresh" button. How could i do it? is it very difficult? Quote Link to comment Share on other sites More sharing options...
sirio Posted February 12, 2007 Author Share Posted February 12, 2007 Well, I've already do it, but i have a problem: I have two files: block-Forums.php: if( eregi( "block-Foros.php",$PHP_SELF ) ) { Header("Location: index.php"); die(); } global $prefix, $user_prefix, $db; // Ajax function $content .= " <script language=\"javascript\" type=\"text/javascript\"> function getPage(Last_New_Topics){ var xmlhttp=false; //Clear our fetching variable try { xmlhttp = new ActiveXObject('Msxml2.XMLHTTP'); } catch (e) { try { xmlhttp = new ActiveXObject('Microsoft.XMLHTTP'); } catch (E) { xmlhttp = false; } } if (!xmlhttp && typeof XMLHttpRequest!='undefined') { xmlhttp = new XMLHttpRequest(); } var file = 'test/1/text.php?n='; xmlhttp.open('GET', file + Last_New_Topics, true); xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4) { var content = xmlhttp.responseText; if( content ){ document.getElementById('content').innerHTML = content; } } } xmlhttp.send(null) return; } </script>"; [...] and text.php: <?php mysql_connect("localhost", "root", ""); mysql_select_db("lq"); $n = $_GET["n"]; $result = mysql_query("SELECT t.topic_id, t.topic_first_post_id, t.forum_id, t.topic_last_post_id, t.topic_title, t.topic_poster, t.topic_views, t.topic_replies, t.topic_moved_id, p.poster_id, p.post_time, u.username, l.username, u.user_id, tx.post_text, p.post_username, f.post_username FROM nuke_bbtopics AS t LEFT JOIN nuke_bbposts AS p ON (p.post_id = t.topic_last_post_id) LEFT JOIN nuke_bbposts AS f ON (f.post_id = t.topic_first_post_id) LEFT JOIN nuke_bbposts_text AS tx ON (p.post_id = tx.post_id) LEFT JOIN nuke_users AS u ON (u.user_id=p.poster_id) LEFT JOIN nuke_users AS l ON (l.user_id=t.topic_poster) WHERE t.topic_moved_id=0 ORDER BY t.topic_last_post_id DESC LIMIT 0, $n "); while( list( $topic_id, $postf_id, $forum_id, $topic_last_post_id, $topic_title, $topic_poster, $topic_views, $topic_replies, $topic_moved_id, $poster_id, $post_time, $post1, $post2, $user_id, $post_text, $guest_name, $guest_name2) = $row = mysql_fetch_row($result)) { [...] In the second file, I have to make a connection, but i want to make it through the "$db" variable, to avoid these lines: mysql_connect("localhost", "root", ""); mysql_select_db("lq"); How could i do it? Quote Link to comment Share on other sites More sharing options...
mrknowledge Posted February 15, 2007 Share Posted February 15, 2007 Do you mean with the refresh button in the browser? Quote Link to comment Share on other sites More sharing options...
sirio Posted February 15, 2007 Author Share Posted February 15, 2007 No, i mean through a link button ("click here to refresh"). I've already done that part, but the problem now is the connection. In the 2nd file, i have this: mysql_connect("localhost", "root", ""); mysql_select_db("lq"); But this is an unsecure method to connect. I've tried to pass the variable $db to the 2nd file using GET method, but my browser doesn't show me anything. I also tried to pass another variable ($prefix) to the second file and I didn't have any problem. How could i pass the $db variable??? (sorry if you don't understand me but i'm spanish) Quote Link to comment Share on other sites More sharing options...
sirio Posted February 15, 2007 Author Share Posted February 15, 2007 Well, i think i've solved the problem. I've added these lines at the beginning of the 2nd file: require("../config.php"); require("../includes/sql_layer.php"); $db = sql_connect($dbhost, $dbuname, $dbpass, $dbname); And I've deleted these other lines: mysql_connect("localhost", "root", ""); mysql_select_db("lq"); Perfect!!!! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.