PC Nerd Posted April 5, 2007 Share Posted April 5, 2007 um, i get that its expecting an ";" on the while loop line, do{ $Login = mysqli_fetch_array($Login_Query); $Latest_time = $Login['Logged_In']; } while($Login = mysqli_fetch_array($Login_Query)) { if($Latest_time < $Login['Logged_In']) { $Login_ID = $Login['Login_ID']; } } there is it meant to go??? ive highlited the line where the ";" is expected. thanks in advance, PC Nerd Link to comment https://forums.phpfreaks.com/topic/45806-query-looping-with-while-simply-question/ Share on other sites More sharing options...
almightyegg Posted April 5, 2007 Share Posted April 5, 2007 {color] I have no idea what that's about but I'm sure that's the problem Link to comment https://forums.phpfreaks.com/topic/45806-query-looping-with-while-simply-question/#findComment-222530 Share on other sites More sharing options...
PC Nerd Posted April 5, 2007 Author Share Posted April 5, 2007 there you go, thankx whats wrong do you think? Link to comment https://forums.phpfreaks.com/topic/45806-query-looping-with-while-simply-question/#findComment-222535 Share on other sites More sharing options...
almightyegg Posted April 5, 2007 Share Posted April 5, 2007 color] looks like the second half of a variable, it won't work on it's own and hasn't been given an instruction therefore will cause errors... remove that and it should work Link to comment https://forums.phpfreaks.com/topic/45806-query-looping-with-while-simply-question/#findComment-222537 Share on other sites More sharing options...
PC Nerd Posted April 5, 2007 Author Share Posted April 5, 2007 i dont understand????? Link to comment https://forums.phpfreaks.com/topic/45806-query-looping-with-while-simply-question/#findComment-222538 Share on other sites More sharing options...
gluck Posted April 5, 2007 Share Posted April 5, 2007 {color] <- right here Link to comment https://forums.phpfreaks.com/topic/45806-query-looping-with-while-simply-question/#findComment-222540 Share on other sites More sharing options...
PC Nerd Posted April 5, 2007 Author Share Posted April 5, 2007 um ok ive changed the post and i cant see that anywhere. ive fixed that and now only the error line is highlited blue. if you cant see it properly, then let me know, and ill repost the code..... Link to comment https://forums.phpfreaks.com/topic/45806-query-looping-with-while-simply-question/#findComment-222541 Share on other sites More sharing options...
kenrbnsn Posted April 5, 2007 Share Posted April 5, 2007 I think PHP is getting very confused with how you wrote the loop. Try this instead: <?php while($Login = mysqli_fetch_array($Login_Query)) { $Latest_time = $Login['Logged_In']; if($Latest_time < $Login['Logged_In']) $Login_ID = $Login['Login_ID']; }?> But looking at the above, the logic doesn't make any sense. What are you trying to accomplish? Ken Link to comment https://forums.phpfreaks.com/topic/45806-query-looping-with-while-simply-question/#findComment-222546 Share on other sites More sharing options...
PC Nerd Posted April 5, 2007 Author Share Posted April 5, 2007 im looping through all your logins, to determine what the most recent login time is. then storing it Link to comment https://forums.phpfreaks.com/topic/45806-query-looping-with-while-simply-question/#findComment-222555 Share on other sites More sharing options...
kenrbnsn Posted April 5, 2007 Share Posted April 5, 2007 What format is the login date/time stored in? If it's not a UNIX time stamp, then a simple comparison won't work. Try this code (it assumes the login date/time is stored as "YYYY-MM-DD HH:MM:00") <?php $current_time = time(); // get the current time as a UNIX Timestamp $most_recent = 0; // initialize to earliest possible login time while($Login = mysqli_fetch_array($Login_Query)) { $Latest_time = strtotime($Login['Logged_In']); if(($current_time - $Latest_time) < ($current_time - $most_recent)) { $most_recent = $Latest_time; $Login_ID = $Login['Login_ID']; } }?> Ken Link to comment https://forums.phpfreaks.com/topic/45806-query-looping-with-while-simply-question/#findComment-222571 Share on other sites More sharing options...
PC Nerd Posted April 5, 2007 Author Share Posted April 5, 2007 that wont work. i am storing all login details in a database first it write a new"login record, with a unique login id. but what i want to do is to find the most recent login ( ie the one that just happened ) so thatg i can store the login id in a cookie, so that i can easily pass the database throughout the members are, if theres a better way of doing this, then please tell me. i originally wanted to just use cookies, but i want to store how much time a use is logged in for, so this is the best the database field is a timestampe, and is default to the the surrent timestamp, ie, NOW, but when we try to get that recond out again acording to timestamp, the timestamp will be different becausae of the number of milli seconds......... if theres a better way, or my plan is completely screwed up, please let me know thanks for your help, PC Nerd Link to comment https://forums.phpfreaks.com/topic/45806-query-looping-with-while-simply-question/#findComment-222582 Share on other sites More sharing options...
PC Nerd Posted April 5, 2007 Author Share Posted April 5, 2007 does anyone else have any suggestions????? Link to comment https://forums.phpfreaks.com/topic/45806-query-looping-with-while-simply-question/#findComment-222613 Share on other sites More sharing options...
PC Nerd Posted April 6, 2007 Author Share Posted April 6, 2007 anymore ideas??? Link to comment https://forums.phpfreaks.com/topic/45806-query-looping-with-while-simply-question/#findComment-222718 Share on other sites More sharing options...
PC Nerd Posted April 6, 2007 Author Share Posted April 6, 2007 anyting??? thankx Link to comment https://forums.phpfreaks.com/topic/45806-query-looping-with-while-simply-question/#findComment-222781 Share on other sites More sharing options...
PC Nerd Posted April 6, 2007 Author Share Posted April 6, 2007 does anyone have any idea to what to look for, or how to organise this?????? Link to comment https://forums.phpfreaks.com/topic/45806-query-looping-with-while-simply-question/#findComment-222816 Share on other sites More sharing options...
PC Nerd Posted April 7, 2007 Author Share Posted April 7, 2007 please???? Link to comment https://forums.phpfreaks.com/topic/45806-query-looping-with-while-simply-question/#findComment-223386 Share on other sites More sharing options...
per1os Posted April 7, 2007 Share Posted April 7, 2007 <?php $Login = mysqli_fetch_array($Login_Query); do{ $Latest_time = $Login['Logged_In']; }while($Login = mysqli_fetch_array($Login_Query)); ?> That is the correct syntax for the do,while. Do whiles are for when you always want certain code to execute. But you have a flaw for an infinite loop by putting the $Login inside the do while, because it never loops if that makes any sense. I would suggest you look into the type of operations you are trying to do before just doing them. IE read up on Do Whiles and the correct syntax. Link to comment https://forums.phpfreaks.com/topic/45806-query-looping-with-while-simply-question/#findComment-223390 Share on other sites More sharing options...
PC Nerd Posted April 7, 2007 Author Share Posted April 7, 2007 thankx do you have any help with the login timestamp or is that another thread? Link to comment https://forums.phpfreaks.com/topic/45806-query-looping-with-while-simply-question/#findComment-223393 Share on other sites More sharing options...
PC Nerd Posted April 7, 2007 Author Share Posted April 7, 2007 ill make a new thread abut the timestamp storage, thankx anyway Link to comment https://forums.phpfreaks.com/topic/45806-query-looping-with-while-simply-question/#findComment-223471 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.