EchoFool Posted September 18, 2008 Share Posted September 18, 2008 I have a problem with a while loop, which is looping only 2 rows im sure its a simple solution but i cannot see it =/ The table has 2 rows with 2 different ID's (ID 2 and ID 15) It loads the two rows fine but obtaining the username for the ID is when it goes wrong.... say user ID 2 comes out first and it loops to get the names it gives: Test[2] Test[15] Even though it should be: Test[2] Test2[15] As you can see the ID changes correct but not the name which is why I am confused by what has gone wrong. Table: Date Of IP | IP | UserID timestamp | IP | 2 timestamp | IP | 15 This is what i have: <?php While($row = mysql_fetch_assoc($Get)){ $DateOfIP = $row['DateOfIP']; $IP = $row['IP']; $UserID = $row['UserID']; If($UserID>0){ $Get2 = mysql_query("SELECT Username FROM users WHERE UserID='$UserID'") Or die(mysql_error()); If(mysql_num_rows($Get2)>0){ $row2 = mysql_fetch_assoc($Get2); $UserName = $row2['Username']; }Else{ $UserName = '---Deleted User---'; } }Else{ $UserName = 'Invalid ID'; } ?> <?=$Username?>[<?=$UserID?>] <?php unset($UserID); } ?> Hope you can help me out Quote Link to comment https://forums.phpfreaks.com/topic/124869-while-loop-error/ Share on other sites More sharing options...
F1Fan Posted September 18, 2008 Share Posted September 18, 2008 Which variable is "Test" supposed to be in your code? Quote Link to comment https://forums.phpfreaks.com/topic/124869-while-loop-error/#findComment-645128 Share on other sites More sharing options...
DarkWater Posted September 18, 2008 Share Posted September 18, 2008 Why don't you just do: <?php $query = "SELECT u.username, u.userid FROM ip_table AS i INNER JOIN users AS u USING (UserID)"; As your query. Then you have just one easy loop. Also, DON'T USE SHORT TAGS. Quote Link to comment https://forums.phpfreaks.com/topic/124869-while-loop-error/#findComment-645130 Share on other sites More sharing options...
EchoFool Posted September 18, 2008 Author Share Posted September 18, 2008 Which variable is "Test" supposed to be in your code? The usernames its Test and Test2 with the id of the usernames in square brackets. Short tags work fine on my server DarkWater lol. So its ok to use them Quote Link to comment https://forums.phpfreaks.com/topic/124869-while-loop-error/#findComment-645156 Share on other sites More sharing options...
DarkWater Posted September 18, 2008 Share Posted September 18, 2008 Not the point, they still should never be used. Quote Link to comment https://forums.phpfreaks.com/topic/124869-while-loop-error/#findComment-645158 Share on other sites More sharing options...
EchoFool Posted September 18, 2008 Author Share Posted September 18, 2008 Under what reason ? Quote Link to comment https://forums.phpfreaks.com/topic/124869-while-loop-error/#findComment-645162 Share on other sites More sharing options...
DarkWater Posted September 18, 2008 Share Posted September 18, 2008 Lack of portability, and eventual discontinuance. Anyway, did you try my new query? Quote Link to comment https://forums.phpfreaks.com/topic/124869-while-loop-error/#findComment-645164 Share on other sites More sharing options...
EchoFool Posted September 18, 2008 Author Share Posted September 18, 2008 Lack of portability, and eventual discontinuance. Anyway, did you try my new query? Yeah same issue though =/ Quote Link to comment https://forums.phpfreaks.com/topic/124869-while-loop-error/#findComment-645165 Share on other sites More sharing options...
EchoFool Posted September 18, 2008 Author Share Posted September 18, 2008 eventual discontinuance. Why would they end the use of using a short tag which makes scripts just that bit more easier? To me to do : Hello my name is <?=$Username?> Is far easier than: Echo 'Hello my name is '.$Username; Quote Link to comment https://forums.phpfreaks.com/topic/124869-while-loop-error/#findComment-645166 Share on other sites More sharing options...
DarkWater Posted September 18, 2008 Share Posted September 18, 2008 eventual discontinuance. Why would they end the use of using a short tag which makes scripts just that bit more easier? To me to do : Hello my name is <?=$Username?> Is far easier than: Echo 'Hello my name is '.$Username; They make script just that bit more lazier, not easier. EDIT: Yeah, because the first one just echos the username, the second one echos a string. At least use a comparable scenario before you try to defend your point. Quote Link to comment https://forums.phpfreaks.com/topic/124869-while-loop-error/#findComment-645180 Share on other sites More sharing options...
Zane Posted September 18, 2008 Share Posted September 18, 2008 well you can still go ="cornholio" ?> If you like using short tags, then use them..... there's no point in conforming to religious PHP methods. Now, if you were creating this script for a business or client or whatever....then....I would recommend not using them. Some server administrators turn short tags off and that could hurt ....sales but as far as short tags go, I've always like them and I can't figure out why they're so "bad". I especially like them for use with $_SERVER['PHP_SELF']...when and if I ever use it. Well now that that's settled, you should continue with your initial topic. Quote Link to comment https://forums.phpfreaks.com/topic/124869-while-loop-error/#findComment-645194 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.