Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

number checker

Posted on 2008-09-29
8
Medium Priority
?
244 Views
Last Modified: 2012-05-05
hello there,
I would like to create something so that if I give a number lets say (150)
the code checks from 0 until 150 and once it finds it then say "number found!"
0
Comment
Question by:XK8ER
  • 5
  • 3
8 Comments
 
LVL 17

Expert Comment

by:nanharbison
ID: 22595327
this should work

<?PHP
$checkthisnumber = $_GET['thisnumber'];
 
$i=1;
while ($i < 151) 
{
	
 if ($i == $checkthisnumber) 
 	{
		echo "number found";
		break;
	}
$i++;
}
 
?>

Open in new window

0
 
LVL 17

Accepted Solution

by:
nanharbison earned 2000 total points
ID: 22595338
or if you want to show the number

<?PHP
$checkthisnumber = $_GET['thisnumber'];
 
$i=1;
while ($i < 151) 
{
	
 if ($i == $checkthisnumber) 
 	{
		echo "number found, it is: ". $checkthisnumber;
		break;
	}
$i++;
}
 
?>

Open in new window

0
 
LVL 1

Author Comment

by:XK8ER
ID: 22595352
yes, the last one is good.. how can I make it show a number not found?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 1

Author Comment

by:XK8ER
ID: 22595378
lets say I type number 6 it should be like

1 not found
2 not found
3 not found
4 not found
5 not found
6 number found
0
 
LVL 1

Author Comment

by:XK8ER
ID: 22595414
ok I think I got it!
$checkthisnumber = '50';
 
$i=1;
while ($i < 151) 
{
        
 if ($i == $checkthisnumber) 
        {
                echo $checkthisnumber . ' number found';
                break;
        }
      			else
        				echo $i . ' not found<br>';
$i++;
}

Open in new window

0
 
LVL 17

Expert Comment

by:nanharbison
ID: 22595423
like this

<?PHP
$checkthisnumber = $_GET['thisnumber'];
 
$i=1;
while ($i < 151) 
{
	
 if ($i == $checkthisnumber) 
 	{
		echo "number found, it is: ". $checkthisnumber;
	} else {
		echo $checkthisnumber." was not found ";
	}
$i++;
}
 
?>

Open in new window

0
 
LVL 17

Expert Comment

by:nanharbison
ID: 22595451
oops, that was wrong

<?PHP
$checkthisnumber = $_GET['thisnumber'];
$checkthisnumber = 100;
$i=1;
while ($i < 151) 
{
	
 if ($i == $checkthisnumber) 
 	{
		echo "number found, it is: ". $checkthisnumber;
	} else {
		echo $i." was not found<br /> ";
	}
$i++;
}
 
?>

Open in new window

0
 
LVL 17

Expert Comment

by:nanharbison
ID: 22595477
use the break statement if you want the loop to stop when the number is found.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

877 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question