nightkarnation Posted August 21, 2008 Share Posted August 21, 2008 Hey! I have a dumb question (i guess it is) for a query result...can i change the variable name of $cant ??? because i have a double for loop inside a function in flash, and both are retrieving the same $cant values when they have to retrieve different ones... for ex here one of the 2 query results which im using the $cant: $result = mysql_query("SELECT chat, messageTime FROM chat WHERE messageTime > '$connectedMinute' ORDER BY `chat`.`messageTime` DESC"); $cant = 0; while($row=mysql_fetch_array($result)){ echo "chat$cant=$row[chat]&messageTime$cant=$row[messageTime]&"; $cant++; } echo "cant=$cant"; (i tried with another random variable name instead of $cant...but when i do that, it doesnt receive the information from mysql) Any ideas and/or solutions? Thanx in advance for the help! Cheers, Quote Link to comment Share on other sites More sharing options...
mmarif4u Posted August 21, 2008 Share Posted August 21, 2008 I think it should work. try $x. Quote Link to comment Share on other sites More sharing options...
nightkarnation Posted August 21, 2008 Author Share Posted August 21, 2008 Nope, nothing Quote Link to comment Share on other sites More sharing options...
nightkarnation Posted August 21, 2008 Author Share Posted August 21, 2008 Bump, anyone please ? Quote Link to comment Share on other sites More sharing options...
akitchin Posted August 21, 2008 Share Posted August 21, 2008 what do you mean by "nothing?" what exactly isn't working? that single line of code should work fine if you substitute $x in for $cant instead: $result = mysql_query("SELECT chat, messageTime FROM chat WHERE messageTime > '$connectedMinute' ORDER BY `chat`.`messageTime` DESC"); $x = 0; while($row=mysql_fetch_array($result)){ echo "chat$x=$row[chat]&messageTime$x=$row[messageTime]&"; $x++; } echo "cant=$x"; if that doesn't work how you want it, we'll need to see more code, because it's obviously somewhere else that's causing the issue. Quote Link to comment Share on other sites More sharing options...
nightkarnation Posted August 21, 2008 Author Share Posted August 21, 2008 Flash Code: this is the for loop that has nothing to do but it could be useful since its interfering with the below for loop: for (var i = 0; i<this.cant; i++) { txtUsersConnected.text = txtUsersConnected.text+this["user_id"+i]+newline; } for (var e = 0; e<this.cant; e++) { txtChat.text = txtChat.text+this["chat"+e]+newline; trace(e); //e always reads the value from the for loop that is above this code which is retrieving another information trace(content_lv.chat1); //this is actually working! so its getting the $chat information from php } But if i try now with the new suggested x for (var e = 0; e<this.x; e++) { txtChat.text = txtChat.text+this["chat"+e]+newline; trace(e); //e is not giving any value trace(content_lv.chat1); //not giving any value } Quote Link to comment Share on other sites More sharing options...
akitchin Posted August 21, 2008 Share Posted August 21, 2008 it's still assigning the value to cant. if you want that individual loop to change the variable name, you'll have to change the echo too: echo "x=$x"; Quote Link to comment Share on other sites More sharing options...
nightkarnation Posted August 21, 2008 Author Share Posted August 21, 2008 Did that, still not working :-\ :'( Any other idea of what it could be? Thanx for the help akitchin Quote Link to comment Share on other sites More sharing options...
akitchin Posted August 21, 2008 Share Posted August 21, 2008 we will need to see trace() - 'e' is correct in that for() loop, so it's not a variable problem (or shouldn't be). change everything back to use cant as it was at the start, and show us trace(). we'll start over again. Quote Link to comment Share on other sites More sharing options...
nightkarnation Posted August 21, 2008 Author Share Posted August 21, 2008 Ok, let me explain something to better understand the goal here... txtChat.text should display the messages that have been stored in mysql only from 1 minute ago to now thats why: WHERE messageTime > '$connectedMinute' (this is working just fine) Ok flash info: for (var e = 0; e<this.cant; e++) { txtChat.text = txtChat.text+this["chat"+e]+newline; trace(e); trace(content_lv.chat0); trace(content_lv.chat1); trace(content_lv.chat2); } (in this example...mysql had 4 msgs stored in less than 1 minute ago) if there are no msgs stored in less than a minute...content_lv.chat0 will be undefined, which is perfect. Flash Trace output: 0 USERNAME: tester USERNAME: test USERNAME: testing (Note that its giving 0 because there is only 1 user connected...if there were 2, e will be = 1) would be the same but: 1 USERNAME: tester USERNAME: test USERNAME: testing This is because as i said before is retrieving the value from: for (var i = 0; i<this.cant; i++) { txtUsersConnected.text = txtUsersConnected.text+this["user_id"+i]+newline; } Im guessing its the this.cant from the e for() loop, but whenever i change this on php and flash, it just doesnt work Hope this info helps, let me know if i wasnt clear in any aspect Quote Link to comment Share on other sites More sharing options...
akitchin Posted August 21, 2008 Share Posted August 21, 2008 this is still fairly muddy, but it might just be me. let's say you have four messages, that means cant should come back as 3. that will assign users this[user_id0], this[user_id1], this[user_id2], this[user_id3] to the usersConnected text. it will also assign this[chat0], this[chat1], this[chat2], this[chat3] to the txtChat text. at least, it SHOULD - is that not what's happening, and if it IS happening, what's wrong with that? my apologies if i'm not understanding properly. Quote Link to comment Share on other sites More sharing options...
nightkarnation Posted August 21, 2008 Author Share Posted August 21, 2008 Yes...what ur saying there u perfectly understood, and yes...it is happening and working that way... BUT...here's the thing, I dont really want that to happen... I want and need this[chat0], this[chat1], this[chat2], this[chat3] to the txtChat text to have the values from the e for() loop...not from the i for() loop And right now...since this.cant is the same in both loops... its giving the same value to both i & e, so its actually giving the value of how many users are connected instead of how many msgs were saved in less than the actual minute. So here's the thing...the problem might still be on php, Here is the complete relevant php code: This one here is the one that i tried with $x ... and when i try that...it doesnt work $connectedMinute = time() - 100; //INFORMATION APARTE - SENDS LAST CHAT and messageTime FROM MYSQL DATABASE to FLASH (hacer nuevo: solamente los que estan bajo el minuto de conectados) $result = mysql_query("SELECT chat, messageTime FROM chat WHERE messageTime > '$connectedMinute' ORDER BY `chat`.`messageTime` DESC"); $cant = 0; while($row=mysql_fetch_array($result)){ echo "chat$cant=$row[chat]&messageTime$cant=$row[messageTime]&"; $cant++; } echo "cant=$cant"; Here's the code concerning to retrieve which users are connected (this works perfect) $result = mysql_query("SELECT user_id, lastConnection FROM tbl_auth_user WHERE lastConnection > '$lastRange'"); $cant = 0; while($row=mysql_fetch_array($result)){ echo "user_id$cant=$row[user_id]&lastConnection$cant=$row[lastConnection]&"; $cant++; } echo "cant=$cant"; } So here u can see the conflict of having two $cant Quote Link to comment Share on other sites More sharing options...
akitchin Posted August 21, 2008 Share Posted August 21, 2008 i see - so the second block grabs all the users, the first block grabs all the messages. try changing the php block for the users to this: $result = mysql_query("SELECT user_id, lastConnection FROM tbl_auth_user WHERE lastConnection > '$lastRange'"); $usrs = 0; while($row=mysql_fetch_array($result)){ echo "user_id$usrs=$row[user_id]&lastConnection$usrs=$row[lastConnection]&"; $usrs++; } echo "usrs=$usrs"; } then change the for() loop for the users to this: for (var i = 0; i<this.usrs; i++) { txtUsersConnected.text = txtUsersConnected.text+this["user_id"+i]+newline; } see if that helps you out. by the by, time() - 100 will access all messages in the last 1:40, not the last minute. Quote Link to comment Share on other sites More sharing options...
nightkarnation Posted August 21, 2008 Author Share Posted August 21, 2008 God im going loco... Ok...tried ur new code...usrs works great... But the e for() loop with the this.cant ... its not working! why???? Its not even entering/doing the loop...no trace results if i trace (i) to check usrs...works great. tracing (e) nothing at all... Quote Link to comment Share on other sites More sharing options...
akitchin Posted August 21, 2008 Share Posted August 21, 2008 could it be that the for() loop using 'i' is never-ending? maybe post your current code, both the PHP blocks and the flash blocks. Quote Link to comment Share on other sites More sharing options...
nightkarnation Posted August 21, 2008 Author Share Posted August 21, 2008 PHP: //mandar actual horario en el cual el usuario esta conectado - USER ONLINE OR OFFLINE INFORMATION if ($action == "lastConnection") { mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("learning") or die(mysql_error()); $name=$_POST['name']; $time = time(); //send new user time connection mysql_query("UPDATE `tbl_auth_user` SET lastConnection = '$time' WHERE user_id = '$name'"); //RETRIEVE LAST CONNECTION FROM USER FROM DATABASE/MYSQL $s = mysql_query("SELECT lastConnection FROM tbl_auth_user WHERE user_id = '$name'"); while($r=mysql_fetch_row($s)){ $last = $r[0]; } $connectedMinute = time() - 100; //SEND LAST CHAT and messageTime FROM MYSQL DATABASE to FLASH (hacer nuevo: solamente los que estan bajo el minuto de conectados) $result = mysql_query("SELECT chat, messageTime FROM chat WHERE messageTime > '$connectedMinute' ORDER BY `chat`.`messageTime` DESC"); $cant = 0; while($row=mysql_fetch_array($result)){ echo "chat$cant=$row[chat]&messageTime$cant=$row[messageTime]&"; $cant++; } echo "cant=$cant"; //-USER CONNECTION, IF RECENT OR NOT $range = time()-600; if($range < $last){ //hacer un valor del ultimo horario - 600, asi abarcan solamente los usuarios activos $lastRange = $last - 100; //--------- echo "User is online!"; echo "&connected=".'You Are Online: ' .$name."&"; } else { echo "User is offline!"; echo "&connected=".'You Are Offline'."&"; } //DISPLAY ONLY RECENT CONNECTIONS USER NAMES: $result = mysql_query("SELECT user_id, lastConnection FROM tbl_auth_user WHERE lastConnection > '$lastRange'"); $usrs = 0; while($row=mysql_fetch_array($result)){ echo "user_id$usrs=$row[user_id]&lastConnection$usrs=$row[lastConnection]&"; $usrs++; } echo "usrs=$usrs"; } FLASH CODE: function lastConnection() { //LOAD INFORMATION EVERY 1 SECOND, diciendo el time() del usuario content_lv.action = "lastConnection"; content_lv.name = myUserId; content_lv.sendAndLoad("http://localhost/Test/phpAndMysql/flash%20user%20admin%201.4/login.php", content_lv, "POST"); //ACA RETRIEVES INFORMATION content_lv.onLoad = function(succes) { if (succes) { trace("looping funcionando"); //avisa si el usuario esta conectado o no txtStatus.text = content_lv.connected; //Cada vez que carga los users...que limpie el txt asi no se repiten los users txtUsersConnected.text = ""; //LOAD user_id connectados for (var i = 0; i<this.usrs; i++) { txtUsersConnected.text = txtUsersConnected.text+this["user_id"+i]+newline; } //RETRIEVE CHAT TEXT: txtChat.text = ""; for (var e = 0; e<content_lv.cant; e++) { txtChat.text = txtChat.text+this["chat"+e]+newline; trace(e); trace(content_lv.chat0); trace(content_lv.chat1); trace(content_lv.chat2); } } }; } var nInterval:Number = setInterval(lastConnection, 1000); Hope this helps to decipher whats going wrong Quote Link to comment Share on other sites More sharing options...
akitchin Posted August 21, 2008 Share Posted August 21, 2008 i would assume that it's because this line: for (var e = 0; e<content_lv.cant; e++) { should have this.cant, rather than content_lv.cant. Quote Link to comment Share on other sites More sharing options...
nightkarnation Posted August 21, 2008 Author Share Posted August 21, 2008 oh yeah sorry...i've always had this.cant i was just trying that... sorry, still, not working Quote Link to comment Share on other sites More sharing options...
akitchin Posted August 21, 2008 Share Posted August 21, 2008 try adding an ampersand (&) to the end of the cant echo, like so: echo "cant=$cant&"; it could be that you're just completely overriding those variables. Quote Link to comment Share on other sites More sharing options...
nightkarnation Posted August 21, 2008 Author Share Posted August 21, 2008 sweet !! It was that afterall we went through... Thanx so much man! I really appreciate your help and patience Cheers bro !! 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.