Jump to content

Recommended Posts

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 :(

Link to comment
https://forums.phpfreaks.com/topic/124869-while-loop-error/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/124869-while-loop-error/#findComment-645180
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/124869-while-loop-error/#findComment-645194
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.