Jump to content

zac1987

Members
  • Posts

    37
  • Joined

  • Last visited

    Never

About zac1987

  • Birthday 06/02/1987

Contact Methods

  • MSN
    gage_ang@hotmail.com

Profile Information

  • Gender
    Male
  • Location
    Malaysia

zac1987's Achievements

Member

Member (2/5)

0

Reputation

  1. Finally finish reading the article u linked. I took few days to read the article, so many terms that didn't understand until I google search for more info. I will normalize my database. Thanks for sharing and helping.
  2. My system doesn't allow user to have same username with other user, and user cannot change/modify username, so unique username is just the same as unique auto increment user_id, so unique username can actually act like auto increment user_id, so username can be foreign key. I don't need to add a column to messages table for user's join date info, because user table already has the column for user's join date. Normally we don't show user's join date on messaging section, we only show user's join date on user profile section. In user profile, I just user normal MySQL query to retrieve username, user-full-name, age, photo and join date info from user table. No need to use JOIN. I save username instead of user_id onto message table can faster the query since no need to JOIN user table, the username act like foreign key. No harm at all. Regarding removes redundancies, store user_id in message table has redundancies too, there will be many duplicated user_id in message table. So there is no different if I store many duplicated username. Both user_id and username are also redundancies. Thus removes redundancies is not a point to convince me to store user_id instead of username in message table. Wow, normally in this case I will get all emails from database, then use javascript to check which are allowed. Your reverse IN function make it easier and save query resource, cool stuff. Thanks for sharing. Just curious why don't you block all unallowed_email at first place? Just pop up a message "sorry, your email is incorrect", then don't store his email onto your database.
  3. May I know why should save id of user instead of username? For me, it is easy to know who is the user by looking at his username in table in database, and it save 1 more step when I want to show the username, I don't need to query user table anymore since friend table has the username already. I have tested it, it works! WOW. I never know IN can function like this, learn a good stuff from u, thanks.
  4. Perfect. It works like charm. Thank you very much. Anyway, your codes has some error which GROUP BY must appear before ORDER BY. May I know why my table suck?
  5. Basically I just want to show my posts and my friends' posts on to website. Please refer to the 2 tables from the picture below : Codes : <?php $username1 = "zac1987"; $query41 = "SELECT p.message FROM friendship f JOIN messageslive p ON p.username = f.frenusername OR p.username = f.username WHERE f.frenusername = '{$username1}' ORDER BY p.id DESC LIMIT 0,16"; $result41 = mysql_query($query41,$connection) or die (mysql_error()); confirm_query($result41); while($msginfo = mysql_fetch_assoc($result41)){ $msg = $msginfo['message']; echo $msg . "<br/>"; } ?> Output : Problem 1 - It shows 3 x duplicated zac1987's post because there are 3 of "zac1987" in the field of "frenusername" in friendship table. How to fix it? Problem 2 - when I change $username1 == "zac1987" to $username1 == "micellelimmeizheng1152013142", output is blank. How to fix it?
  6. WOW, I never knew can codes like that, nice work. Some people said UNION is faster than OR. That's why I use UNION.
  7. Both field frenusername and username have "zac1987". So I need to use UNION to SELECT frenusername WHERE username="zac1987" and SELECT username WHERE frenusername="zac1987". But the UNION can't give the output that I want. I guess I need to read the rules of using UNION.
  8. because it will include "zac1987" on the output. For example, if $username2 = "zac1987", "SELECT frenusername, username FROM friendship WHERE frenusername='{$username2}' ";, the output will include "zac1987" as you SELECT frenusername.
  9. Here is my table records : username | frenusername --------------------------------- zac1987 | qq zac1987 | bb uu | zac1987 oo | zac1987 The value of $username2 is "zac1987". Supposedly $frenusername2 hold value of "uu" and "oo". I don't know why it fail to hold the value, it is holding empty value now.
  10. $query120 = "SELECT frenusername FROM friendship WHERE username='{$username2}' UNION SELECT username FROM friendship WHERE frenusername='{$username2}' "; $result120 = mysql_query($query120,$connection) or die (mysql_error()); confirm_query($result120); while($userinfo120 = mysql_fetch_array($result120)){ $frenusername= $userinfo120['frenusername']; $frenusername2= $userinfo120['username']; // why this hold empty value? echo $frenusername2; } May I know why $frenusername2 is holding empty value?
  11. I want to reduce a picture size from 600px * 500px to 60px * 50px size, then crop it become 50px *50px. I have two groups of codes, 1 is to reduce the size of image, other 1 is to crop the image. The problem is they works separately, how to combine this two groups of codes to make them work together? Below is my codes : <?php //codes of group A - Reduce the size of image from 600px * 500px to 60px * 50px $save2 = "images/users/" . $image_name_2; //This is the new file you saving list($width2, $height2) = getimagesize($file) ; $modwidth2 = 50; $diff2 = $width2 / $modwidth2; $modheight2 = $height2 / $diff2; $tn2 = imagecreatetruecolor($modwidth2, $modheight2) ; $image2 = imagecreatefromjpeg($file) ; imagecopyresampled($tn2, $image2, 0, 0, 0, 0, $modwidth2, $modheight2, $width2, $height2) ; imagejpeg($tn2, $save2, 100) ; //codes of group B - Crop the image from 60px * 50px to 50px * 50px $save3 = "images/users/" . $image_name_3; list($width3, $height3) = getimagesize($file) ; $modwidth3 = 60; $diff3 = $width3 / $modwidth3; $modheight3 = $height3 / $diff3; $left = 0; $top = 0; $cropwidth = 50; //thumb size $cropheight = 50; $tn3 = imagecreatetruecolor($cropwidth, $cropheight) ; $image3 = imagecreatefromjpeg($file) ; imagecopyresampled($tn3, $image3, 0, 0, $left, $top, $cropwidth, $cropheight, $modwidth3, $modheight3) ; imagejpeg($tn3, $save3, 100) ; //save the cropped image ?> As you can see from 2 groups of codes above, 1st group resize the pic then save it to a folder. 2nd group of codes crop the pic then save it into the folder too. My question is ... After 1st group of codes resize the picture, is it necessary to save it into folder before I can crop it? If it is necessary, then I need to write new lines of codes to retrieve the resized pic from the folder for 2nd group of codes to crop it? If it is not necessary, after resizing the pic, how do I pass the pic to 2nd group of codes to crop it? php image-resizing
  12. so my real problem is the conflict between the two features below : 1) feature of reload page for every 10 seconds to get new records. 2) feature of get older records when user scroll down to the page. Because both features above are depend on the same variable $last_msg_id, how can I solve the conflict between the two features?
  13. I guess session is not what I need. My problem is not remind value of variable when refreshing the page. Let me explain my problem : Let's say I have 10 records on database. At first, display latest 3 records at beginning, so the value of $last_msg_id should be 8. Then user scroll down to the page, the page will display 2 older records which has id of 7 and 6, so the value of $last_msg_id should be 6. Then user scroll down again, value of $last_msg_id should be 4. After 10 seconds, the page reload, currently the value of $last_msg_id is still remain as 4. But when it auto call message1.php to get 3 of the latest records, the value of $last_msg_id become be 8. So when user scroll down again to get 2 older records, it will shows the same records as previously which has id of 7 and 6. It is wrong, the user already scrolled down for 3 times, so the page should show the records which have id of 3 and 2. 1st time scroll = 7,6 2nd time scroll = 5,4 3rd time scroll = 3,2
  14. Twitter chat features : 1) use ajax to reload the page to get new data from database for every 10 seconds, 2) When the user scroll down to the bottom of page, it load the older 5 data from database. I have 3 files (index.php, message1.php and message2.php) On index.php, I use ajax to reload the page for every 10 seconds to call a php file (message1.php). On message1.php, I use mysql to retrieve 30 records from database and php to display the records to the index.php. ($last_msg_id to hold the id of last data in message1.php, then send the $last_msg_id to index.php) When user scroll down to bottom of the page, it will auto call other php file (message2.php) to display older 5 records from database. (index.php will send $last_msg_id_id to message2.php, so that message2.php will know which was the last data previously and display the older data where id is less than $last_msg_id, eg : $query2 = "SELECT id, message, datetime FROM messages WHERE id < '$last_msg_id' LIMIT 5"; Now my problem is when the ajax reload the index.php, the value of $last_msg_id is become empty. So if the user is on the half way scrolling to bottom of page to get older data, the older data will not show up, it will show up the previous data because the value of $last_msg_id is back to empty after page is reloaded by ajax. May I know how to fix this problem please? Maybe I should not reload the page for every 10 seconds to get new data? If without reload the page, how am I going to get new data when his friends posted new messages on other side?
×
×
  • 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.