Jump to content

Archived

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

usadarts

PhP MYSql Help

Recommended Posts

I have the following in the header:
[code]function categoryHandler(form){
var URL = "http://www.Example.com/index.php?"+category.site.value+"=Y";
window.location.href = URL;
}[/code]

The following form in the body:
[code]        <form name="category">
          <div align="center">
            <select name="site" size=1 onChange="javascript:categoryHandler()">
              <option value=" ">Filter By Category</option>
              <option value="opt1">Option 1</option>
              <option value="opt2">Option 2</option>
              <option value="opt3">Option 3</option>
              <option value="opt4">Option 4</option>
              <option value="opt5">Option 5</option>
              <option value="opt6">Option 6</option>
            </select>
          </div>
        </form>
[/code]

I then have several IfElse statements to bring up page:
[code]if($category == 'opt1') {
$query = "SELECT * FROM `links` WHERE `opt1` = 'Y' and `approved` = 'Y' ORDER BY `title`";
$result = mysql_query($query,$dbh) or die(mysql_error());
}
elseif($category == 'opt2') {
$query = "SELECT * FROM `links` WHERE `opt2` = 'Y' and `approved` = 'Y' ORDER BY `title`";
$result = mysql_query($query,$dbh) or die(mysql_error());
}
elseif($category == 'opt3') {
$query = "SELECT * FROM `links` WHERE `opt3` = 'Y' and `approved` = 'Y' ORDER BY `title`";
$result = mysql_query($query,$dbh) or die(mysql_error());
}
elseif($category == 'opt4') {
$query = "SELECT * FROM `links` WHERE `opt4` = 'Y' and `approved` = 'Y' ORDER BY `title`";
$result = mysql_query($query,$dbh) or die(mysql_error());
}
elseif($category == 'opt5') {
$query = "SELECT * FROM `links` WHERE `opt5` = 'Y' and `approved` = 'Y' ORDER BY `title`";
$result = mysql_query($query,$dbh) or die(mysql_error());
}
elseif($category == 'opt6') {
$query = "SELECT * FROM `links` WHERE `opt6` = 'Y' and `approved` = 'Y' ORDER BY `title`";
$result = mysql_query($query,$dbh) or die(mysql_error());
}[/code]


This does not work.  It brings up the URL as:
[code]http://www.dartsites.com/index.php?baseball=Y[/code]

but does not filter the information as it should.  It brings up everything in the database.

Any ideas?

Share this post


Link to post
Share on other sites
i think it is u have no method to go by like change ur code to ... :

[code]
        <form name="category" method="post">
          <div align="center">
            <select name="site" size=1 onChange="javascript:categoryHandler()">
              <option value=" ">Filter By Category</option>
              <option value="opt1">Option 1</option>
              <option value="opt2">Option 2</option>
              <option value="opt3">Option 3</option>
              <option value="opt4">Option 4</option>
              <option value="opt5">Option 5</option>
              <option value="opt6">Option 6</option>
            </select>
            <input type="submit" name="submit" value="Submit" />
          </div>
        </form>
        <?php
        if($_POST['submit'])
        {
          if($category == 'opt1') {
          $query = "SELECT * FROM `links` WHERE `opt1` = 'Y' and `approved` = 'Y' ORDER BY `title`";
          $result = mysql_query($query,$dbh) or die(mysql_error());
          }
          elseif($category == 'opt2') {
          $query = "SELECT * FROM `links` WHERE `opt2` = 'Y' and `approved` = 'Y' ORDER BY `title`";
          $result = mysql_query($query,$dbh) or die(mysql_error());
          }
          elseif($category == 'opt3') {
          $query = "SELECT * FROM `links` WHERE `opt3` = 'Y' and `approved` = 'Y' ORDER BY `title`";
          $result = mysql_query($query,$dbh) or die(mysql_error());
          }
          elseif($category == 'opt4') {
          $query = "SELECT * FROM `links` WHERE `opt4` = 'Y' and `approved` = 'Y' ORDER BY `title`";
          $result = mysql_query($query,$dbh) or die(mysql_error());
          }
          elseif($category == 'opt5') {
          $query = "SELECT * FROM `links` WHERE `opt5` = 'Y' and `approved` = 'Y' ORDER BY `title`";
          $result = mysql_query($query,$dbh) or die(mysql_error());
          }
          elseif($category == 'opt6') {
          $query = "SELECT * FROM `links` WHERE `opt6` = 'Y' and `approved` = 'Y' ORDER BY `title`";
          $result = mysql_query($query,$dbh) or die(mysql_error());
          }
        }
[/code]

Share this post


Link to post
Share on other sites
That can't be it.  I have other drop down menu's to help filter information and they all work but this one.

Thank though

Share this post


Link to post
Share on other sites
well sorry i couldnt help but Jeremysr got it
im just not that good with code thats not my own

Share this post


Link to post
Share on other sites
It should actually be...
[code=php:0]
if ($_GET['site']
[/code]

Share this post


Link to post
Share on other sites
I now have the following and it still does not work
[code]function categoryHandler(form){
var URL = "http://www.TestURL.com/index.php?"+category.site.value+"=Y";
window.location.href = URL;
}[/code]

[code]        <form name="category">
          <div align="center">
            <select name="site" size=1 onChange="javascript:categoryHandler()">
              <option value=" ">Filter By Category</option>
              <option value="opt1">option 1</option>
              <option value="opt2">option 2</option>
              <option value="opt3">option 3</option>
            </select>
          </div>
        </form>[/code]

[code]
if($_GET['site'] == 'opt1') {
$query = "SELECT * FROM `links` WHERE `opt1` = 'Y' and `approved` = 'Y' ORDER BY `title`";
$result = mysql_query($query,$dbh) or die(mysql_error());
}
elseif($_GET['site'] == 'opt2') {
$query = "SELECT * FROM `links` WHERE `opt2` = 'Y' and `approved` = 'Y' ORDER BY `title`";
$result = mysql_query($query,$dbh) or die(mysql_error());
}
elseif($_GET['site'] == 'opt3') {
$query = "SELECT * FROM `links` WHERE `opt3` = 'Y' and `approved` = 'Y' ORDER BY `title`";
$result = mysql_query($query,$dbh) or die(mysql_error());
}[/code]

Still not working....still show all links instead of the selection I want. 

Thanks above for all the help so far......

David

Share this post


Link to post
Share on other sites

×

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.