bkassar Posted September 20, 2009 Share Posted September 20, 2009 Hello. I am quite new to PHP and MySQL. So please forgive me. I would like to do the following. 1.Allow a user to identifity a city they are interested in and 2Allow a user to read information others have submitted about that city. Code for page 1 is as follows: <form action="results.php" method="post" class="style2"> <div align="center"> <p>Enter a City<br /> <br /> <input type="text" name="citysearch" /> <input type="submit" value="Search" /> Code for page 2 is as follows (but i don't want it to be hardcoded "ixtapa" as i have below.. i want to limit the data displayed by the the variable the user generates in page 1. Please help :-) <?php $query="SELECT * FROM Questions WHERE City='ixtapa'"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); ?> <table border="0" cellspacing="2" cellpadding="2"> <tr> <th><font face="Arial, Helvetica, sans-serif">Name</font></th> <th><font face="Arial, Helvetica, sans-serif">Where</font></th> <th><font face="Arial, Helvetica, sans-serif">"Home"</font></th> <th><font face="Arial, Helvetica, sans-serif">Other Places</font></th> <th><font face="Arial, Helvetica, sans-serif">I Wish</font></th> </tr> <?php $i=0; while ($i < $num) { $f1=mysql_result($result,$i,"Name"); $f2=mysql_result($result,$i,"City"); $f3=mysql_result($result,$i,"Loc"); $f4=mysql_result($result,$i,"Other"); $f5=mysql_result($result,$i,"Before"); ?> <tr> <td><font face="Arial, Helvetica, sans-serif"><?php echo $f1; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $f2; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $f3; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $f4; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $f5; ?></font></td> </tr> <?php $i++; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/174888-how-to-pass-a-variable-from-a-form-to-limit-data-displayed/ Share on other sites More sharing options...
BioBob Posted September 20, 2009 Share Posted September 20, 2009 Use the mysql LIMIT feature. It accepts ONE or TWO arguments. SELECT * FROM field_name WHERE name='Fred' LIMIT 1; or SELECT * FROM field_name WHERE name='Fred' LIMIT 15, 30; When you use the second argument, the first argument becomes the result number you start at, and the second option is the total number of results, if there are that many results. This is also supposing that the second example query I gave you had over 45 rows in it. So basically it starts at result #15 and shows the next 30 records from there. Quote Link to comment https://forums.phpfreaks.com/topic/174888-how-to-pass-a-variable-from-a-form-to-limit-data-displayed/#findComment-921892 Share on other sites More sharing options...
bkassar Posted September 21, 2009 Author Share Posted September 21, 2009 Thank you BioBob. I didn't describe my question quite clearly enough. I'm sure what I am asking is quite fundamental. To use your example... how would I make the name variable dynamic. Instead of WHERE name='Fred' I'd like it to be WHERE name= something the user typed on the prior page Thank you Quote Link to comment https://forums.phpfreaks.com/topic/174888-how-to-pass-a-variable-from-a-form-to-limit-data-displayed/#findComment-922073 Share on other sites More sharing options...
fenway Posted September 21, 2009 Share Posted September 21, 2009 This sounds like a fundamental php question. Quote Link to comment https://forums.phpfreaks.com/topic/174888-how-to-pass-a-variable-from-a-form-to-limit-data-displayed/#findComment-922580 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.