Gazz1982 Posted November 20, 2015 Share Posted November 20, 2015 (edited) Hi, I'm using the below code for a list, I want to do this again for a second query (drop down), on the same page eg. using: $sql2="SELECT statement2" $result2=mysql_query($sql2); I have tried renaming the variables but it just leads to a blank screen, where have I gone wrong? Thanks. ... $sql1="SELECT Questions.Question_ID, Questions.Question from Questions ORDER BY `Questions`.`Question_ID` ASC"; $result1=mysql_query($sql1); $site_array = array(); while (list($id, $name) = mysql_fetch_row($result1)) {$site_array[$id] = $name;} function get_options($arr, $current=null) { $opts = ''; foreach ($arr as $k => $v) { $sel = $k==$current ? 'selected="selected"' : ''; $opts .= "<option value='$k' $sel>$k $v</option>\n"; } return $opts; } ... ... <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST"> <select name="site" onchange="this.form.submit();"> <?php echo"<option>Select Question</option>";?> <?php echo get_options($site_array);?> </select> </form> ... The above code does exactly what I want it to do, I duplicated the code as follows: $aspect_array = array(); while (list($id2, $name2) = mysql_fetch_row($result2)) {$aspect_array[$id2] = $name2;} function get_options($arr2, $current2=null) { $opts2 = ''; foreach ($arr2 as $k2 => $v2) { $sel2 = $k2==$current2 ? 'selected="selected"' : ''; $opts2 .= "<option value='$k2' $sel2>$k2 $v2</option>\n"; } return $opts2; } ... ... <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST"> <select name="aspect" onchange="this.form.submit();"> <?php echo"<option>Select Aspect</option>";?> <?php echo get_options($aspect_array);?> </select> </form> ... Edited November 20, 2015 by Gazz1982 Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted November 20, 2015 Share Posted November 20, 2015 Is PHP set to show all errors and warnings? To make sure, you can add the following to the top of your script during the debugging process: error_reporting(E_ALL); ini_set('display_errors', 1); Side note: using the raw value from PHP_SELF in the form action attribute makes your script vulnerable to XSS attacks. To send form submissions to the same page, you can leave the attribute blank or delete the attribute altogether. Quote Link to comment Share on other sites More sharing options...
Solution Gazz1982 Posted November 20, 2015 Author Solution Share Posted November 20, 2015 Simply solved, all I had to do was change the name of the function, solved! Quote Link to comment Share on other sites More sharing options...
Barand Posted November 20, 2015 Share Posted November 20, 2015 So you now have two functions which do exactly the same thing, good thinking. The correct solution was to define the function once then call it each time you need it. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.