Jump to content

[SOLVED] selectbox+database connection retrive problem


chennaibala

Recommended Posts


<tr>
            <th align="left" scope="col"><span class="style2 style8">Features </span></th>
            <th colspan="2" align="left" scope="col"><span class="style8">
              <textarea name="features" cols="30%" rows="6"></textarea>
            </span></th>
            <th scope="col"><span class="style8">
              <select name="select">
                <?php 	
$query="select ID, CODE from features order by ID asc"; 		
			     $result=mysql_query($query); 			
				while(list($id, $name)=mysql_fetch_row($result)) { 
					echo "<option value=\"".$id."\">".$name."</option>"; 
				} 
			?>
              </select>
            </span></th>
          </tr>

 

 

hi frds...

 

am using same select box in 20 different place in same php page.for these i creating database connection,executing query and value display in select box.my question is ,i want write same set of code for 20 selectbox in my php page ?if it so means,my php form load very slowly because php is creating 20 different database conection on loading page.how to solve these problem??i need to creat one connection,using that one connection i should diaplay same values,20 select box in my php page any suggestion pls..

 

or

 

query="select ID, CODE from features order by ID asc"; 

    $result=mysql_query($query);

can i store $result in any array variable.. then i can dispaly value in select box..?? suggest pls..thanks in advance

$query="select ID, CODE from features order by ID asc";       
                 $result=mysql_query($query);          
               while(list($id, $name)=mysql_fetch_row($result)) { 
                $select_array[$id]=$name;
               } 

then

foreach($select_array as $id=>$name)
{
echo "<option value='".$id."'>".$name."</option>"; 
}

put this before any of your select boxes

<?php

$query = "select ID, CODE from features order by ID asc";
$result = mysql_query($query);
while (list($id, $name) = mysql_fetch_row($result)) {
$selectbox.= "<option value=\"".$id."\">".$name."</option>";
}

?>

Then for each of the code snippets you originally had replace them with just

<?php echo $selectbox; ?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.