Page 1 of 1

Need help with some simple php problem...

Posted: Thu Mar 31, 2011 4:59 pm
by phppadawan
Hey everyone,

I am not a big php coder, i know my html and what not but i need help with something thats probably pretty simple to you guys. Heres what I need help with.

I have a text box and enter button I just need it to display different results for a certain input range.

For example lets say I want the person to enter results 1-100, but I only want to display 10 different results for each input 1-10 will send them to a different link, 11-20 to a different link, 21-30, etc.

Whats the best way to do this?

Re: Need help with some simple php problem...

Posted: Thu Mar 31, 2011 5:16 pm
by fugix
set a limit mysql query as a variable..and create dynamic links with those variables..

Re: Need help with some simple php problem...

Posted: Thu Mar 31, 2011 6:08 pm
by phppadawan
now thats getting into stuff i have zero experience in. Would you be willing to do this for me for some compensation?

Re: Need help with some simple php problem...

Posted: Thu Mar 31, 2011 6:10 pm
by social_experiment
This is called pagination and as the other poster points out, it uses sql's LIMIT option.

Code: Select all

<?php
 $qry = mysql_query("SELECT * FROM table LIMIT 0, 10");
?>
This query will start from the record 0 and display 10 records (including the first one).

Re: Need help with some simple php problem...

Posted: Thu Mar 31, 2011 6:25 pm
by phppadawan
Hmm, I think i might not have explained it enough. This stuff seems a little over kill for what I want. Let me see if i can explain it better.

All I need really in theory is a simple redirect to different part of my website once the users inputs his number. In this case his credit score number. I will be asking him what his credit score number will be and there will be a empty text box with an enter button. All i need it to do is if he puts in 450 for example, then it will send him to mywebsite.com/450-460.php, Meaning anyone who puts in a number 450-460 will get sent there.

and anyone who puts in a number 461-470 will get sent someplace else. It seems like an easy thing to do without getting into databases and all that with like a simple, if code.

Can it be done this way or is the only way to do it with a database?

Re: Need help with some simple php problem...

Posted: Thu Mar 31, 2011 6:42 pm
by social_experiment
phppadawan wrote:Hmm, I think i might not have explained it enough. This stuff seems a little over kill for what I want. Let me see if i can explain it better.
You actually explained it totally different the first time.
phppadawan wrote:It seems like an easy thing to do without getting into databases and all that with like a simple, if code.
There could be a switch statement involved that tested the value of your input and based on that redirected the user to the specific page. This would not require a database.

Re: Need help with some simple php problem...

Posted: Thu Mar 31, 2011 6:48 pm
by phppadawan
awesome thats what I had thought. Could you write it up for me ill paypal you 5$?

Re: Need help with some simple php problem...

Posted: Thu Mar 31, 2011 6:55 pm
by fugix
basically you're filtering your form validation..can you a switch statement or if else statements...which ever you prefer

Re: Need help with some simple php problem...

Posted: Thu Mar 31, 2011 8:04 pm
by phppadawan
anyone willing to do this for 5$?

Re: Need help with some simple php problem...

Posted: Thu Mar 31, 2011 9:46 pm
by fugix
you could just use if statements if you have all of the pages already made for each number group

Re: Need help with some simple php problem...

Posted: Thu Mar 31, 2011 10:32 pm
by klandaika
Here is your solution:

The form:

Code: Select all

<html>
      <form id="form1" name="form1" method="post" action="redirect.php">
        <p>Enter your credit scroe      
          <input type="text" name="score" id="score" />
          <input type="submit" name="submit" id="submit" value="Submit" />
        </p>
      </form>
</html>
Redirection page "redirect.php":

Code: Select all

<?php
	$score = $_REQUEST['score'];
	
	if($score => 450 && $score < 460){
		header("Location: mywebsite.com/450-460.php");	
	}elseif($score => 460 && $score < 470){
		header("Location: mywebsite.com/460-470.php");	
	}
?>
Now all you have to do is add more elseif conditions.

Or you could do something like this:

Code: Select all

<?php
        $score = $_REQUEST['score'];
        
        for($i = 0; $i <= 900; $i += 10){
                if($score => $i && $score < ($i+10)){
                        header("Location: mywebsite.com/".$i."-".($i+10).".php");  
                }
        }
?>

Re: Need help with some simple php problem...

Posted: Fri Apr 01, 2011 12:55 am
by social_experiment
What is the maximum (& minimum) value a user can enter and what increments do you want? In the example you indicate 10, is that correct?