How to call a field name from database and link it with another database in php

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • KeyraRa
    New Member
    • Aug 2014
    • 5

    #1

    How to call a field name from database and link it with another database in php

    Hello guys..I have multiple checkboxes in form. Now the value of checkbox has been successfully entered into the database. Here are my checkbox form:

    Code:
    <form method="post" action="">
           <div align="left">
           <p align="left">
    
            <input type="checkbox"  name="BMK81A"     value="BMK81A"  > 1. BMK81A <br>
    
           <input type="checkbox" name="BMK81" value="BMK81" >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
          2. BMK81 <br>
    
          <input type="checkbox" name="DL3" value="DL3" >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
          3. JPN-DL-3 / JPN-DL-4  <br>       
    
          <input type="checkbox" name="DL2" value="DL2" >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
          4. JPN-DL-2 <br>
    
          <input type="checkbox" name="DL1" value="DL1" >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
          5. JPN-DL-1 <br>
    
        </div>
    </form>


    Now code for insert into database:

    Code:
    $insert_data7=mysql_query(" INSERT into docu (BMK81A,BMK81,DL3,DL2,DL1) VALUES  ('$BMK81A','$BMK81','$DL3','$DL2','$DL1') ") or die(mysql_error());

    At database when to store the value of checkbox it become like this: i can't insert the image to show

    -| BMK81A | BMK81 | DL3 | DL2 | DL1

    | | BMK81 | | DL2 |

    As you guys can see graph.... if user make a selection of checkbox and the value has been insert into database. after that, what I want is to make it display the description of "DOCUMENT". .

    Let me explain clearly.. I have second table in database named name_Document which is has field of CODE and DESC.. EXAMPLE:

    CODE | DESC : DL2 | JPN-DL-2 DL3 | JPN-DL-3/JPN-DL-4 and so on...

    So now if user make a selection at form. i want it can be display..when data has insert into database..it will refer to second table to call for a description...c an anyone help me?:'( please help me..:'(


    For better understanding:
    What I want is from table one value of checkbox has inserted. Then part of displayed, ,it will refer from table two for code and description if true..means.. if BMK81A succeeded insert into database, I just want the description of BMK81A will be appear. Only the value of checkbox that inserted will appear to be displayed. help me..
  • Claus Mygind
    Contributor
    • Mar 2008
    • 571

    #2
    You are dealing with two things here. both php and javascript.

    If you want to return information back to the user's computer screen you will have to make an ajax call or stream out a new page (which is much more work).

    Once you have done your insert you could do a read of the schema for table two and return the information you want.

    Here is how you could read the schema. Pass the function the table name you want to look up $t1.
    Code:
    	function getFieldList($t1)
    	{
    		/*
    		--------------------------------------------------
    		query the table schema of this table to be updated
    		--------------------------------------------------
    		*/
    		$query =  "SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '".$t1."'";
    
    		/*
    		---------------------------------------
    		Store column information of this table
    		in an array
    		---------------------------------------
    		*/
    		$aFieldList = array();
    
    		if ($result = $this->query($query)) 
    		{
    			/* fetch associative array */
    			while ($row = $result->fetch_assoc()) {
    				$aFieldList[$row['COLUMN_NAME']] = 
    				array(	
    					"name"=>		$row['COLUMN_NAME'], 	
    					"type"=>		$row['DATA_TYPE'], 	
    					"length"=>		$row['CHARACTER_MAXIMUM_LENGTH'], 
    					"numeric"=>		$row['NUMERIC_PRECISION'], 
    					"decimal"=>		$row['NUMERIC_SCALE'],
    					"isAutoInc"=>	$row['EXTRA'],
    					"isKey"=>		$row['COLUMN_KEY'], 
    					"default"=>		$row['COLUMN_DEFAULT']
    					);
    										   
    			}
    			/* free result set */
    			$result->free();
    		}
    
    		/* close connection */
    		return $aFieldList;
    	}
    But I suspect that your real question is more simple that that. Perhaps you are asking how can you use the value inserted into table one to look up a value in table 2 and return that value to be displayed for the user. In that case just do a second sql query on table 2 in the database.

    Comment

    Working...