join three table in mysql using php

May 19 2015 8:46 AM
hi i am trying to fetching  data from the database when i am selecting the campaign name from dropdown list item without submit button click  in php mysql.
and the data is fetch from the three table . my table name is popup_question, popup_answar, and answar_mode,
the table field in popup_question are Id,question_text, mod_id, set_id, question_id, and campaign_id
and the table popup_answar are contain id, question_id, answar_text
and table answar_mode contain id, mode field. i am trying to select campaign_id and get the result from database . the result table contain field
and data r bellow
 
answar_text, question_text, answar_mode. please help me i am new in this field.
my code is bellow----
 
<?php
include('config.php');
/* $option_b_campaign="<option value='' id='radi_id1'>- SELECT A CAMPAIGN -</option>";
$result2=mysql_query("select DISTINCT campaign_id from popup_question");
while($qdata=mysql_fetch_array($result2))
{
$campaign_id=$qdata['campaign_id'];
//$asset_name=$qdata['asset_type'];
$option_b_campaign .= "<option id='radi_id1' value='$campaign_id'>$campaign_id</option>";
} */
//$sql=mysql_query("select DISTINCT campaign_id from popup_question");
//while($row=mysql_fetch_array($sql))
//{
//echo "<option onclick='change("<?php echo $row['campaign_id'];
if(isset($_POST['h_action']))
{
$val_h_action=$_POST['h_action'];
}
if($val_h_action=="insert")
{
$campaign=$_POST['campaign_id'];
$question=$_POST['question'];
$catagory=$_POST['mode'];
$sid=$_POST['sid'];
$qid=$_POST['qid'];
$sql=mysql_query("INSERT INTO popup_question(campaign_id,Question_text,Mod_id,Set_ID,Question_ID)VALUES('$campaign','$question','$catagory','$sid','$qid')");
}
?>
<html>
<head>
<link rel="stylesheet" href="themes/ui-lightness/jquery.ui.all.css">
<link href="css/cssmenu.css" rel="stylesheet" type="text/css" />
<link href="css/inner.css" rel="stylesheet" type="text/css" />
<link href="css/style.css" rel="stylesheet" type="text/css" />
<script src="popjquery/jquery-1.10.2.js"></script>
<script>
$(document).ready(function () {
$('.p').hide()
$('#text').click(function(){
$('.p').show()
});
});
</script>
<script>
function insert()
{
document.form1.h_action.value="insert";
document.form1.submit();
}
</script>
<script>
/* function change(id){
alert(id);
document.form1.h_value.value=id;
document.form1.h_action.value='selectcam';
document.form1.submit();
}*/
</script>
<SCRIPT language="JavaScript">
function addRow(tableID) {
var table = document.getElementById(tableID);
var rowCount = table.rows.length;
var row = table.insertRow(rowCount);
//Column 1
var cell1 = row.insertCell(0);
var element1 = document.createElement("input");
element1.type = "button";
var btnName = "button" + (rowCount + 1);
element1.name = btnName;
element1.setAttribute('value', 'Delete'); // or element1.value = "button";
element1.onclick = function () { removeRow(btnName); }
cell1.appendChild(element1);
//Column 2
var cell2 = row.insertCell(1);
cell2.innerHTML = rowCount + 1;
//Column 3
var cell3 = row.insertCell(2);
var element3 = document.createElement("input");
element3.type = "text";
cell3.appendChild(element3);
}
function removeRow(btnName) {
try {
var table = document.getElementById('dataTable');
var rowCount = table.rows.length;
for (var i = 0; i < rowCount; i++) {
var row = table.rows[i];
var rowObj = row.cells[0].childNodes[0];
if (rowObj.name == btnName) {
table.deleteRow(i);
rowCount--;
}
}
}
catch (e) {
alert(e);
}
}
</SCRIPT>
<script type="text/JavaScript">
function validation()
{
if(document.form1.campaign_id.value=="blank")
{
alert("Please select campaign Id..");
return false;
}
if(document.form1.question.value=="")
{
alert("Enter text question ..");
return false;
}
if(document.form1.mode.value=="blank1")
{
alert("Please select catagory mode..");
return false;
}
if(document.form1.sid.value=="")
{
alert("Please enter set id..");
return false;
}
if(document.form1.qid.value=="")
{
alert("Please enter Question id..");
return false;
}
}
</script>
</head>
<body>
<?php include ('header.php');?>
<div class="maindiv">
<div class="wapper">
<div class="mainbody" style="height:auto;">
<div class="loginbar">
<h3>Qualify Question Entry</h3>
</div>
<div class="content-box-content">
<form action="" name="form1" method="post" onsubmit="return validation();">
<input type="hidden" name="h_action" />
<input type="hidden" name="h_value" />
<table>
<tr><td class="style1">
<label style="font-size:15px;font-style:italic;">Campaign</label></td><td>
<select class="medium" name="campaign_id" style="width:450px; onchange="this.form.submit();">
<option value="blank">Select Campaign</option>
<?php
$sql=mysql_query("SELECT DISTINCT campaign_id FROM popup_question");
while($row=mysql_fetch_array($sql)){
?>
<option onclick="text1" value="<?php echo $row['campaign_id'];?>"><?php echo $row['campaign_id'];?></option>
<?php
}
?>
</select>
</td>
<td>
</td>
</tr>
<tr>
<td class="style1">
<label style="font-size:15px;font-style:italic;">Question</label></td><td>
<input type="text" name="question" Class="medium" style="width:450px;height:35px;" >
</td>
<td>
</td>
</tr>
<tr>
<td class="style1">
<label style="font-size:15px;font-style:italic;">Category</label></td><td>
<select Class="medium" name="mode" style="width:450px;">
<option value="blank1">select mode</option>
<option value="0">Manual</option>
<option value="1" id="text">Multiple Option</option>
</select>
</td>
<td>
</td>
</tr>
<tr>
<td class="style1">
<label style="font-size:15px;font-style:italic;">Set ID</label></td><td>
<input type="text" name="sid" Class="medium" style="width:450px;height:35px;" >
</td>
<td>
</td>
</tr>
<tr>
<td class="style1">
<label style="font-size:15px;font-style:italic;">Question ID</label></td><td>
<input type="text" name="qid" Class="medium" style="width:450px;height:35px;">
</td>
<td>
</td>
</tr>
<tr>
<td class="style1">
<label style="font-size:15px;font-style:italic;">ANSWAR OPTION</label>
</td>
<td>
<div class="p">
<input type="button" value="Add Row" onclick="addRow('dataTable')" Class="btnz"/>
<table id="dataTable" width="350px" border="1">
<tr bgcolor="#33FFFF"><th>Action</th><th>SL</th><th style="width:300px;"></tr>
<tr><td><input type="button" name="button1" value="Delete" onclick="removeRow('button1')"></td>
<td>1</td>
<td><input type="text" value="qmode" name="nameTxt" style="width:250px;"></td>
</tr>
</table>
</div>
</td>
</tr>
<tr><td><input type="submit" value="Submit" Class="btnz"></td></tr>
</table>
</form>
</div>
<div class="loginbar">
<h3>Existing Pop Up Questions</h3>
</div>
<?php
if (isset($_POST['campaign_id'])) {
$selection = $_POST['campaign_id'];
echo $selection ;
}
/* $val_h_action=$_POST['h_action'];
$val_h_id=$_POST['h_value'];
if($val_h_action=='selectcam')
{ */
//$Campaign_Name=$_POST['campaign_id'];
/* $query="SELECT * FROM popup_question WHERE campaign_id='$val_h_id'";
$run=mysql_query($query);
$numrow = mysql_num_rows($run); */
?>
<table border="2" class="div">
<tr bgcolor="#33FFFF">
<th>SL</th>
<th>Question</th>
<th>Answer Mode</th>
<th>Answer Text</th>
<th>Condition Status</th>
<th>Edit</th>
<th>Delete</th>
<th></th></tr>
<?php
$campain=$_POST['campaign_id'];
$query=mysql_query("SELECT a.Question_text,b.Mode,c.Answar_text FROM popup_question a INNER JOIN answar_mode b ON a.ID_id=b.ID INNER JOIN popup_answar c ON a.Question _ID=c.Question_id WHERE campaign_id='$campain'");
while($row = mysql_fetch_array( $query))
{
?>
<tr bgcolor="#D8D8D8 "><td><?php echo $row['Id']; ?></td>
<td><a href="popup_selection.php"><?php echo $row['Question_text']; ?></a></td>
<td><?php echo $row['Mode_id']; ?></td>
<td><?php echo $row['Set_ID']; ?></td>
<td><input type="checkbox"></td>
<td><input type="button" value="Edit"></td>
<td><input type="button" value="Delete"></td>
<td><input type="button" value="Edit Condition"></td>
</tr>
<?php
}
?>
</table>
</div>
</div>
<!--Main Body Ends-->
</div>
<?php include('footer.php');?>
</body>
</html>
 

Answers (1)