I have a section of code i use over and over and I would like to turn it into a function passing in the args.
Thanx in advance.
I am attempting to turn this piece of code into a reuseable function. I need to create several drop down select boxes from data pulled from postgresqldb. Getting the data is no trouble. I use the same piece of code over and over, just changing variable names. I would like to turn it into a function.
This is what I have so far:
function make_query ($query) {
$result = pg_query ($conn, $query);
$numrows = pg_num_rows ($result);
if (!$numrows) { echo ("Can't get numrows!"
; exit; }
$iLoop=0;
while ( $iLoop < $numrows ) {
$var1 = pg_fetch_result ($result,$iLoop,0);
$option_block .="<option value='$var1'>$var1</option>";
$display_block = "<select name=\"$var2\">
$option_block </select>";
}
I need to pass in
1: The query string
2: var 2
3: The variable called $display_block will need to be passed in as a variable so i can call <?php echo $display_block; ?> and it will point to the correct information.
4: also $query, $result, $numrows will need to be renamed as a variable.
I already wrote this reusing the code over and over with cut and paste. I would like to make it cleaner using a function.
Thanx in advance.
I am attempting to turn this piece of code into a reuseable function. I need to create several drop down select boxes from data pulled from postgresqldb. Getting the data is no trouble. I use the same piece of code over and over, just changing variable names. I would like to turn it into a function.
This is what I have so far:
function make_query ($query) {
$result = pg_query ($conn, $query);
$numrows = pg_num_rows ($result);
if (!$numrows) { echo ("Can't get numrows!"
$iLoop=0;
while ( $iLoop < $numrows ) {
$var1 = pg_fetch_result ($result,$iLoop,0);
$option_block .="<option value='$var1'>$var1</option>";
$display_block = "<select name=\"$var2\">
$option_block </select>";
}
I need to pass in
1: The query string
2: var 2
3: The variable called $display_block will need to be passed in as a variable so i can call <?php echo $display_block; ?> and it will point to the correct information.
4: also $query, $result, $numrows will need to be renamed as a variable.
I already wrote this reusing the code over and over with cut and paste. I would like to make it cleaner using a function.