Solved

number checker

Posted on 2008-09-29
8
195 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 500 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

863 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now