SitePoint Sponsor

User Tag List

Results 1 to 19 of 19
  1. #1
    SitePoint Wizard co.ador's Avatar
    Join Date
    Apr 2009
    Posts
    1,054
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How Can I $_GET a variable?

    Notice: Undefined variable: rmenu in C:\wamp\www\nyhungry\restaurants\shoe1.php on line 76

    I know how to global GET an integer
    PHP Code:
    " . (int) $_GET['shoe'] 
    But not a variable, which in this case the rmenu value pass undefined being.

    How could I global get the $rmenu variable so I can use it's value.

    Thank you.
    Last edited by co.ador; May 13, 2009 at 20:21.

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Please restate your question in coherent English. An example of the problem would be useful as well.

    The error you have means you tried to use a variable $rmenu that was not defined before you used it. The solution is to not use variables which you haven't defined.

  3. #3
    SitePoint Wizard co.ador's Avatar
    Join Date
    Apr 2009
    Posts
    1,054
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It was defined before but the value of $rmenu does not pass

    PHP Code:
    while($rmenu mysql_fetch_array($regularshoe_set)){
      echo 
    "<li"
      if (
    $rmenu["id"] == $sel_shoe) {
      echo 
    " class=\"selected\""
      } 
      echo 
    "><a href=\"shoe1.php?menu=" urlencode($rmenu["id"]) ."\";>
    {$rmenu["shoename"]}</a></li>";  }
      }
     if (
    $rmenu["id"] == $sel_menu) { // this is line 76 
    If you note before line 76 the rmenu value is difined but so how it doesn't pass it to the $rmenu below it.

    Sorry about the incoherent English.

  4. #4
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    That variable only exists within the loop. Even if it existed outside the loop, $rmenu would simply hold false as that was the last return value of mysql_fetch_array() when there were no more rows in the result set.

  5. #5
    SitePoint Wizard co.ador's Avatar
    Join Date
    Apr 2009
    Posts
    1,054
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    so It doesn't exist.

    I will abandon this possibility then.


    Thanks though!

  6. #6
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Define a variable before the loop, set its value within the loop, and after the loop is over, it will hold the value from the last row.

  7. #7
    SitePoint Wizard co.ador's Avatar
    Join Date
    Apr 2009
    Posts
    1,054
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok let me try difine a variable with that name before the loop starts
    PHP Code:
    $regularshoe_set mysql_query($query$connection);
      if(!
    $regularshoe_set){
      die(
    "Database query failed:" mysql_error());} 
      
    $rmenu mysql_fetch_array($regularshoe_set
    // I am not sure If I should define or call $rmenu with a mysql_fetch_array?
    //another thing is that before the while loop I have an If statement.
    //I am not sure if I should place this variable in between the if statement and the while loop thought it was better to locate it here. 
      
    echo "<ul class=\"submenu\">";
      if (
    $shoesubject["id"] == $sel_shoekind['id'])  {
    while(
    $rmenu mysql_fetch_array($regularshoe_set)){
      echo 
    "<li"
      if (
    $rmenu["id"] == $sel_shoe) {
      echo 
    " class=\"selected\""
      } 
      echo 
    "><a href=\"shoe1.php?menu=" urlencode($rmenu["id"]) ."\";>
    {$rmenu["shoename"]}</a></li>";  }
      }
     if (
    $rmenu["id"] == $sel_menu) { // this is line 76 

  8. #8
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Doing that will throw away the first row of the result set, since you advanced the row pointer twice before getting inside your loop by calling mysql_fetch_array twice.

    PHP Code:
    $lastrow = array();

    while (
    $rmenu mysql_fetch_array($regularshoe_set)) {
      
    // other code
      
    $lastrow $rmenu;
    }

    //now you can use $lastrow 

  9. #9
    SitePoint Wizard co.ador's Avatar
    Join Date
    Apr 2009
    Posts
    1,054
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you Dan Grossman!!!

    I will keep trying tomorrow morning

  10. #10
    SitePoint Addict skunkbad's Avatar
    Join Date
    Apr 2008
    Location
    Temecula, CA
    Posts
    278
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    One thing you should know about variables is that they can be set, unset, and not set at all. Being set means that the variable has a value of some sort applied to it. Unsetting a variable makes the variable lose all value, and a variable without a value is not set.

    When debugging your php applications, you will see errors like the one you saw:

    Notice: Undefined variable: rmenu in C:\wamp\www\nyhungry\restaurants\shoe1.php on line 76

    and this error tells you that the rmenu variable was not set. If you thought you had set it, you were wrong.

    Sometimes, programatically speaking, you will not know if a variable is set or not, and in that case, you can check if it is set or not, and do what is necessary.

    Tonight, after reinstalling my operating system, wamp, and all of my programs, one of my applications wasn't working, and it was hard to track down, because of the complex nature of the framework I was using. In the end, my error came down to a problem similar to yours. My script was checking for a server variable - $_SERVER['HTTP_USER_AGENT'] - and it didn't exist. I used the php function isset() to fix my problem like this:

    Code:
    if(isset($_SERVER['HTTP_USER_AGENT'])){
    			$ie6 = "MSIE 6.0";  
    			$browser = $_SERVER['HTTP_USER_AGENT'];  
    			$browser = substr("$browser", 25, 8);
    			if($browser == $ie6){
    				$this->template->javascripts[] = 'js/supersleight-min.js';
    			}
    		}
    I just thought you might need to know this, because I had a hard time learning php, and you seem sort of new.

  11. #11
    Web Professional
    Join Date
    Oct 2008
    Location
    London
    Posts
    862
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Dan Grossman View Post
    That variable only exists within the loop.
    This statement is false. Loops run in the scope they are created in so all variables set in a loop do exist outside it.

    Quote Originally Posted by Dan Grossman View Post
    [...] $rmenu would simply hold false as that was the last return value of mysql_fetch_array() when there were no more rows in the result set.
    True, but it's got nothing to do with PHP throwing an undefined variable error. The variable is defined and set to FALSE.

    @co.ador: Please paste in more code (especially the code after problematic line).

    EDIT: After formatting your code correctly:

    PHP Code:
      while($rmenu mysql_fetch_array($regularshoe_set)) {
        echo 
    "<li"
      
        if (
    $rmenu["id"] == $sel_shoe) {
          echo 
    " class=\"selected\""
        } 
      
        echo 
    "><a href=\"shoe1.php?menu=" urlencode($rmenu["id"]) ."\";>{$rmenu["shoename"]}</a></li>";
      }
    // what block of code is this closing?

    if ($rmenu["id"] == $sel_menu) { // this is line 76 
    it is obvious that you are closing another block of code (after closing the loop) before line 76. Please paste more code before the lines you have pasted.

  12. #12
    SitePoint Wizard co.ador's Avatar
    Join Date
    Apr 2009
    Posts
    1,054
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Skundbad it is debuged, I debuged it for a while but still showing up the problem. I will show some more detail so you guys can see more details.

    after line 76 the fallowing bit of code
    PHP Code:
    if ($rmenu["id"] == $sel_menu) { 
    I am trying to place or arrange the bit of code below this paragraph, so it can open the subject and hold on to its submenus and avoid to close the submenus once the users click on a submenu. The problem is that when a user open or click on a subject it opens it's submenus but once users click on a submenu it closes everything and it return to show the subject only closing all the submenus below the subject. If users want to open another submenu other than the one opened again, the users have to click on the subject again to choose another submenu instead of leaving all of the submenus visible and available to the users regardless users clicking on a submenu or not. Is there a format or coding it could be arranged for that? The way it is arranged now, the subject always closes its submenus once a submenu is click on instead of leaving all the submenus visible whether it is clicked on or not.

    PHP Code:
     echo "<ul class=\"submenu2\">";
     while(
    $rmenu mysql_fetch_array($regularshoe_set)){
      echo 
    "<li"
      if (
    $rmenu["id"] == $sel_shoe) { 
      echo 
    " class=\"selected\"";
      } 
      echo 
    "><a href=\"shoe1.php?menu=" urlencode($rmenu["id"]) ."\";>{$rmenu["shoename"]}</a></li>";  }
    echo 
    "</ul>"

    decowski this is the rest of the code before the while loop and what the curly braces below closes is the If statement after the mysql_query, Thank you for the help.

    PHP Code:
    $regularshoe_set mysql_query($query$connection);
      if(!
    $regularshoe_set){
      die(
    "Database query failed:" mysql_error());} 
    if (
    $shoesubject["id"] == $sel_shoe['id'])  {   
    while(
    $rmenu mysql_fetch_array($regularshoe_set)) {
        echo 
    "<li"
      
        if (
    $rmenu["id"] == $sel_shoe) {
          echo 
    " class=\"selected\""
        } 
      
        echo 
    "><a href=\"shoe1.php?menu=" urlencode($rmenu["id"]) ."\";>{$rmenu["shoename"]}</a></li>";
      }
    //That carly brace is closing the first If then statement at the top of the code.

    if ($rmenu["id"] == $sel_menu) { // this is 
    line 76

  13. #13
    Web Professional
    Join Date
    Oct 2008
    Location
    London
    Posts
    862
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You have a logical error in your code:

    PHP Code:
    if ($shoesubject["id"] == $sel_shoe['id'])  {
      while(
    $rmenu mysql_fetch_array($regularshoe_set)) {
      
    // [...]
      
    }
    }

    if (
    $rmenu["id"] == $sel_menu) { 
    So only if the first condition is met you set the $rmenu variable but you're trying to use it even if the condition is not met. You need to rethink what you're doing here.

    Sorry I can't help more but I can't understand the purpose of this code.

  14. #14
    SitePoint Wizard co.ador's Avatar
    Join Date
    Apr 2009
    Posts
    1,054
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    if ($rmenu["id"] == $sel_shoe
    It is not sel_menu is $sel_shoe

  15. #15
    Web Professional
    Join Date
    Oct 2008
    Location
    London
    Posts
    862
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is irrelevant. I'm talking about $rmenu variable, because that's what PHP is complaining about being not set. Look again at the snippet:

    PHP Code:
    if ($shoesubject["id"] == $sel_shoe['id'])  {
      while(
    $rmenu mysql_fetch_array($regularshoe_set)) {
      
    // [...]
      
    }
    }

    if (
    $rmenu["id"] == $sel_menu) { 
    You only set $rmenu variable if the first condition is met but then try to use the variable outside the condition (thus it may be not set).
    Last edited by decowski; May 14, 2009 at 08:36.

  16. #16
    SitePoint Wizard co.ador's Avatar
    Join Date
    Apr 2009
    Posts
    1,054
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok I will analize the code and I will print it out later so you can see in details what is happening.

  17. #17
    Web Professional
    Join Date
    Oct 2008
    Location
    London
    Posts
    862
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just a guess, as I don't know what your code is supposed to do, but maybe you are trying to do this:

    PHP Code:
    if ($shoesubject["id"] == $sel_shoe['id'])  {
      while(
    $rmenu mysql_fetch_array($regularshoe_set)) {
      
    // [...]
      
    }
    }

    if (isset(
    $rmenu) && $rmenu["id"] == $sel_menu) {
        ^^^^^^^^^^^^^ 

  18. #18
    SitePoint Wizard co.ador's Avatar
    Join Date
    Apr 2009
    Posts
    1,054
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Paul it is something like that...

    I just didn't knwo how to set it up, I am not at my house right now but once I get there I will try This.

    thank you paul. I will write you back guys around five eastertime.

  19. #19
    SitePoint Wizard co.ador's Avatar
    Join Date
    Apr 2009
    Posts
    1,054
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Paul I built the line below
    PHP Code:
     if (isset($rmenu) && $rmenu["id"] == $sel_menu) { 
    hoping that I was going to get the result of my desired purpose I have described below this qoute. So the pure motive why I have posted this thread was looking forward to achieve my purpose, but no the set up of this line hasn't work so far and maybe it will but I really don't know what I have to do or put it to make work along with my purpose.
    The purpose (my purpose) that I talk about is described below this quote in details.
    PS: I have directed this quote to you to explain the reasons of this thread only.

    Thank you for your help so far PAUL
    First Part.


    I will explain in details what I want to achieve first, and then I will post the code explaining and clarifying bit by bit for your understanding. in other words you will be able to see what can be done about the purpose or achievements i want to do.

    What I want to achieve is:

    First, I have three headings and within each of the three headings you will find different subheadings. The subheadings will only appears once an user click on any of the three headings when one heading is clicked on then the subheadings display downward. for example:

    Illustration 1
    Sneakers
    1. Nike
    2. Adidas
    3. Fila

    Boots
    DressShoes
    Explanation of Illustration 1.


    In this illustration there are three headings; Sneakers, Boots and DressShoes. The one clicked on is Sneakers and it shows or display a list of subheadings. In this case we have three subheadings Nike, Addidas and Fila. if you notice the others Headings stay closed containing its subheadings within because they haven't been clicked on. The set up of the code or what the code I have built so far does as fallows:

    1- Enter the web address and the three headings appears

    Sneakers
    Boots
    DressShoes
    2-A user click on a heading in this case the Sneakers heading and it display the subheadings of that heading called Sneakers and leave the subheadings of that heading (Sneakers) displayed, If you notice the others heading stay closed containing its subheadings inside but not visible.

    Sneakers
    1. Nike
    2. Addias
    3. Fila

    Boots
    DressShoes
    3-From this point if a user click on any other heading let say Boots

    Sneakers
    Boots
    • Timberland
    • Deakers
    • Western Boots

    DressShoes
    4 Then the subheadings of the previous clicked on heading Sneakers disappear in other words close the previous heading along with its subheadings,
    5-And then display the subheadings of the recent clicked on heading in this case Boots and leave it displayed. if you notice the Sneakers and DressShoes stay closed containing its subheadings inside but not visible to the users at this point.

    Second part
    My Purpose is:

    The subheadings as I said will only display downward when you click on one of the headings which is ok. It display the subheadings and when I click on one of the subheading then it shows the content of the selected subheading in a table that I have styled to be at the right side of the page.
    Illustration 2

    Sneakers
    1. Nike
    2. Addias
    3. Fila

    Boots
    DressShoes
    Explanation of the illustration 2 if for example the Nike subheading is clicked on then the content would displayed. The content would be placed in the table to the right of the page.
    1-Air jordan
    2-Air force
    3-Air jordan D-Zero
    4-Jordan true Flight Man
    5-Lebroms Nike
    As it display the content of the subheading *Nike it closes all the headings and comeback to the default state leaving the content of the *Nike display.

    Illustration 3

    leave the Displayed content of the *Nike subheading but .

    1-Air jordan
    2-Air force
    3-Air jordan D-Zero
    4-Jordan true Flight Man
    5-Lebroms Nike
    But the headings placed in a table at the left of the page comeback to the Default state.


    Sneakers
    Boots
    DressShoes

    in others words, it display the content of the subheading but it doesn't leave the subheadings displayed underneath the heading selected which in this case was Sneakers.So that if a user want to select or choose another subheading other than the *Nike subheading within the heading Sneakers, to display the content of any other desired subheading in the table placed to the right of the page, the user has to open the Sneakers heading again and choose any other subheading than the *Nike for instance *Adidas to see Adidas content.

    Instead I want to display the headings as default just as it is, and once an user clicked on a heading then the subheadings underneath that heading display. Onto that point that's how the actual coding I have now is set up. But after that point I want the subheadings to display the content in the table styled at the right side of the web page and at the same time I want the subheadings underneath the clicked on heading in this case *Nike *Adidas *Fila to stay displayed and visible after an user click on one of the subheadings to display its content in the table, instead avoid the headings coming back to the default state which disappear all the subheadings underneath that subheading in this case Sneakers.

    default state:

    Sneakers
    Boots
    DressShoes

    Sneakers
    1. Nike
    2. Addias
    3. Fila

    Boots
    DressShoes
    Click on the *Nike subheading and it shows the content of *Nike but it comes
    back to:

    default state
    Sneakers
    Boots
    DressShoes
    Instead of leaving the subheading of the Heading Sneakers visible and still shows the content.

    Sneakers
    1. Nike
    2. Addias
    3. Fila

    Boots
    DressShoes

    1-Air jordan
    2-Air force
    3-Air jordan D-Zero
    4-Jordan true Flight Man
    5-Lebroms Nike
    End of the purpose or what I want to achieve in php.

    Third part

    I have re-explained the purpose above enough, so that you guys can understand it without leaving doubts in your head. and If you still don't understand let me know I just here to clarify I need help.

    Now that the purpose is clear let me explain the code set up I have so far.

    PHP Code:
    <?php

    if(isset($_GET['shoesubject'])){
    $sel_subject $_GET['shoesubject'];
    $sel_shoe "";
    } elseif(isset(
    $_GET['shoe])){
    $sel_subject = "";
    $sel_shoe = $_GET['
    shoe'];
    }else {
    $sel_subject= ""; 
    $sel_shoe = "";
             
    }

    ?>
    These are the values I have (isset) on the top of the document. The $_GET variable which I understand function as a variable that scatter its values through out the whole document right?. That what I understand the $_GET variable does. As explain you the code you will see the values scattered through the document.

    The next bit of code it's what fallows after I (isset) the variables
    PHP Code:
    <ul class="menu">
       <?php   
      $query 
    "SELECT * 
                    FROM menusubjects "
    //headings are called on this query
                            
      
    $menusubject_set mysql_query($query$connection);
      if(!
    $menusubject_set){
      die(
    "Database query failed:" mysql_error());
      }while(
    $menusubject mysql_fetch_array($menusubject_set)){ // this while loop display the list of heading which are three 
      
    echo "<li"
      if (
    $menusubject["id"] == $sel_subject) {
      echo 
    " class=\"selected\"";
      }
      echo 
    "><a href=\"example1.php?subject=" urlencode($menusubject["id"]) ."\";>{$menusubject["Subject"]}</a></li>"
       
      
    $query "SELECT * 
                  FROM regularmenu  // these are the subheadings and they display beneath the headings
                WHERE menusubject_id = 
    {$menusubject["id"]}";
                
      
    $regularmenu_set mysql_query($query$connection);
      if(!
    $regularmenu_set){die("Database query failed:" mysql_error());} 
      echo 
    "<ul class=\"submenu\">"
      if (
    $menusubject["id"] == $sel_subject) { // this if statement stays that the heading will only display the subheadings withing the next while loop 
      
    while($rmenu mysql_fetch_array($regularmenu_set)){
      echo 
    "<li"
      if (
    $rmenu["id"] == $sel_menu) {
      echo 
    " class=\"selected\""
      } 
      echo 
    "><a href=\"example1.php?menu=" urlencode($rmenu["id"]) ."\";>{$rmenu["platename"]}</a></li>";  }
      } 
      
    echo 
    "</ul>"
      }
       
     
     
    ?>
     </ul> </table>
    Now my final question is, where within this code I could place a condition where subheadings display its content and at the same time the subheadings stay displayed underneath the headings which is the final part of the purpose I described and detailed above.

    There are a final part of the entire php code i have which contain a query that calls the content of the subheadings which will be displayed in a table found within this final part of the php code set up in this file, and it goes as follows:

    PHP Code:
    <?php $query "SELECT shoe.shoename, shoe.price, shoe.moreinfo 
    FROM shoe
    WHERE
    shoe_kind = "
    . (int) $_GET['shoe']; // $_GET value I extract it from the (isset) selection at the top of the code. This condition will show the content if the shoe_kind is == to $_GET value. I don't know if the query or purpose described above need a query to be place before this query or after this query and table found on this final part of my code.
    echo $query 
    $result 
    mysql_query($query$connection);
    while (
    $content mysql_fetch_array($result)) {
    echo 
    "<table style=\"float:left\">
    <td width=\"150\" style=\"text-align:center;\">" 
    $row['shoename'] . "</td>
    <tr>
    <td height=\"100\" width=\"100\"   style=\"position:relative;\">
    <img src=\"../images/shoesname.jpg\" alt=\"sd\" width=\"97\" height=\"80\"  border=\"1\" style=\"border-color:#FF6600;\" />
    </td></tr>
    <tr>
    <td width=\"5\" height=\"21\" ></td><td>" 
    $row['price'] . "</td>
    </tr>
    <td>" 
    $row['moreinfo'] . "</td>
    </table>"
    ;

    ?>
    <?php
    mysql_close($connection);
    ?>

    Help please...
    Again where could I locate a query and condition

    where I Click on subheading in this case the *Nike subheading it shows the content of *Nike but instead of coming back to:

    default state

    Sneakers
    Boots
    DressShoes

    Instead of leaving the subheadings of the Heading Sneakers visible and still shows the content like this.

    Heading and subheadings in a table to the left of the page

    Sneakers
    1. Nike
    2. Addias
    3. Fila

    Boots
    DressShoes
    This is what display in the table at the right of the page

    1-Air jordan
    2-Air force
    3-Air jordan D-Zero
    4-Jordan true Flight Man
    5-Lebroms Nike
    Help please....


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •