colap
Members-
Posts
302 -
Joined
-
Last visited
Everything posted by colap
-
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.
-
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.
-
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?
-
Button is not necessary if there is not more data. No more code.
-
<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?
-
<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.
-
How can i write a query: select from table where a pair of record is not there?
colap replied to colap's topic in MySQL Help
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 ? -
How can i write a query: select from table where a pair of record is not there?
colap replied to colap's topic in MySQL Help
What will be the sql query with NOT EXISTS to get the same result? Can you paste the sql query here? -
How can i write a query: select from table where a pair of record is not there?
colap replied to colap's topic in MySQL Help
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. -
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.
-
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?
-
How can i write a query: select from table where a pair of record is not there?
colap replied to colap's topic in MySQL Help
If there is (2,3) then it will not insert (3,2). Do i have to check this programmatically? -
How can i write a query: select from table where a pair of record is not there?
colap replied to colap's topic in MySQL Help
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? -
How can i write a query: select from table where a pair of record is not there?
colap replied to colap's topic in MySQL Help
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. -
How can i design facebook like users,friends database? Someone please post the database schema. One user has many friends.
-
How can i write a query: select from table where a pair of record is not there?
colap replied to colap's topic in MySQL Help
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? -
How can i write a query: select from table where a pair of record is not there?
colap replied to colap's topic in MySQL Help
Can't understand the query. Can you please explain more(elaborate) with example ? -
Are != and <> same in mysql? Please post some examples.
-
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/
-
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.
-
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?
-
$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?
-
Would the code's from address and sendmail from address be the same?
-
sendmail server configurations?