Jump to content

PhP MYSql Help


usadarts

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?
Link to comment
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]
Link to comment
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
Link to comment
Share on other sites

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.