Loading ...
Sorry, an error occurred while loading the content.
 

PHP, create link behind a drop down list box!

Expand Messages
  • Sana Alamgeer
    hello everyone here i have a php code i wantto create a link to a specific page behind the drop down list box, while data is coming from databse. when user
    Message 1 of 32 , Aug 1, 2009
      hello everyone
      here i have a php code
      i wantto create a link to a specific page behind the drop down list box, while data is coming from databse.
      when user clicks on any item in list, a concerned page should open in frame f4. here is the code, please correct this, or help me, partial code i m sending.
      <SCRIPT language="JavaScript">
      function submitform()
      {
        document.form1.submit();
      }
      </SCRIPT>
      =================
         <form action="<?php $_SERVER['../sana/PHP_SELF']; ?>" name="form1" method="post">
         <table width="500px" cellpadding="0" cellspacing="0" align="left">
          <tr>
           <td>
            <select name="mem_year" onchange="submitform();">
                   <?php
              $sql="select id, page_name from tab_1";
              $sqlstmt=mysql_query($sql);
              echo "<option value='--'>Page Name</option>";
              while($result=mysql_fetch_array($sqlstmt)){
              echo "<option value=".$result["id"].">".$result["page_name"]."</option>"; 
              $i++;
              }
             ?>
            </select>
           </td>
          </tr>
         </table>
         </form>
      =====================   
      <?php
      switch ($_POST['mem_year']):
          case "1":
       echo '<a href="f1.php"?target=f4></a>';
             break;
          default:
             echo "Error: Action must be either one option";
      endswitch;
      ?>
      </body>
      </html>
      SanaAlamgeer

















      [Non-text portions of this message have been removed]
    • markwatling@ymail.com
      Hi Again Gab Wrote my earlier response in the early hours whilst a bit tired so only spotted the first error in the query. No offense but there s actually so
      Message 32 of 32 , Aug 9, 2009
        Hi Again Gab

        Wrote my earlier response in the early hours whilst a bit tired so only spotted the first error in the query.

        No offense but there's actually so many errors I won't waste your or my time by listing them, apart from this one:

        You run the query as $numresults=mysql_query($query2);

        but the query is declared as $query = "select * from table where etc.

        This never works - ever! Trust me:-)


        Anyway - this is what I came up with:

        $name = trim($_GET['q']);

        $query = "SELECT *
        FROM student
        WHERE name LIKE '$name%'
        ORDER BY name
        ";

        On a table containing

        select * from student;
        +----+-----------+
        | id | name |
        +----+-----------+
        | 1 | mark |
        | 2 | jo |
        | 3 | steve |
        | 4 | John |
        | 5 | dave |
        | 6 | johnathon |
        | 7 | janet |
        | 8 | joanne |
        +----+-----------+

        my query produces

        select * from student where name like 'jo%' order by name;
        +----+-----------+
        | id | name |
        +----+-----------+
        | 2 | jo |
        | 8 | joanne |
        | 4 | John |
        | 6 | johnathon |
        +----+-----------+

        select * from student where name like 'john%' order by name;
        +----+-----------+
        | id | name |
        +----+-----------+
        | 4 | John |
        | 6 | johnathon |
        +----+-----------+

        Really couldn't work out what you were trying to do with LIMIT - $s will always be empty the 1st time its tested so will always be allocated a value of 0, which once again will result in no results being returned. Also if you want to append it to the original $query use the concatenation operator .=

        Hope this has been helpful, but you really need to get hold of a good book on MySQL - I started with, & still use as a handy reference, the MySQL 5.0 Certification Study Guide published by MySQL AS. If you're a diligent student you could even become a MySQL 5.0 Certified Developer

        Good luck with the rest of your script

        Mark
      Your message has been successfully submitted and would be delivered to recipients shortly.