Jump to content

web_master

Members
  • Posts

    419
  • Joined

  • Last visited

About web_master

  • Birthday 07/12/1966

Contact Methods

  • MSN
    info@internetlabor.net
  • Website URL
    http://www.internetlabor.net

Profile Information

  • Gender
    Male
  • Location
    Serbia

web_master's Achievements

Advanced Member

Advanced Member (4/5)

0

Reputation

  1. As I see there is a many ways to use mysqli in request data from database. I try simple to "rename" mysql_ to mysqli_ but it not work. Somewhere I need to connect to the database too, $dbConnect. This is a problem, how can I do this...
  2. Hi, I got a problem with pagination. I got a script but the problem is that I use the connection to database with "mysqli" NOT "mysql". Im newbe with mysqli and I dont know how can I change the pagination script to work. <?php $dbConnect= mysqli_connect('localhost', 'user', 'password') or die('Cant connect'); mysqli_select_db($dbConnect, 'database') or die('Cant connect to database'); mysqli_set_charset($dbConnect, "utf8"); ?> And this is a script for pagination <?php $limit = 4; $sql = "select count(c_vesti_id) from c_vesti"; $c = array_shift(mysql_fetch_row(mysql_query($sql))); $maxpage = ceil($c / $limit); $page = isset($_GET['page']) ? abs((int)$_GET['page']) : 1; if ($page <= 0) { $page = 1; } else if ($page >= $maxpage) { $page = $maxpage; } $offset = ($page-1) * $limit; $query = mysql_query("select * from c_vesti limit $offset, $limit "); while ($row = mysql_fetch_assoc($query)) { print $row['c_vesti_naslov']."<br />"; } // $linklimit = 4; $linklimit2 = $linklimit / 2; $linkoffset = ($page > $linklimit2) ? $page - $linklimit / 2 : 0; $linkend = $linkoffset+$linklimit; if ($maxpage - $linklimit2 < $page) { $linkoffset = $maxpage - $linklimit; if ($linkoffset < 0) { $linkoffset = 0; } $linkend = $maxpage; } if ($page > 1) { print "<a href='?page=".($page-1)."'>Back</a> "; } for ($i=1+$linkoffset; $i <= $linkend and $i <= $maxpage; $i++) { $style = ($i == $page) ? "color: black;" : "color: blue;"; print "<a href='?page=$i' style='$style'>[$i]</a> "; } if ($page < $maxpage) { print "<a href='?page=".($page+1)."'>Forward</a>"; } ?> Thanks in advanced for help T
  3. Hi, I don't know what amI do wrong. I have 3 tables, (authors, text, kategories). I want to print every group names from database and + 3 text below kategory name. After first record (text) separately two more (next) records. With this code I give only the first category with 3 text... Please if You can help me.... <?php /* SELECT FROM DATABASE */ $QuerySelect = ' SELECT c_kat.c_kat_onoff, c_kat.c_kat_delete, c_kat.c_kat_order, c_autor.c_autor_onoff, c_autor.c_autor_delete, c_autor.c_autor_prezime, c_autor.c_autor_ime, c_autor.c_autor_id, c_kat.c_kat_id, c_kat.c_kat_ime, c_vesti.c_vesti_id, c_vesti.c_vesti_date, c_vesti.c_vesti_sat, c_vesti.c_vesti_min, c_vesti.c_vesti_naslov, c_vesti.c_vesti_text, c_vesti.c_vesti_kat, c_vesti.c_vesti_autor, c_vesti.c_vesti_onoff, c_vesti.c_vesti_delete FROM c_vesti INNER JOIN c_kat ON c_kat.c_kat_id = c_vesti.c_vesti_kat INNER JOIN c_autor ON c_autor.c_autor_id = c_vesti.c_vesti_autor WHERE `c_vesti_onoff` = 1 AND `c_vesti_delete` = 0 ORDER BY `c_kat_order` ASC, `c_vesti_date` DESC, `c_vesti_sat` DESC, `c_vesti_min` DESC, `c_vesti_id` ASC LIMIT 3 '; $query_select = mysqli_query($dbConnect, $QuerySelect) or die (mysqli_error($dbConnect)); if(!$query_select){ echo mysqli_error($dbConnect); exit; } while($request = mysqli_fetch_array($query_select)) { $group_by_cat[$request['c_kat_ime']][] = $request; } foreach($group_by_cat as $group => $rows) { echo '<div class="catcolor">' . $group . '</div>'; // Category name $first_rec = true; foreach($rows as $row) { if ($first_rec) { // first record echo '<div>First text headline - ', $row['c_vesti_naslov'], '</div>'; $first_rec = false; } else { // other records echo '<div>Other text headline -', $row['c_vesti_naslov'], '</div>'; } } } ?>
  4. Hi, I just begin to use msqli and I dont know what am I doing wrong? The warning message is: Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, object given in ... $QuerySelect = ' SELECT * FROM `a_slider` WHERE `a_slider_id` = "' . $a_slider_id . '" '; if(!$QuerySelect){ echo mysqli_error($dbConnect); exit; } $request = mysqli_fetch_array($QuerySelect); thanks T
  5. here is the styles too: body{ font-family: Verdana; font-size: 11px; background-color: #BFC08D; } .tablebottom{ border-bottom: 1px solid #E6E6E6; } .middlebox{ border-bottom: 1px solid #E6E6E6; border-left: 1px solid #E6E6E6; } #maintable{ border: 1px solid #E6E6E6; background-color: #C9CCBB; } #chatscreen{ width: 850px; height: 500px; float: left; overflow: auto; text-align: left; } #onlineusers{ height: 500px; width: 100px; float: right; } a{ text-decoration: none; color: #000000; } a:hover{ text-decoration: none; color: #8DBAEB; } input{ border: 1px solid #E6E6E6; } #submitbutton{ background-color: #FFFFFF; font-family: Tahoma; } #messagebox{ background-color: #E8E9E2; } #userbox{ background-color: #E8E9E2; height: 20px; } #usersbox{ text-align: left; background-color: #E8E9E2; } .user{ border-bottom: 1px solid #969A7A; }
  6. Hi, I fond some script on internet, and the textarea dont work. I cant find what is the problem.... Nothing is inserted in database, and reloaded from database. The (who is) online users is work perfect. thnks in advanced T database CREATE TABLE IF NOT EXISTS `auth` ( `user` varchar(30) NOT NULL, `session` varchar(50) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1; CREATE TABLE IF NOT EXISTS `chat` ( `time` varchar(30) NOT NULL, `user` varchar(30) NOT NULL, `text` text NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1; config.php <?php // Let's connect to our database // Usually your host is 'localhost' // But sometimes it might be different so ask your host // About your database server address $mysql_con = mysql_connect("localhost", "Username", "Password"); // Now let's check if everything is good // If there's something wrong.. let's display an error if(!$mysql_con){ die(mysql_error()); } // Let's select our database $mysql_db = mysql_select_db("DatabaseName", $mysql_con); // Let's check here also is everything is okay // If there's something wrong, let's display an error if(!$mysql_con){ die(mysql_error()); } ?> actions.php <?php // Let's start our session session_start(); // Include the config.php because we are // Going to start work with our database include("config.php"); // First let's make a login form // Here user sets his/her username that // He/she will use in this chatroom function login_form(){ echo "<br /><br />"; echo "<table width='500' border='0' id='maintable' style='background-color: #F3F3F3' align='center'>" ."<tr>" ."<td align='center'><font style='font-size: 20px'>Login</font></td>" ."</tr>" ."<tr>" ."<td align='center'>"; echo "<form action='index.php?act=login' method='post'>" ."Username: <input type='text' name='username' /> <input type='submit' id='button' value='Login' /><br /><br />" ."</form>"; echo "</td>" ."</tr>" ."</table>"; } // Now let's log that user in function process_login(){ // Let's get user's username $username = $_REQUEST['username']; // Now let's find if there are records about him/her in database $sql = "SELECT * FROM auth WHERE user='".mysql_real_escape_string($username)."'"; $query = mysql_query($sql); // If there are any records, delete them if(mysql_num_rows($query)>0){ $sql = "DELETE FROM auth WHERE user='".mysql_real_escape_string($username)."'"; $query = mysql_query($sql); // Check that everything is okay // If something is wrong, display an error if(!$query){ die(mysql_error()); } } // Now let's set session with user's name // And insert it into database so we know that // He/she is logged in $_SESSION['user'] = $username; $sql = "INSERT INTO auth (user, session) VALUES ('".mysql_real_escape_string($username)."', '".session_id()."')"; $query = mysql_query($sql); // Check that all things went well // If something was wrong, display an error // But if evetrything is good, redirect him/her // To the chatroom if(!$query){ echo "Can not insert info into database!<br />". mysql_error(); }else{ header("Location: index.php"); } } // Now let's make a function that logs users our function logout(){ // This will delete any traces of him/her // From database so it will be a clean sheet // When he/she comes back $sql = "DELETE FROM auth WHERE session='".mysql_real_escape_string(session_id()). "'"; $query = mysql_query($sql); // Little error checking again if(!$query){ echo "Can not delete info from database!"; }else{ // If everything went well, let's destroy // Session and redirect to main page also // Where login form waits him/her session_destroy(); header("Location: index.php"); } } // Now we want to show user's username // In "Welcome [user]" area function get_username(){ // Let's get all info abour our current session from database $sql = "SELECT * FROM auth WHERE session='".mysql_real_escape_string(session_id()). "'"; $query = mysql_query($sql); $row = mysql_fetch_array($query); // If there aren't any records // Let's set our user's name to "Guest" // If there are records let's get the real username if(mysql_num_rows($query) == "0"){ $username = "Guest"; }else{ $username = $row['user']; } return $username; } // Now we want to display "Log In" or "Log Out" // Link after greeting function get_link(){ // Again we check for records from database $sql = "SELECT * FROM auth WHERE session='".mysql_real_escape_string(session_id()). "'"; $query = mysql_query($sql); $row = mysql_fetch_array($query); // If there are no records about our user // Let's display "Log In" link // But if there are records about our user // Display a "Log Out" link if(mysql_num_rows($query) == "0"){ $link = "<a href='index.php?act=login'>Log In</a>"; }else{ $link = "<a href='index.php?act=logout'>Log out</a>"; } return $link; } // This is the function that posts // User messages to database function post_message(){ // Let's clean our text that user entered $text = addslashes(htmlentities(htmlspecialchars($_REQUEST['text']))); // Now let's insert it into database $sql = "INSERT INTO chat (time, user, text) VALUES ('".date("H:i")."', '".get_username()."', '".$text."')"; $query = mysql_query($sql); // Little error checking and we are done if(!$query){ die(mysql_error()); } } // Now we have to get messages // From database to see what other users are writing function get_messages(){ // Now let's get all info from "chat" table $sql = "SELECT * FROM chat"; $query = mysql_query($sql); // Some error checking if(!$query){ echo "Can not get messages from database."; }else{ // If everything is fine let's display our messages // First to come is time, it will look like this (12:34) // Second is user's name and after that comes the text // For example: (13:54) Jaan: Hey there! while($row = mysql_fetch_array($query)){ echo "(".$row[time].") "."<b>".$row['user'].":</b> ".$row['text']."<br />"; } } } // Now let's get users that are using this // Chatroom, so people can see who they are talking function get_users(){ // Let's get all info from "auth" table $sql = "SELECT * FROM auth"; $query = mysql_query($sql); // Check that everything is fine if(!$query){ echo "Can not get users from database."; }else{ // If everything is fine, let's display all users while($row = mysql_fetch_array($query)){ echo "<div class='user'>".$row['user']."</div>"; } } } // Here's the engine that puts everything to work // All functions are triggered when they are wanted // For example we want to log our user out // We put this link to our page: <a href='index.php?act=logout'>Log out</a> // And as you see when "act" isn't empty and "act" is "logout" // Let's trigger logout() function that logs our user out // Everything works the same with other functions $act = addslashes(htmlentities(htmlspecialchars($_GET['act']))); if($act != "" && $act == "logout"){ logout(); }elseif($act != "" && $act == "login"){ process_login(); }elseif($act != "" && $act == "post"){ post_message(); }elseif($act != "" && $act == "getmessages"){ get_messages(); exit; }elseif($act != "" && $act == "getusers"){ get_users(); exit; } ?> process.js // If page is loaded let's load our functions $(function(){ // If submit button has been clicked $("#submitbutton").click(function(){ // Let's get what user has entered to the text field var message = $("#text").val(); // Now let's post this text $.post("includes/actions.php?act=post", { text: message }); // When user's text is posted // Remove it from the text field $("#text").attr("value", ""); return false; }); // Now let's load our messages function load_messages(){ // Let's use AJAX to get them from our actions file $.ajax({ url: "includes/actions.php?act=getmessages", cache: false, success: function(html){ // Let's get old posts from there // Where user's posts are shown $("#chatscreen").html(html); // Now let's get this area's height where // All posts are displayed and then let's animate // It little bit so the scrollbar is always // Scrolled down so you can see the new posts var newheight = $("#chatscreen").attr("scrollHeight") - 20; $("#chatscreen").animate({ scrollTop: newheight }, 'fast'); }, }); } // Now let's load chatroom's active users function load_users(){ // Let's use AJAX also to get chatroom's users $.ajax({ url: "includes/actions.php?act=getusers", cache: false }); } // Now let's set the time when we will // Check for new messages and new users // First, we set the time of our posts // setInterval(load_messages, 500) loads our posts every 0.5 seconds // setInterval(load_users, 5000) loads our posts every 5 seconds setInterval(load_messages, 500); setInterval(load_users, 5000); }); index.php <?php // Let's start session and let's include our files session_start(); include("includes/config.php"); include("includes/actions.php"); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> <title>Sugar Chat 1.0</title> <script src="includes/jquery.js" type="text/javascript"></script> <script src="includes/process.js" type="text/javascript"></script> <link href="includes/style.css" rel="stylesheet" type="text/css" /> </head> <body> <?php // Now if our username is "Guest" // Let's display the login form if(get_username() == "Guest"){ echo "<td>" .login_form() ."</td>"; // If it isn't let's display the chatroom }else{ ?> <table width="900" border="0" align="center" id="maintable"> <tr> <td class="tablebottom" colspan="2" id="userbox"> <?php // Let's say greetings to the user and display the "Log out link" echo "Welcome: ".get_username()."! (".get_link().")"; ?> </td> </tr> <tr> <td align="center" class="tablebottom"> <div id="chatscreen"> <?php // Now here is the same thing that is in actions file // Let's select all info from "chat" table $sql = "SELECT * FROM chat"; $query = mysql_query($sql); // Little error checking again if(!$query){ echo "Can not get messages from database."; }else{ // If everything is good let's display // User's messages while($row = mysql_fetch_array($query)){ echo "<div align='left'>(".$row[time].") "."<b>".$row['user'].":</b> ".$row['text']."</div>"; } } ?> </div> </td> <td class="middlebox" id="usersbox" rowspan="2"> <div id="onlineusers"> <?php // This is also like in actions file // Get all info from "auth" table $sql = "SELECT * FROM auth"; $query = mysql_query($sql); // Check for errors if(!$query){ echo "Can not get users from database. ".mysql_error(); }else{ // If everything is fine // Let's display active users while($row = mysql_fetch_array($query)){ echo "<div class='user'>".$row['user']."</div>"; } } ?> </div> </td> </tr> <tr> <td colspan="2" id="messagebox"> <form action=""> <input type="text" size="129" id="text" name="chattxt" /> <input type="submit" id="submitbutton" value="Send" /> </form> </td> </tr> </table> <?php } ?> </body> </html>
  7. Hi, I got a "simple" problem. I use the "textarea" - in My case this is the TinyMCE. Is some possibility that when somebody edit the text on one computer the other people on the other computer see that, and thay can't "open" and edit same text. Like on Word, only one person can edit same text. In advanced tnahnk You. T
  8. I write in htaccess file next: <IfModule mod_rewrite.c> RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /index.php?route=$1 [QSA] </IfModule> in PHP file is: $route = explode("/", trim($_GET["route"], " \t\n\r\0\x0B/")); so how can I split those variables, to make links in php files? example domain.com/content/main/header-of-text/155 content is the content file which is included into index.php main is a some group of texts (name is stored in database - joined tables) header-of-text is a header of the text stored in database - just writed 155 is the ID of text without rewriting thats looks like domain.com?route=content&textgroup=7&id=155 ...or am a totaly wrong...
  9. I use the links in php like this: index.php?content=filename So I want to use it in future like: http://example.com/2014/link-name/post-head-name/ I dont have the idea how can I do that? Can anybody help me how to do that in PHP?
  10. I can't find how can I validate (confirm) password width jQuery without submit. Mean, when I type the password confirmation to see immediatly is correct or not. <input type="password" name="password" autocomplete="off" value="password" maxlength="12" /> <input type="password" name="password" autocomplete="off" value="passwordconfirm" maxlength="12" /> I can't find script without submit form....
  11. Hi, I got a problem. I have an array, list of users (and passwords). But it is an Array and I must enter a names and passwords "manually". I want to change that array to query... Array is: $LOGIN_INFORMATION = array( 'zubrag' => 'password', 'test' => 'testpass', 'admin' => 'passwd' ); so I want to chage it: $QueryReturn = mysql_query(' SELECT * FROM `users` WHERE ORDER BY `users_username` ASC '); if(!$QueryReturn){ echo mysql_error(); exit; } while($request = mysql_fetch_array($QueryReturn)) { /// } $request['users_username'] $request['users_password'] this two variables is what can change in array... So, I dont know how can I replase with Query the Array. Thanks in advanced T
  12. With firebug I find that the Getlist is working, but the update is not working, in Dreamweaver is a syntax error, but I don't know what is the problem.... Somewhere here.... <script type="text/javascript"> $(document).ready(function () { function reload() { $("#content").load("update.php"); } setTimeOut(reload, seconds*1000) } </script>
  13. The first script need to update the update.php file every X second - update from session ( $_SESSION['reg_nick'] ) and this is a first problem, that don't update, and I don't know where is a problem javascript: <script type="text/javascript"> $(document).ready(function () { function reload() { $("#content").load("update.php"); } setTimeOut(reload, seconds*1000) } </script> php <?php session_start(); mysql_query(' UPDATE `users` SET `lastActiveTime` = NOW() WHERE `reg_nick` = "' . $_SESSION['reg_nick'] . '" ') or die(mysql_error()); ?> The second script need to reload from getList.php the users who is online: javascript: <script type="text/javascript"> setInterval("getList()", 10000) // Get users-online every 10 seconds function getList() { $.post("getList.php", function(list) { $("#listBox").html(list); }); } </script> php; <?php session_start(); if (!$_SESSION["reg_nick"]) { die; // Don't give the list to anybody not logged in } else { $users = mysql_query('SELECT * FROM `users` WHERE `lastActiveTime` > NOW()-60 ') or die(mysql_error()); $output = "<ul>"; while($row=mysql_fetch_array($users)) { $output .= "<li>".$row["reg_nick"]."</li>"; } $output .= "</ul>"; print $output; } ?> So, at the end in index.php file, where is the <div id="listBox"></div> I want to see the list of online users. I didn't say that will be a simple chat, and I didn't do something like this before... I'm sorry, I'm omitted to put scripts in CODE...
  14. The first script need to update the update.php file every X second - update from session ( $_SESSION['reg_nick'] ) and this is a first problem, that don't update, and I don't know where is a problem javascript: <script type="text/javascript"> $(document).ready(function () { function reload() { $("#content").load("update.php"); } setTimeOut(reload, seconds*1000) } </script> php <?php session_start(); mysql_query(' UPDATE `users` SET `lastActiveTime` = NOW() WHERE `reg_nick` = "' . $_SESSION['reg_nick'] . '" ') or die(mysql_error()); ?> The second script need to reload from getList.php the users who is online: javascript: <script type="text/javascript"> setInterval("getList()", 10000) // Get users-online every 10 seconds function getList() { $.post("getList.php", function(list) { $("#listBox").html(list); }); } </script> php; <?php session_start(); if (!$_SESSION["reg_nick"]) { die; // Don't give the list to anybody not logged in } else { $users = mysql_query('SELECT * FROM `users` WHERE `lastActiveTime` > NOW()-60 ') or die(mysql_error()); $output = "<ul>"; while($row=mysql_fetch_array($users)) { $output .= "<li>".$row["reg_nick"]."</li>"; } $output .= "</ul>"; print $output; } ?> So, at the end in index.php file, where is the <div id="listBox"></div> I want to see the list of online users. I didn't say that will be a simple chat, and I didn't do something like this before...
×
×
  • 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.