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
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"){

Link to comment
Share on other sites

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

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.