I have a modal form with two select boxes with the same current_models class.
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label class="control-label">Model</label>
<select class='form-control' id='left_model_id' name='left_model_id'>
<div id="left_model" class="current_models"></div>
</select>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label class="control-label">Model</label>
<select class='form-control' id='right_model_id' name='right_model_id'>
<div id="right_model" class="current_models"></div>
</select>
</div>
</div>
</div>
Each select needs to have it's own id, but they are loading the same select options into groups like this:
$('.current_models').load('ajax_get_models_man_group.php');
Here's my ajax_get_models_man_group.php page:
<?php
require_once 'core/init.php';
$user = new User();
if(!$user->isLoggedIn()) {
Redirect::to('login.php');
}
$models = DB::getInstance()->query("SELECT man.id AS man_id, man.man AS man, models.name AS model, models.id AS model_id FROM hearing_aid_models models LEFT JOIN hearing_aid_man man ON man.id = models.man_id WHERE models.currently_fitting = 'Y' AND company_id = '" . $user->data()->company_id . "' ORDER BY man ASC");
if ($models->error()) {
echo 'Error occurred.';
} else {
$currentGroup = null;
foreach( $models->results() as $result ) {
// start a new optgroup
if( $currentGroup == null || $result->man_id != $currentGroup ) {
// end the previous group
if( $currentGroup != null ) {
echo "</optgroup\n>";
}
// start a new group
echo "<optgroup data-id='{$result->man_id}' label='{$result->man}'>\n";
$currentGroup = $result->man_id;
}
echo "<option value='{$result->model_id}'>{$result->model}</option>\n";
}
// end the last opt group
if( $currentGroup != null ) echo "</optgroup>\n";
}
?>
The problem is that the values do not load into the select divs!
Here's my ajax source code results:
<optgroup data-id='1' label='Audibel'>
<option value='95'>Start 7 Wireless</option>
<option value='96'>Start 7</option>
<option value='99'>A3i Platinum</option>
</optgroup>
<optgroup data-id='16' label='Phonak'>
<option value='98'>Naida Q70</option>
</optgroup>
<optgroup data-id='2' label='Starkey'>
<option value='100'>S Series i30</option>
<option value='81'>3 Series I 70</option>
<option value='82'>3 Series I 90</option>
</optgroup>
1) Get rid of divs inside select tags
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label class="control-label">Model</label>
<select class='form-control current_models' id='left_model_id' name='left_model_id'>
</select>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label class="control-label">Model</label>
<select class='form-control current_models' id='right_model_id' name='right_model_id'>
</select>
</div>
</div>
</div>
2) load ajax inside the right div
$('.current_models').load('ajax_get_models_man_group.php');
Related
I can't show the data that I want to edit from my table. The combobox and the table don't show data when I edit the data categories, sub-categories, and manufacturers. I want to be able to see the data from my table after editing.
Controller form
public function data_items_edit($id)
{
$this->load->model('additem_m');
$model3 = $this->additem_m;
$data['table'] = $model3->get_where2($id)[0];
//$data['table'] = $model3->get();
$this->load->model('category_m');
$model = $this->category_m;
$data['category'] = $model->get();
$this->load->model('subcategory_m');
$model1 = $this->subcategory_m;
$data['sub'] = $model1->get();
$this->load->model('manufactures_m');
$model2 = $this->manufactures_m;
$data['manu'] = $model2->get();
//print_r($data['table']);
$this->load->view('items/edit_items_v', $data);
}
Data table controller
public function index()
{
if($this->session->has_userdata('isLogin')){
$this->load->model('additem_m');
$model = $this->additem_m;
$data['table'] = $model->get('items.*, item_categories.name as ic,
item_categories_sub.name as ics, item_manufactures.name as im',
[
['table'=>'item_categories','condition'=>'item_categories.id =
items.item_category_id'],
['table'=>'item_categories_sub','condition'=>'item_categories_sub.id
= items.item_category_sub_id'],
['table'=>'item_manufactures','condition'=>'item_manufactures.id =
items.item_manufacturer_id'],
]);
//print_r($data['table']);
$this->load->view('items/items_v', $data);
}else{
redirect('login');
}
}
View Form
<div class="form-group">
<label class="col-sm-4 control-label form-label">Category :</label>
<div class="col-sm-8">
<select name="item_category_id" class="form-control" id="category">
<option value='' <?php if($category == '0'){ echo 'selected';} ?>>--Select--</option>
<?php foreach($category as $category){
echo '<option value="'.$category->id.'">'.$category->name.'</option>';
} ?>
</select>
</div>
</div>
<div class="form-group">
<label class="col-sm-4 control-label form-label">Sub Category</label>
<div class="col-sm-8">
<select name="item_category_sub_id" class="form-control" id="category_sub">
<option value=''>- Select Sub Category -</option>
</select>
</div>
</div>
<div class="rightcontact">
<div class="form-group">
<label class="col-sm-4 control-label form-label">Manufacturer</label>
<div class="col-sm-8">
<select name="item_manufacturer_id" class="form-control" id="item_manufacturer_id">
<option>- Select Manufacturer -</option>
<?php foreach($manu as $manu){
echo '<option value="'.$manu->id.'">'.$manu->name."</option>";
} ?>
</select>
</div>
</div>
</div>
My view
You have to add selected attribute to the options.
$category == $category->id ? "selected" : ""
Something like this
<?php
foreach($category as $category){
echo '<option value="'.$category->id.'" '. $category == $category->id ? "selected" : "" .'>'.$category->name.'</option>';
^ ^
}
?>
I have one text box name is Skills , if admin enter skill name we will get user data based on the user skills in database field . it will working fine . i can display all users data based on the skill set .
My requirement is if admin search any skill that skill is mentioned user in Resume also .i need based on the resume also display data in codeigniter. can you any one please help out this problem. Please find below QUERY in model.
SELECT js_simple.js_id,js_simple.firstname,js_skills_achievements.skill,js_ResumeDetails.fileResume,js_ResumeDetails.profileImage FROM js_simple LEFT JOIN js_skills_achievements ON js_skills_achievements.js_id = js_simple.js_id WHERE js_skills_achievements.skill = '".trim($skill)."'
This is working for me , my requirement is user having resume . with in the resume suppose user mention skills is PHP,JAVA,SQL. if admin search any skill RESUME also i need search . What is QUERY for this in codeigniter model .
view.php
<form id="advance_search" action="" method="post">
<div class="col-md-8" style="border: 2px solid lightgray;padding: 0px 0px 9px 0px;">
<div class="advanced_serach_bg" style="background: #4a90cc;">
<div class="col-md-8">
<h4 style="color:#fff;"> Quick Search </h4>
</div>
</div>
<div class="col-md-12">
<div class="form-group">
<label style="color:#323232;" for="pincode">Any keyword</label>
<input style="color:#535353; background:#f1f1f1;height: 35px;" id="keywords" class="form-control" name="keywords" type="text">
</div>
</div>
<div class="col-md-12">
<div class="form-group">
<label style="color:#323232;" for="pincode">Location</label>
<input style="color:#535353; background:#f1f1f1;" id="location" class="form-control" name="location" placeholder="Enter Location" type="text">
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label style="color:#323232;" for="activein">Active in:</label>
<select style="background: #4a90cc;color:#fff;margin-top:2px;" name="active_records" id="active_records" class="form-control" >
<option value='3 day'> 3 days</option>
<option value='1 week'> 1 week</option>
<option value='30 day'> 30 days</option>
<option value='2 MONTH'> 2 months</option>
<option value='3 MONTH'> 3 months</option>
<option value='4 MONTH'> 4 months</option>
<option value='5 MONTH'> 5 months</option>
<option value='6 MONTH'> 6 months</option>
<option value='7 MONTH'> 7 months</option>
<option value='8 MONTH'> 8 months</option>
<option value='9 MONTH'>9 months</option>
<option value='10 MONTH'> 10 months</option>
<option value='11 MONTH'> 11 months</option>
<option value='12 MONTH'> 12 months</option>
<option value='10 Year'> 1 + Year</option>
</select>
</div>
</div>
<div class="clearfix"></div>
<br>
<div class="form-group">
<div class="col-md-offset-5 col-sm-4">
<input type="submit" value="Search" class="btn btn-normal subbtn">
</div>
</div>
</div>
</form>
javascript
<script>
$(function(){
$('form#advance_search').submit(function(e) {
e.preventDefault();
var formData = $('form#advance_search').serializeArray();
//var keywords = $('#keywords').tagEditor('getTags')[0].tags;
//console.log(keywords);
$.ajax({
url:"<?php echo base_url();?>newrecruiter_control/candidate_advance_search",
type:"post",
data:formData,
success:function(data) {
window.location.href="<?php echo base_url();?>newrecruiter_control/search_candidate";
}
});
});
});</script>
newrecruiter_control.php
public function candidate_advance_search() {
$this->recruiter_model->delete_candidate_search();
$data['job_seeker'] = $this->recruiter_model->advance_candidate_search();
}
recruiter_model.php
<?php
public function advance_candidate_search() {
$data = array(
'active_records' => $this->input->post('active_records')?$this->input->post('active_records'):'3 day',
'search_keyword' => $this->input->post('keywords')?$this->input->post('keywords'):'',
'semantic_search' => $this->input->post('search_mode')?$this->input->post('search_mode'):'ON',
'search_in_resume' => 'NO' //$this->input->post('search_resume')
);
$sql_query = $this->db->select('*')
->from('recruiter_recent_search_results')
->where('recruiter_id',$this->session->userdata('recruiter_id'))
->get();
if($sql_query->num_rows() >= 5 ){
$this->db->delete('recruiter_recent_search_results',array('recruiter_id' => $this->session->userdata('recruiter_id')));
}else{
$exp = $data['min_experience'];
$this->db->insert('recruiter_recent_search_results',array('recruiter_id' => $this->session->userdata('recruiter_id'),'skills' => strtoupper($data['search_keyword']), 'location' => ucfirst($data['location']),'experience' => $exp));
}
if($data['search_in_resume'] == 'YES') {
/*
if($data['semantic_search'] == 'OFF') {
$response_array = $this->getAdvanceSearchResultInResume($data);
}else{
$response_array = $this->getAllSearchResultInResume($data);
}*/
}else{
if($data['semantic_search'] == 'OFF') {
$response_array = $this->getAdvanceSearchResult($data);
}else{
$response_array = $this->getAllSearchResult($data);
}
}
}
public function getAllSearchResult($data) {
$search_query = "SELECT js_simple.js_id,js_simple.firstname,js_simple.lastname,js_simple.added_date,js_skills_achievements.skill1,js_ResumeDetails.percentage,js_ResumeDetails.fileResume,js_ResumeDetails.profileImage,js_ResumeDetails.profile_type,js_ResumeDetails.about_self FROM js_simple LEFT JOIN js_skills_achievements ON js_skills_achievements.js_id = js_simple.js_id LEFT JOIN js_ResumeDetails ON js_ResumeDetails.js_id = js_simple.js_id WHERE js_simple.added_date >= DATE_SUB(NOW(),INTERVAL ".$data['active_records']." ) ";
if($data['search_keyword'] != NULL) {
$search_key = explode(',',$data['search_keyword']);
if(count($search_key) == 1) {
$search_query .= " AND (js_skills_achievements.skill1 = '".trim($search_key[0])."' OR js_ResumeDetails.about_self LIKE '%".trim($search_key[0])."%')";
$str = $this->db->last_query($search_query);
echo $str;
}
}
$search_query .= " GROUP BY js_simple.js_id ORDER BY js_simple.added_date DESC LIMIT ".$data['sort_by'];
$response = $this->db->query($search_query);
// return $this->db->last_query();
return $response->result_array();
}
public function getAdvanceSearchResult($data) {
$this->db->select('*');
$this->db->from('js_simple,js_skills_achievements,js_ResumeDetails');
$this->db->join('js_skills_achievements','js_skills_achievements.js_id = js_simple.js_id','left');
$this->db->join('js_ResumeDetails','js_ResumeDetails.js_id = js_simple.js_id','left');
$this->db->where("js_simple.added_date >= DATE_SUB(NOW(),INTERVAL ".$data['active_records']." )",NULL,FALSE);
if($data['search_keyword'] != NULL) {
$search_key = explode(',',$data['search_keyword']);
if(count($search_key) == 1) {
$this->db->where('js_skills_achievements.skill1',$search_key[0]);
}
}
$this->db->group_by('js_simple.js_id');
$this->db->order_by('js_simple.added_date','desc');
if($data['sort_by'] != NULL) {
$this->db->limit($data['sort_by']);
}
$search_response = $this->db->get();
return $search_response->result_array();
}
public function getAllSearchResultInResume($data) {
$jobseekers = '';
$get_js_details = $this->getAllSearchResult($data);
foreach($get_js_details as $key => $jobseeker) {
if($jobseekers == NULL) {
$jobseekers .= $jobseeker['js_id'];
}else{
$jobseekers .= ','.$jobseeker['js_id'];
}
}
}
?>
I'm learning PHP (and having great fun) but I've run up against a problem in a CRUD application that I can't seem to find a way around.
I need to use a dropdown for data entry on the create page. I also want to have the same dropdown on the update page, but of course this would need to set the value to the one already stored in the record when the update form loads. I have hand-coded some of the shorter dropdowns (see below) but the one I need to do next is 2008 records!! (it will be searched as input is typed).
I have looked at multiple posts about arrays etc and I can get the dropdown to list the values that way but can't figure out how to pull in the existing value.
The relevant code is as follows (please be gentle about the coding...I'm new!!):
<?php
require_once "../includes/header.php";
?>
<?php
if ( isset($_POST['patient_id']) && isset($_POST['datadate'])
&& isset($_POST['bedspace']) && isset($_POST['episode_id']) ) {
$sql = "UPDATE tbl_users SET patient_id = :patient_id,
datadate = :datadate, bedspace = :bedspace, isadmitday = :isadmitday, antimicrobial = :antimicrobial
WHERE episode_id = :episode_id";
$stmt = $PDO->prepare($sql);
$stmt->execute(array(
':patient_id' => $_POST['patient_id'],
':datadate' => $_POST['datadate'],
':bedspace' => $_POST['bedspace'],
':episode_id' => $_POST['episode_id'],
':isadmitday' => $_POST['isadmitday'],
':antimicrobial' => $_POST['antimicrobial']));
$_SESSION['success'] = '<div class="alert alert-success" role="alert"><strong>Record successfully updated</strong></div>';
header( 'Location: index.php' ) ;
return;
}
$stmt = $PDO->prepare("SELECT * FROM tbl_users where episode_id = :xyz");
$stmt->execute(array(":xyz" => $_GET['episode_id']));
$row = $stmt->fetch(PDO::FETCH_ASSOC);
if ( $row === false ) {
$_SESSION['error'] = '<div class="alert alert-danger" role="alert"> <strong>Unable to proceed - bad episode_id value</strong></div';
header( 'episode_id: index.php' ) ;
return;
}
$n = htmlentities($row['patient_id']);
$e = htmlentities($row['datadate']);
$l = htmlentities($row['bedspace']);
$i = htmlentities($row['isadmitday']);
$am = htmlentities($row['antimicrobial']);
$episode_id = htmlentities($row['episode_id']);
?>
<div class="container">
<div class="row">
<div class="row">
<div class="col-md-12">
<h2>Edit episode record</h2><br>
</div> <!-- /col-md-12 -->
</div> <!-- /row -->
</div> <!-- /row -->
<div class="row">
<form name="edit_record" id="edit_record" method="POST" action="">
<div class="form-group">
<label for="patient_id" control-label>Patient ID</label>
<input type="text" class="form-control" id="patient_id" name="patient_id" value="<?= $n ?>">
</div> <!-- /form-group -->
<div class="form-group">
<label for="datadate" control-label>Date</label>
<input type="text" class="form-control" id="datadate" name="datadate" value="<?= $e ?>">
</div> <!-- /form-group -->
<div class="form-group">
<label for="bedspace" control-label>Bedspace</label>
<select class="form-control" required="required" id="bedspace" name="bedspace" value="<?= $l ?>">
<option></option>
<option value="Side Ward 1" <?php echo $l == 'Side Ward 1'?'selected':'';?>>Side Ward 1</option>
<option value="Bed 1" <?php echo $l == 'Bed 1'?'selected':'';?>>Bed 1</option>
<option value="Bed 2" <?php echo $l == 'Bed 2'?'selected':'';?>>Bed 2</option>
<option value="Bed 3" <?php echo $l == 'Bed 3'?'selected':'';?>>Bed 3</option>
<option value="Bed 4" <?php echo $l == 'Bed 4'?'selected':'';?>>Bed 4</option>
<option value="Bed 5" <?php echo $l == 'Bed 5'?'selected':'';?>>Bed 5</option>
<option value="Side Ward 2" <?php echo $l == 'Side Ward 2'?'selected':'';?>>Side Ward 2</option>
<option value="Side Ward 3" <?php echo $l == 'Side Ward 3'?'selected':'';?>>Side Ward 3</option>
</select>
</div> <!-- /form-group -->
Ok after an intensive couple of days research I have things working like I want to, although I am sure my work-around isn't pretty! The dropdown is a list of antibiotc medicines called 'antimicrobials'. I have the dropdown list from the database using a SELECT statement and I am matching the value pulled from the other table to set the value of the dropdown when a record is edited.
The code below is from the edit.php file:
<?php
if (isset($_POST['episode_id']) ) {
$sql = "UPDATE tbl_users SET antimicrobial = :antimicrobial
WHERE episode_id = :episode_id";
$stmt=$PDO->prepare($sql);
$stmt->execute(array(
':antimicrobial' => $_POST['antimicrobial']));
$_SESSION['success'] = '<div class="alert alert-success" role="alert"><strong>Record successfully updated</strong></div>';
header( 'Location: index.php' ) ;
return;
}
$stmt = $PDO->prepare("SELECT * FROM tbl_users where episode_id = :xyz");
$stmt->execute(array(":xyz" => $_GET['episode_id']));
$row = $stmt->fetch(PDO::FETCH_ASSOC);
if ( $row === false ) {
$_SESSION['error'] = '<div class="alert alert-danger" role="alert"><strong>Unable to proceed - bad episode_id value</strong></div';
header( 'episode_id: index.php' ) ;
return;
}
$am = htmlentities($row['antimicrobial']);
$episode_id = htmlentities($row['episode_id']);
?>
<div class="form-group">
<label for="antimicrobial" control-label>Antimicrobial from database</label>
<?php
$sql_am = 'SELECT antimicrobial FROM tbl_antimicrobials';
$stmt_am = $PDO->query($sql_am);
?>
<select class="form-control" id="antimicrobial"></select>
<?php
while ($row = $stmt_am->fetch(PDO::FETCH_ASSOC))
{
$selected = ($row['antimicrobial'] == $am ) ? ' selected' : '';
echo "<option value='" . $row['antimicrobial'] . "'" . $selected . ">" . $row['antimicrobial'] . "</option>";
}
echo '</select>';
?>
</div> <!-- /form-group -->
I have a problem, where I want to get a value from the database, and if the value matches the one in my option, the option should be selected.
This is my form:
<!-- Select Basic -->
<div class="form-group">
<label class="col-md-4 control-label" for="tidspunkt_varighed">Vælg Antal Timer</label>
<div class="col-md-4">
<select id="tidspunkt_varighed" name="tidspunkt_varighed" class="form-control">
<option value="1">1 Time</option>
<option value="2">2 Timer</option>
<option value="3">3 Timer</option>
<option value="4">4 Timer</option>
</select>
</div>
</div>
I don't want to make an if clause every line.
Thanks in advance.
Kristian
You should use a loop as your values are incremental when check with one if() inside the loop for the checked value.
<?php
$options = '';
$valueFromDb = 1;
for($i = 1;$i<=4 ; $i++)
{
if( $i == $valueFromDb) {
$options .= '<option value="'.$i.'" selected="selected">'.$i.'Time</option>';
} else {
$options .= '<option value="'.$i.'" >'.$i.'Time</option>';
}
}
?>
<div class="form-group">
<label class="col-md-4 control-label" for="tidspunkt_varighed">V�lg Antal Timer</label>
<div class="col-md-4">
<select id="tidspunkt_varighed" name="tidspunkt_varighed" class="form-control">
<?php echo $options;?>
</select>
</div>
</div>
I think, you can use an array somehow like that:
<?
$value=YOUR_VALUE_FROM_DB
$selected[$value]="selected";
?>
<option value="1" <?=$selected[1]?>>1 Time</option>
<option value="2" <?=$selected[2]?>>2 Timer</option>
etc.
if you are not displaying these options using a loop then you have to put if with every option like
<option value="1" <?php if($dbvalue == 1){echo 'selected="selected"';}>1 Time</option>
and in case you are showing options using a loop you can put a condition in the loop and make a string like
$selected = 'selected="selected"';
based on the condition, and echo $selected with every option.
$val_from_db = 3;
$output = '<!-- Select Basic -->
<div class="form-group">
<label class="col-md-4 control-label" for="tidspunkt_varighed">Vælg Antal Timer</label>
<div class="col-md-4">
<select id="tidspunkt_varighed" name="tidspunkt_varighed" class="form-control">';
foreach( $values as $key=>$value ) {
if ( $key==$val_from_db )
$selected = 'selected="selected" ';
else
$selected = '';
$output .= '<option '.$selected.'value="'.$key.'">'.$value.'</option>';
}
$output .= '</select>
</div>
</div>';
echo $output;
I have a php form that gets dumped into a MySQL table. I create an array that is populated from a Product table using php.
Queries the table to get the values for the array - works fine.
<?php
function getProducts ($id)
{
$sql =("SELECT * FROM products where products.CAT_ID = $id AND DISABLED ='NO'");
$result = mysql_query($sql);
if ($result > 0)
{
$products = array();
$x=0;
while($row = mysql_fetch_array($result))
{
$products[$x]= $row;
$x += 1;
}
return $products;
}
else return false;
}
function newProd(){
global $products;
}
?>
Then I use the above array to create labels in a javascript accordion. Next to the labels -are select boxes. (Removed unnecessary page elements.. ) Html/php form below that displays the above array.
<?php include('includes/query.php');?>
Inventory
<body onload="toggleField()">
<div id="container" class="container_16">
<form name="form1" id="form1" action="insert.php" method="post" enctype="multipart/form-data" style="height: inherit">
<div id="Info" class="grid_16">
<fieldset>
<label id="Label1">
<span class="Labels">Store Information</span> <br>
</label>
<div>
<label for="name">
<span class="Labels"> Name :</span> </label>
<input id="name" name="name" type="text">
</div>
</fieldset>
</div>
<hr id="SpacePadding">
<hr class="SpacePadding">
<div class="clear"></div>
<!-- Start of the Accordion Container-->
<!-- Start array, make sure Category Array isn't false -->
<?php if($categoryArray !=false):?>
<!-- create the variables for modulus -->
<!-- Start the foreach loop for the category Array -->
<?php $cataCounter = 0; ?>
<?php $closeSection = false; ?>
<?php foreach($categoryArray as $row):?>
<?php if($cataCounter % 2 == 0): ?>
<div class="push_1 grid_8">
<?php $closeSection = false; ?>
<?php else: ?>
<div class="grid_8">
<?php $closeSection = true; ?>
<?php endif; ?><!-- insert modulus-->
<div class="AccordionTitle"><?php echo $row['CATEGORY_NAME'];?></div>
<div class="AccordionContent">
<table>
<?php foreach(getProducts($row['CAT_ID']) as $row):?>
<tr>
<th class="boldLabels"><?php echo $row['PRODUCT_NAME'];?>
<span class="label"></span></th>
<th><span class="Labels">Count:</span></th>
<td>
<select name="selCount[]" onChange="toggleField(this.value);" class="Listbox">
<option value="Select">Select One</option>
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="Other">Other(Specify)</option>
</select>
<input type="text" name="otherCount[]" class ="Listbox" style="display: none;">
</td>
<td><span class="Labels">Need:</span></td>
<td>
<select name="selNeed[]" onChange="toggleField2(this.value);" class="Listbox">
<option value="Select">Select One</option>
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="Other">Other(Specify)</option>
</select>
<input type="text" name="otherNeed[]" class ="Listbox" style="display: none;">
</td>
</tr>
<?php endforeach;?>
</table>
</div>
</div>
<?php if($closeSection): ?>
<div class="clear"></div>
<?php endif; ?>
<?php $cataCounter += 1; ?>
<?php endforeach;?>
<?php endif;?>
<input name="Submit" type="submit" value="submit">
</div>
</form>
<br>
</div>
<footer>
<div align="center">
<ul>
<li>Home</li>
<li>Daily Inventory Counts</li>
<li>Contact System Admin</li>
</ul>
</div>
</footer>
</body>
When submitted, I want the Product_Name to go inside a new table with the correlating select option.
(i took out the database connection info out.)
<?php
//Assign array
$SelCount = $_POST['selCount'];
$SelNeed = $_POST['selNeed'];
$otherNeed = $_POST['otherNeed'];
$otherCount = $_POST['otherCount'];
$limit = count($SelCount);
for($i=0;$i<$limit;$i++) {
$SelCount[$i] = mysql_real_escape_string($SelCount[$i]);
$SelNeed[$i] = mysql_real_escape_string($SelNeed[$i]);
$otherNeed[$i] = mysql_real_escape_string($otherNeed[$i]);
$otherCount[$i] = mysql_real_escape_string($otherCount[$i]);
if (($SelCount[$i]) !="Select" ) {
$sql = ("INSERT INTO inventory ( STORE_ID, REQUESTOR, ITEM_COUNT, ITEM_NEED, NEED_COUNT, OTHER_COUNT)
VALUES ('$_POST[store]', '$_POST[name]', '".$SelCount[$i]."', '".$SelNeed[$i]."', '".$otherNeed[$i]."', '".$otherCount[$i]."')");
if(mysql_query($sql ,$db))
echo "$i successfully inserted.<br/>";
else
echo "$i encountered an error. <br/>";
}
}
?>
Here's what I would do:
function getProducts($id)
{
$sql = 'SELECT * FROM products where products.CAT_ID = ' . $id . ' AND DISABLED = "NO"';
$result = mysql_query($sql);
if($result !== false) {
while($row = mysql_fetch_array($result)) {
$products[]= $row;
}
} else {
$products = false;
}
}
Then you can print it out via:
if($products = getData(id)) {
foreach($products as $product) {
echo $product['database_field_name'];
}
}
To see them all for debugging purposes, you can use this:
echo '<pre>' . print_r($products, true) . '</pre>';
Also, you have to sanitize $id somewhere using:
http://php.net/manual/en/function.mysql-real-escape-string.php and perhaps use intval() if it's an integer.
Store data in session:
session_start();
$_SESSION['name'] = $product['database_field_name'];
And then on the insert.php page you can read the data via:
echo $_SESSION['name'];
Then after you don't need it anymore, you can unset it:
unset($_SESSION['name']);