Jump to content

$GET['id']; to pass from nav menu


remybink

Recommended Posts

this is my nav menu code

<ul>
        <li><a href='fountains_page.php?id=all'>all fountains</a></li> 
        <li><a href='fountains_page.php?id=garden'>garden fountains</a></li>
        <li><a href='fountains_page.php?id=wall'>wall fountains</a></li>
      </ul>

this is my script

   require('dbconnect.php');        
                                         
   $id = $_GET['id'];
   if($id = all){
      $records = "SELECT * FROM (fountains)";
        }else{
          if ($id = garden){ 
            $records = "SELECT * FROM (fountains) WHERE wall='no'";
              }else{
                if($id = wall){
                  $records = "SELECT * FROM (fountains) WHERE wall='yes'"; 
                    }
                     }
                      }
  
  
  
      $query_records = mysql_query($records);
      $num_records = mysql_num_rows($query_records);
      if ($num_records == 0) {
        echo "The menu is closed for now.";
        }
          else{
            $i=1;
             
              } 
            echo 'We have'.' '.$num_records.' '.'fountains for your consideration<br />Please visit our store to view hundreds of styles.<br />'; 
            echo $id;
       $errors = array(); // initialize error array

Here is the link

http://www.mywebsitepaid.com/stonemans/fountains_page.php

 

I can't get the 'id' to pass. What am I doing wrong? I did another site fine, but here I messed something up.

Link to comment
https://forums.phpfreaks.com/topic/245724-getid-to-pass-from-nav-menu/
Share on other sites

Lots of issues with your code.

 

1) You are using an assignment operator. (=) If you are comparing you need to use ==.

 

2) When you are comparing strings, you have to put quotes around it to define it as a string. ""

 

3) You don't need to do if (blah) { } else { if (blah) }. You can do if (blah) {} else if (blah) {} else { }

 

if($id == "all"){
      $records = "SELECT * FROM (fountains)";
        }else{
          if ($id == "garden"){ 
            $records = "SELECT * FROM (fountains) WHERE wall='no'";
              }else{
                if($id == "wall"){

$id = $_GET['id'];
   if($id == "all"){
      $records = "SELECT * FROM (fountains)";
        }else if($id == "garden"){ 
            $records = "SELECT * FROM (fountains) WHERE wall='no'";
              }else{
                  $records = "SELECT * FROM (fountains) WHERE wall='yes'"; 
                    }

 

hahaha -- you rock!!!!

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.