Function to Return Name of HTML Element Containing PHP Code -


i have form in html5 on php page. of form elements contain php code things such populating drop-down menu options. different options put in each menu, populated same php code (called query.php).

i want pass name of html element query.php determine query execute. query.php coded generally:

<?php $connection = pg_connect(...); $query = "select name table order name asc;"; $results = pg_query($connection, $query); $rows = pg_num_rows($results);  ($i=0; $i < $rows; $i++) {     ?>     <option><?php echo pg_fetch_result($results, $i, 0); ?></option>     <?php } ?> 

i want 'table' in $query variable coming html. here example line of html:

<p>select city: <select name="city"><?php include("query.php"); ?></select> 

i've been trying use http method replacing 'query.php' query.php?table=$this.name. understand should able use $_get['table'] in query.php , passed value, don't know function name of html element. function, when used within html tags, return name of html element? example, if use query.php?table=$this.name in above html, $_get['table'] in query.php should return "city". $this.name not correct function.

i suggest create function this:

<?php include("query.php"); ?>  <p>select city: <select name="city"><?php echo queryfunction("city"); ?></select></p> 

in query.php:

<?php function queryfunction($table) {     $connection = pg_connect(...);     $query = "select name $table order name asc;";     $results = pg_query($connection, $query);     $rows = pg_num_rows($results);     $string = "";          ($i=0; $i < $rows; $i++) {         $string = $string . "<option>" . pg_fetch_result($results, $i, 0) . "</option>";     }      return $string; } ?> 

i'm pretty sure there no way name of select box unless provide yourself. if done in javascript have been possible.


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

css - Can I use the :after pseudo-element on an input field? -