tombot Posted December 1, 2009 Share Posted December 1, 2009 Hi Guys, i am trying to have a page display data from my database that meets a specific requirement, such as Type == "Attractions". I tried putting that into an if statement within my code that pulls everything and it didn't work, I got a blank page. What am I doing wrong. Here is my codw. Thanks <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <meta name="GENERATOR" content="Microsoft FrontPage 4.0"> <meta name="ProgId" content="FrontPage.Editor.Document"> <title>New Page 1</title> </head> <body stylesrc="csstemplate.htm"> <div align="center"> <center> <table border="0" width="810" bgcolor="#C2D3FC"> <tr> <td width="50%"><?php $con = mysql_connect("localhost","username","password"); //Replace with your actual MySQL DB Username and Password if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("kidsfun", $con); //Replace with your MySQL DB Name $query = "SELECT results, address, phone, websitelink, maplink FROM pickastate"; $result = mysql_query($query); while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { if ($type == "Attractions") { // This code is executed if $variable is equal to yes. echo "{$row['results']} <br>" . "{$row['address']} <br>" . "{$row['phone']} <br>". "{$row['websitelink']} <br>" . "{$row['maplink']} <br><br>" ; } } mysql_close($con); ?></td> <td width="50%"></td> </tr> </table> </center> </div> </body> </html> Link to comment https://forums.phpfreaks.com/topic/183647-beginner-trying-to-only-pull-data-that-has-specific-requirements/ Share on other sites More sharing options...
will35010 Posted December 1, 2009 Share Posted December 1, 2009 What about using a WHERE statement on your query. That would be easier. Link to comment https://forums.phpfreaks.com/topic/183647-beginner-trying-to-only-pull-data-that-has-specific-requirements/#findComment-969290 Share on other sites More sharing options...
tombot Posted December 1, 2009 Author Share Posted December 1, 2009 How would I code it? Sorry, extreme beginner Link to comment https://forums.phpfreaks.com/topic/183647-beginner-trying-to-only-pull-data-that-has-specific-requirements/#findComment-969294 Share on other sites More sharing options...
will35010 Posted December 1, 2009 Share Posted December 1, 2009 I don't see anything in your script that defines $type. Are you using POST or GET? That variable isn't set, so it will always be false. Link to comment https://forums.phpfreaks.com/topic/183647-beginner-trying-to-only-pull-data-that-has-specific-requirements/#findComment-969295 Share on other sites More sharing options...
mikesta707 Posted December 1, 2009 Share Posted December 1, 2009 $query = "SELECT results, address, phone, websitelink, maplink FROM pickastate WHERE type='Attractions'"; ? Link to comment https://forums.phpfreaks.com/topic/183647-beginner-trying-to-only-pull-data-that-has-specific-requirements/#findComment-969299 Share on other sites More sharing options...
will35010 Posted December 1, 2009 Share Posted December 1, 2009 How would I code it? Sorry, extreme beginner You need something like: POST method $type = $_POST['name']; GET method $type = $_GET['name']; This depends on your form type. Look at http://www.w3schools.com/html/html_forms.asp http://w3schools.com/PHP/php_post.asp http://w3schools.com/PHP/php_get.asp Link to comment https://forums.phpfreaks.com/topic/183647-beginner-trying-to-only-pull-data-that-has-specific-requirements/#findComment-969300 Share on other sites More sharing options...
tombot Posted December 1, 2009 Author Share Posted December 1, 2009 Thank you, this worked perfectly. Link to comment https://forums.phpfreaks.com/topic/183647-beginner-trying-to-only-pull-data-that-has-specific-requirements/#findComment-969306 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.