Jump to content

zac1987

Members
  • Posts

    37
  • Joined

  • Last visited

    Never

Everything posted by zac1987

  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?
  15. May I ask another question? Note that 3 of my dropdown menu has array on its name, eg : <select name="dropdown[1]"> $query2 = "SELECT * FROM messages"; $result2 = mysql_query($query2,$connection) or die (mysql_error()); confirm_query($result2); while($userinfo = mysql_fetch_array($result2)){ echo "<select name=\"dropdown[]\">"; } If I have 10 rows of records on the database, I want the php auto creating 10 dropdown menus with the name=dropdown[1] to dropdown[10], how to do that? Is it I need to use for loop $i = 1, $i <=10, $i++ then put name=dropdown[$i] ? But if I put the for loop inside the while loop, it will create 30 dropdown menus, seriously I don't know how to do that... Or can I do something like this? $count=0; while($userinfo = mysql_fetch_array($result2)){ $count=$count + 1; echo "<select name=\"dropdown[$count]\">"; }
  16. I have 3 dropdown menus which have the same name <select name="dropdown">, how to get the value from 3 of them by using php for loop and array? I did try to put array on them before, but seem it can't work. My codes : <?php for ( $counter = 1; $counter <= 3; $counter ++) { if (isset($_POST['submit'])) { //Form has been submitted. $dropvalue = $_POST['dropdown[$counter]']; echo $dropvalue; } } ?> <form action="test8.php" name="frmtest8" method='post'> <select name="dropdown[1]"> <option value="1st">first</option> <option value="2nd">second</option> <option value="3rd">third</option> </select> <select name="dropdown[2]"> <option value="1st">first</option> <option value="2nd">second</option> <option value="3rd">third</option> </select> <select name="dropdown[3]"> <option value="1st">first</option> <option value="2nd">second</option> <option value="3rd">third</option> </select> <input type="submit" name="submit" value="Send" /> </form> It gives error message Parse error: parse error in C:\wamp\www\plekz\test8.php on line 23 I guess the error is because of $_POST['dropdown[$counter]']; I cannot put the two symbols [] inside $_POST[' '] right? How to call the array if cannot put the two symbols?
  17. I want to convert this url www.2aek.com/userprofile.php?username=zac1987 into www.2aek.com/zac1987 How to do that? I google search "dns setup vanity url" but I can't find any result. After I change it to vanity url, the php get method still can function without any problem?
  18. My god, I took many hours to understand your codes. Finally I understand that. It works perfectly for me now. Thank you. You are the smartest person that I ever seen. Thank you so much.
  19. Is it I need to write $len1 until $len1000 manually? $len1 = 3; $len2 = 6; $len3 = 9; $len4 = 12; $len5 = 15; ..... $len1000 = 3000; since all data below are +3, +3, +3 Can I use for loop to assign the value for $len1 to $len1000? for ($i=3; $i<=3000; $i+3) { echo $len . $i .... er, I don't know how to write it.
  20. Finally I know why you do num/3, because u though I just want 3 columns. Haha. Actually I want 1000 columns. I have edit your codes to : $len1 = 3; $len2 = 6; $len3 = 9; $len4 = 12; $len5 = 15; while($userinfo = mysql_fetch_array($result2)){ $lastid=$userinfo['id']; if($count==$len1){$top=80; $left=200;} if($count==$len2){$top=30; $left=400;} if($count==$len3){$top=80; $left=600;} if($count==$len4){$top=30; $left=800;} if($count==$len5){$top=80; $left=1000;} It works perfect for me!!! Thanks again for your guidance, I really appreciate it. Thanks.
  21. I just change the value of left : if($count==$len1){$top=80; $left=200;} if($count==$len2){$top=30; $left=400;} Then I saw the 3 columns already!!! Thank you!!! So if I want to add another new column (4th column), I just need to write something like this? $len3 = $len2 + floor($num/3); if($count==$len3){$top=30; $left=600;} It is okay, I go try it now, thanks anyway Thank you guru Sasa.
  22. I used firebug to detect the 1st div, then i just realize the 1st div is at the back of the 5th div, which mean the 5th div is cover on top of 1st div, so I can't see the 1st div, which mean they both divs are at the same left and same top.
  23. How you do the "when 1st column is full go to 2nd column" ? How you know when the 1st column is full? I have 16 rows of records on database. When I use your codes, first 5 records are not displayed. It starts display the result from 6th record. I echo out the value of count, len1 and len2 of every process and the output is : count=1, len1=6, len2=11. count=2, len1=6, len2=11. count=3, len1=6, len2=11. count=4, len1=6, len2=11. .... count=16, len1=6, len2=11. my database has 16 records, so len1=ceil(16/3)=6 len2=6+floor(16/3)=11 if($count==$len1){$top=30; $left=10;} if($count==$len2){$top=80; $left=200;} So it mean if $count==6, then only execute the code. That's why it fail to display the first 5 records on my database. Why you use num/3? but not num/2 or num/5?
×
×
  • 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.