Jump to content

Beginner trying to only pull data that has specific requirements


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

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.