Jump to content


Photo

PhP MYSql Help


  • Please log in to reply
6 replies to this topic

#1 usadarts

usadarts
  • Members
  • PipPipPip
  • Advanced Member
  • 64 posts
  • LocationLaurence Harbor, NJ

Posted 17 August 2006 - 03:18 AM

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

The following form in the body:
        <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>

I then have several IfElse statements to bring up page:
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());
}


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

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

Any ideas?

#2 BillyBoB

BillyBoB
  • Members
  • PipPipPip
  • Advanced Member
  • 630 posts

Posted 17 August 2006 - 03:36 AM

i think it is u have no method to go by like change ur code to ... :

        <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());
           }
        }


#3 usadarts

usadarts
  • Members
  • PipPipPip
  • Advanced Member
  • 64 posts
  • LocationLaurence Harbor, NJ

Posted 17 August 2006 - 03:39 AM

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

#4 Jeremysr

Jeremysr
  • Members
  • PipPipPip
  • Advanced Member
  • 199 posts
  • LocationSaskatchewan, Canada

Posted 17 August 2006 - 03:40 AM

Change all the if($category to if($site

#5 BillyBoB

BillyBoB
  • Members
  • PipPipPip
  • Advanced Member
  • 630 posts

Posted 17 August 2006 - 03:45 AM

well sorry i couldnt help but Jeremysr got it
im just not that good with code thats not my own


#6 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 17 August 2006 - 03:53 AM

It should actually be...
if ($_GET['site']


#7 usadarts

usadarts
  • Members
  • PipPipPip
  • Advanced Member
  • 64 posts
  • LocationLaurence Harbor, NJ

Posted 23 August 2006 - 03:42 AM

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

        <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>

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());
}

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

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

David





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users