Jump to content

Beginner trying to only pull data that has specific requirements


tombot

Recommended Posts

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>

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

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.