Jump to content

colap

Members
  • Posts

    302
  • Joined

  • Last visited

Everything posted by colap

  1. I have selected utf8-bin during creation of database. What else should i have to do to insert Bangla? In PHP script there is: I am trying with PHP and PDO. It is unreadable characters in mysql table.
  2. How can i preview a form value before submit? <form method="POST" action="p.php"> <table> <tr><td>Username</td><td><input type="text" name="username" id="id_username" /></td></tr> <tr><td>Fathers name</td><td><input type="text" name="f_username" id="id_f_username" /></td></tr> <tr><td><input type="submit" value="Submit" /></td></tr> </table> </form> It will be like "Preview Post" of phpfreaks forum.
  3. It hides the button, but there is one extra request from button to load data. How can i stop it? How can i let jquery know that it is the last record so hide the button?
  4. Button is not necessary if there is not more data. No more code.
  5. <input type="button" id="id_load_more" name="nm_load_more" value="Load More" /> If the data.length = 0 , then there will be no button. How can i do this?
  6. <script type=text/javascript src="jquery-1.11.3.js"></script> <input type="button" id="id_load_more" name="nm_load_more" value="Load More" /> <script type="text/javascript"> $(document).ready(function() { var limit = 1; console.log("ready!"); $( "input#id_load_more" ).on( "click", function( event ) { //event.stopPropagation(); $.ajax({ method: "POST", url: "load_more.php", data: {"page": limit}, dataType: "JSON", success: function(data) { console.log(data); //console.log(data.status); limit++; } }); }); }); </script> If there is no data in table limit++ needs not to increment. How can i do it? This is the load_more.php <?php if (session_id() == '') { session_start(); } require_once ('./functions.php'); $dbh = mysql_connection(); $user_id = $_SESSION['login_user_id']; $sql_total_rows = "SELECT u.id, u.username as non_friend FROM users u LEFT JOIN ( SELECT user_id, friend_id FROM friends WHERE user_id = $user_id UNION SELECT friend_id, user_id FROM friends WHERE friend_id = $user_id ) f ON u.id = f.friend_id WHERE u.id <> $user_id AND f.friend_id IS NULL ORDER BY id"; $stmt_total_rows = $dbh->prepare($sql_total_rows); $stmt_total_rows->execute(); $result_total_rows = $stmt_total_rows->rowCount(); //echo $result_total_rows; $number_of_items_per_page = 2; $total_number_of_page = ceil($result_total_rows/$number_of_items_per_page); //echo $total_number_of_page; //$page = $_POST['page']; //$_POST['page'] = 2; $limit = ($_POST['page'] - 1) * $number_of_items_per_page; $sql_non_friends = "SELECT u.id, u.username as non_friend FROM users u LEFT JOIN ( SELECT user_id, friend_id FROM friends WHERE user_id = $user_id UNION SELECT friend_id, user_id FROM friends WHERE friend_id = $user_id ) f ON u.id = f.friend_id WHERE u.id <> $user_id AND f.friend_id IS NULL ORDER BY id limit $limit , $number_of_items_per_page;"; //echo $sql_non_friends; $stmt = $dbh->prepare($sql_non_friends); $stmt->execute(); $result = $stmt->fetchAll(); //formatted_value($result); /* foreach ($result as $value) { //formatted_value($value); $user_id = $value['id']; echo $value['non_friend']; echo "<a href='add_friend.php?user_id=$user_id' >Add Friend</a>"; echo '<br/>'; } */ //echo $_POST; //echo json_encode($_POST); if($_POST['page'] = $total_number_of_page) { $data['status'] = 1; $data['result'] = $result; echo json_encode($data); } else { echo json_encode($result); } It is a ajax request to do load more data after clicking the button. Thanks in advance.
  7. How can i do facebook/twitter like loading more data for scrolling down? Can someone post example code in php and jquery ajax here? Can anyone post good link to learn this? Thanks in advance.
  8. http://stackoverflow.com/questions/915643/select-where-not-exists Here it says: "You can join these tables with a LEFT JOIN keyword and filter out the NULL's, but this will likely be less efficient than using NOT EXISTS." NOT EXISTS is more efficient ?
  9. What will be the sql query with NOT EXISTS to get the same result? Can you paste the sql query here?
  10. SELECT * FROM users WHERE NOT EXISTS ( SELECT * FROM friends WHERE (user_id = users.id AND friend_id = 2) OR (user_id = 2 AND friend_id = users.id) ) This outputs: (2, 'user2', NULL, NULL), (5, 'user5', NULL, NULL) SELECT u.id , u.name as non_friend FROM user u LEFT JOIN ( SELECT user_id , friend_id FROM friend WHERE user_id = 2 UNION SELECT friend_id , user_id FROM friend WHERE friend_id = 2 ) f ON u.id = f.friend_id WHERE u.id <> 2 AND f.friend_id IS NULL ORDER BY id; +----+------------+ | id | non_friend | +----+------------+ | 5 | user 5 | +----+------------+ Is it possible to do the same thing with NOT EXISTS ? Thanks in advance.
  11. user table friend table +----+--------+ +---------+-----------+ | id | name | | user_id | friend_id | +----+--------+ +---------+-----------+ | 1 | user1 | | 2 | 3 | | 3 | user3 | | 2 | 4 | | 4 | user 4 | +---------+-----------+ | 5 | user 5 | | +----+--------+ | | | | | | | +-------------------LEFT JOIN---------------------+ select * from user inner join friend, Inner join has 10 cartesian product(rows). select * from user left join friend, does this also produce 10 cartesian product(rows)? Thanks in advance.
  12. http://www.sitepoint.com/understanding-sql-joins-mysql-database/ Is it possible to see the result of left join of two tables(without on clause)? mysql> select * from user; +----+----------+--------+ | id | name | course | +----+----------+--------+ | 1 | Alice | 1 | | 2 | Bob | 1 | | 3 | Caroline | 2 | | 4 | David | 5 | | 5 | Emma | NULL | +----+----------+--------+ 5 rows in set (0.00 sec) mysql> select * from course; +----+------------+ | id | name | +----+------------+ | 1 | HTML5 | | 2 | CSS3 | | 3 | Javascript | | 4 | PHP | | 5 | MySQL | +----+------------+ 5 rows in set (0.00 sec) mysql> SELECT * FROM `user` left join course on user.course=course.id; +----+----------+--------+------+-------+ | id | name | course | id | name | +----+----------+--------+------+-------+ | 1 | Alice | 1 | 1 | HTML5 | | 2 | Bob | 1 | 1 | HTML5 | | 3 | Caroline | 2 | 2 | CSS3 | | 4 | David | 5 | 5 | MySQL | | 5 | Emma | NULL | NULL | NULL | +----+----------+--------+------+-------+ 5 rows in set (0.00 sec) Why/how is id=NULL and name=NULL for Emma,NULL?
  13. If there is (2,3) then it will not insert (3,2). Do i have to check this programmatically?
  14. http://www.w3schools.com/sql/sql_unique.asp CONSTRAINT uc_PersonID UNIQUE (P_Id,LastName) CONSTRAINT uc_PersonID UNIQUE (LastName,P_Id) Are these same?
  15. How can i stop inserting same data into friends table during friend request? For example: (2,3) and (3,2) are same. If (2,3) is there in friends table, (3,2) will not be inserted. How can i check it to keep data integrity.
  16. How can i design facebook like users,friends database? Someone please post the database schema. One user has many friends.
  17. In friend table, select user_id,friend_id from friends where user_id=2; Here, (2,3) and (2,4) . But (3,2) is same as (2,3) and (4,2) is same as (2,4) . Both are friends. How do/did you handle this?
  18. Can't understand the query. Can you please explain more(elaborate) with example ?
  19. Are != and <> same in mysql? Please post some examples.
  20. What is the difference between IS NULL and =NULL? SELECT * FROM user,course WHERE user.course is NULL; SELECT * FROM user,course WHERE user.course=NULL; Tables information is here: http://www.sitepoint.com/understanding-sql-joins-mysql-database/
  21. How can i write a query: select from table where a pair of record is not there? mysql> describe users;+-------------+---------------------+------+-----+---------+----------------+| Field | Type | Null | Key | Default | Extra |+-------------+---------------------+------+-----+---------+----------------+| id | bigint(20) unsigned | NO | PRI | NULL | auto_increment || username | varchar(255) | YES | | NULL | || password | varchar(255) | YES | | NULL | || email | varchar(255) | YES | | NULL | || email_token | varchar(255) | NO | | NULL | || is_active | tinyint(1) | YES | | NULL | || created | datetime | YES | | NULL | || modified | datetime | YES | | NULL | |+-------------+---------------------+------+-----+---------+----------------+8 rows in set (0.00 sec)mysql> describe friends;+-----------+---------------------+------+-----+---------+----------------+| Field | Type | Null | Key | Default | Extra |+-----------+---------------------+------+-----+---------+----------------+| id | bigint(20) unsigned | NO | PRI | NULL | auto_increment || user_id | bigint(20) unsigned | YES | | NULL | || friend_id | bigint(20) unsigned | YES | | NULL | || created | datetime | YES | | NULL | || modified | datetime | YES | | NULL | |+-----------+---------------------+------+-----+---------+----------------+5 rows in set (0.01 sec) How can i get all users where a user id not equal to login_user_id and this user_id and friend_id pair is missing in friends table? That means they are not friends. Thanks in advance.
  22. php crypt with same salt returns same crypted string, why? $crypted_withq = crypt('12345678q','salt'); $crypted_withoutq = crypt('12345678', 'salt'); echo $crypted_withq; echo '<br/>'; echo $crypted_withoutq; It returns same output. saX6EvfO393Go saX6EvfO393Go How can i store different crypted password in database with php?
  23. $sql = "UPDATE books SET title=?, author=? WHERE id=?"; $q = $conn->prepare($sql); $q->execute(array($title,$author,$id)); UPDATE `access_users` SET `contact_first_name` = :firstname, `contact_surname` = :surname, `contact_email` = :email, `telephone` = :telephone WHERE `user_id` = :user_id Which one is better to follow and why is that better?
  24. Would the code's from address and sendmail from address be the same?
×
×
  • 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.