samoi Posted October 17, 2009 Share Posted October 17, 2009 Hello guys! My idea is to pull private messages to the user using PHP from MySQL, then when the user click on <div> element, then it should fadeIn() the message for him. Let's see it in action: <script type="text/javascript"> $(document).ready(function(){ $("#subj").click(function(){ $("#msgBox").css('display', 'inline').fadeIn(3000); }); } }); </script> <? // PHP code! // query to get the messages! $SQL = mysql_query("SELECT * FROM msg WHERE to_id = '".$userid."' AND `read` = \"0\"")or die(mysql_error()); // loop and pull more msgs ! while($row = mysql_fetch_array($SQL)){ // Only a function to get the username instead of user id! do not see it! $sender = sender($row["from_id"],$row["to_id"] ); // Out put format! echo 'From: '.$sender[0].' |,| And To '.$row["to_id"].' |,| subject! is:'; // Subject here! look in it has span id of *SUBJ* ! echo '<span id="subj"><font color="red">'.$row["subj"].'</font></span>'; // The Private message! echo '<span id="msgBox" style="display:none;">'.$row["msg"].'</span>'; } ?> This couldn't work! it only works with the *FIRST* record of private messages! But doesn't with the second message! Help would be appreciated! Quote Link to comment Share on other sites More sharing options...
cbolson Posted October 17, 2009 Share Posted October 17, 2009 Hi there, I can't help you much with the actual jquery code but your problem is probably due to the fact that you are using a non-unique "id" for the hidden messages. ie. all the messages (and subject spans) have the same id so the javascript is only ever going to address the first one that it finds. You are going to have be more creative with your naming (eg use the item $row["to_id"]) both for the subject span and the message span then, in your javascript (jquery) extract this value from the subject span when clicked to know which message you want to expand. As I say, I am not hot on jquery but you could do something this like this: $(".subjects").click(function(){ // get rel value (this will be the id) msg_id=attr("id"); // not quite sure how you get the element id in jquery, in mootools you can just use "this.id" $("#msgBox_"+msg_id+"").css('display', 'inline').fadeIn(3000); }); and the code in your while loop could look like this: while($row = mysql_fetch_array($SQL)){ // Only a function to get the username instead of user id! do not see it! $sender = sender($row["from_id"],$row["to_id"] ); // Out put format! echo 'From: '.$sender[0].' |,| And To '.$row["to_id"].' |,| subject! is:'; // Subject here! look in it has span id of *SUBJ* ! echo '<span id="'.$row["to_id"].'" class="subjects"><font color="red">'.$row["subj"].'</font></span>'; // The Private message! echo '<span id="msgBox_'.$row["to_id"].'" style="display:none;">'.$row["msg"].'</span>'; } Not sure if my code will work but hopefully you will get the idea of how it could be done. Chris Quote Link to comment Share on other sites More sharing options...
samoi Posted October 17, 2009 Author Share Posted October 17, 2009 Hi there, I can't help you much with the actual jquery code but your problem is probably due to the fact that you are using a non-unique "id" for the hidden messages. ie. all the messages (and subject spans) have the same id so the javascript is only ever going to address the first one that it finds. You are going to have be more creative with your naming (eg use the item $row["to_id"]) both for the subject span and the message span then, in your javascript (jquery) extract this value from the subject span when clicked to know which message you want to expand. As I say, I am not hot on jquery but you could do something this like this: $(".subjects").click(function(){ // get rel value (this will be the id) msg_id=attr("id"); // not quite sure how you get the element id in jquery, in mootools you can just use "this.id" $("#msgBox_"+msg_id+"").css('display', 'inline').fadeIn(3000); }); and the code in your while loop could look like this: while($row = mysql_fetch_array($SQL)){ // Only a function to get the username instead of user id! do not see it! $sender = sender($row["from_id"],$row["to_id"] ); // Out put format! echo 'From: '.$sender[0].' |,| And To '.$row["to_id"].' |,| subject! is:'; // Subject here! look in it has span id of *SUBJ* ! echo '<span id="'.$row["to_id"].'" class="subjects"><font color="red">'.$row["subj"].'</font></span>'; // The Private message! echo '<span id="msgBox_'.$row["to_id"].'" style="display:none;">'.$row["msg"].'</span>'; } Not sure if my code will work but hopefully you will get the idea of how it could be done. Chris You are awesome ! and genius!! Great thinking! Thank you very much! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.