PolurNET Communications Support Forums: PHP drop down menu function not working - PolurNET Communications Support Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

PHP drop down menu function not working Strange "string" error within function

#1 User is offline   ba2008 Icon

  • Hi, I'm New!
  • Icon
  • Group: Members
  • Posts: 1
  • Joined: 21-September 09
  • Gender:Male

Posted 21 September 2009 - 10:35 PM

Hi everyone,
First of all, I apologize because I am new to PHP programming. I would really appreciate anyone's help in trying to fix the code below. I am trying to write a reusable function that dynamically generates drop down menu options on my site, but the function isn't working. The idea is to query the id and name of topics from the MySQL database and populate the menu. However, the code below isn't working:

<?php  
   function dropdown($Id, $Name, $Table) {
     echo "<select id='$Id' name='$Id'>";
     echo "<option value=\"0\">Select Value</option>";
          $query = "SELECT * FROM $Table";
          $data = mysqli_query($dbc, $query);
          while($row = mysqli_fetch_array($data)) {
             $strA = $row['$Id'];
             $strB = $row['$Name'];
             echo "<option value=\"$strA\">$strB</option>";
          }
          echo "</select><br />";
   }
      dropdown(type_id, name, usertype);      
?>
 


For some reason the error is complaining about the "$query=" line. But the same syntax works elsewhere in my code. Any thoughts?
much appreciated!
0

#2 User is offline   PN-Anand Icon

  • President, Founder, Chief of Operations
  • Icon
  • Group: PolurNET Staff
  • Posts: 1,816
  • Joined: 27-July 05
  • Gender:Male
  • Location:Canada

Posted 22 September 2009 - 02:11 PM

Did you enter some debug statements? i.e. echo the $query on your page and see what it says. If it returns what you want, then proceed to echo the $row, etc.
Anand A.
President, Founder, Chief of Operations
PolurNET Communications
anand @ polurnet.com
0

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users