Need help with some simple php problem...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
phppadawan
Forum Newbie
Posts: 5
Joined: Thu Mar 31, 2011 4:55 pm

Need help with some simple php problem...

Post 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?
fugix
Forum Contributor
Posts: 207
Joined: Fri Mar 18, 2011 8:01 pm

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

Post by fugix »

set a limit mysql query as a variable..and create dynamic links with those variables..
phppadawan
Forum Newbie
Posts: 5
Joined: Thu Mar 31, 2011 4:55 pm

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

Post by phppadawan »

now thats getting into stuff i have zero experience in. Would you be willing to do this for me for some compensation?
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

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

Post 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).
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
phppadawan
Forum Newbie
Posts: 5
Joined: Thu Mar 31, 2011 4:55 pm

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

Post 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?
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

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

Post 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.
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
phppadawan
Forum Newbie
Posts: 5
Joined: Thu Mar 31, 2011 4:55 pm

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

Post by phppadawan »

awesome thats what I had thought. Could you write it up for me ill paypal you 5$?
fugix
Forum Contributor
Posts: 207
Joined: Fri Mar 18, 2011 8:01 pm

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

Post by fugix »

basically you're filtering your form validation..can you a switch statement or if else statements...which ever you prefer
phppadawan
Forum Newbie
Posts: 5
Joined: Thu Mar 31, 2011 4:55 pm

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

Post by phppadawan »

anyone willing to do this for 5$?
fugix
Forum Contributor
Posts: 207
Joined: Fri Mar 18, 2011 8:01 pm

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

Post by fugix »

you could just use if statements if you have all of the pages already made for each number group
klandaika
Forum Newbie
Posts: 19
Joined: Wed Mar 30, 2011 3:25 pm
Location: New York

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

Post 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");  
                }
        }
?>
Last edited by klandaika on Fri Apr 01, 2011 3:41 am, edited 1 time in total.
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

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

Post 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?
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Post Reply