更新
我正在使用codeigniter,我有这样简单的选择选项:
<select id="field_' + count + '" name="fields[]' + '" class="form-control no_inv" >
<?php
$jj = "<script>var e = document.getElementById('id_barang').value;document.write(e);</script>";
$noInv = $this->modelku->select_inv($jj);
?>
<option value="" selected="selected" disabled>Pilih no inventaris</option>
<?php
foreach($noInv->result() as $inv){ ?>
<option value="<?php echo $inv->no_inv ?>">
<?php echo $inv->no_inv ?>
</option><?php }
?>
</select><br>
这是我的html元素,其id = id_barang
:
<select name="id_barang" id="id_barang" class="form-control">
<?php $idBarang = $this->modelku->select_idBrang() ?>
<?php foreach($idBarang->result() as $idBr){ ?>
<option value="<?php echo $idBr->id_barang ?>"><?php echo $idBr->id_barang ?></option>
<?php } ?>
</select required>
来自modelku的 select_inv
函数:
public function select_inv($idbrang)
{
$this->db->select("no_inv");
$this->db->from('detail_barang');
$this->db->where('kondisi', 'Ada');
$this->db->where('id_barang ', $idbrang);
$query = $this->db->get();
return $query;
}
但是当我点击选择选项时,no_inv中的值不会出现在我的选择选项中?
有人可以帮我吗?
答案 0 :(得分:1)
问题在于在手写的where子句中使用变量$this->db->where('kondisi', 'Ada');
$this->db->where('id_barang ', $idbrang);
。要使用变量,请更改行
The action 'favicon' could not be found for XXXXController.
到
-------------------------------
Backtrace:
-------------------------------
actionpack (3.2.8) lib/abstract_controller/base.rb:116:in `process'
actionpack (3.2.8) lib/abstract_controller/rendering.rb:45:in `process'
actionpack (3.2.8) lib/action_controller/metal.rb:203:in `dispatch'
actionpack (3.2.8) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
actionpack (3.2.8) lib/action_controller/metal.rb:246:in `block in action'
actionpack (3.2.8) lib/action_dispatch/routing/route_set.rb:73:in `call'
actionpack (3.2.8) lib/action_dispatch/routing/route_set.rb:73:in `dispatch'
actionpack (3.2.8) lib/action_dispatch/routing/route_set.rb:36:in `call'
journey (1.0.4) lib/journey/router.rb:68:in `block in call'
journey (1.0.4) lib/journey/router.rb:56:in `each'
journey (1.0.4) lib/journey/router.rb:56:in `call'
actionpack (3.2.8) lib/action_dispatch/routing/route_set.rb:600:in `call'
exception_notification (3.0.1) lib/exception_notifier.rb:41:in `call'
wicked_pdf (1.1.0) lib/wicked_pdf/middleware.rb:14:in `call'
actionpack (3.2.8) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
rack (1.4.7) lib/rack/etag.rb:23:in `call'
rack (1.4.7) lib/rack/conditionalget.rb:25:in `call'
actionpack (3.2.8) lib/action_dispatch/middleware/head.rb:14:in `call'
actionpack (3.2.8) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.2.8) lib/action_dispatch/middleware/flash.rb:242:in `call'
rack (1.4.7) lib/rack/session/abstract/id.rb:210:in `context'
rack (1.4.7) lib/rack/session/abstract/id.rb:205:in `call'
actionpack (3.2.8) lib/action_dispatch/middleware/cookies.rb:339:in `call'
activerecord (3.2.8) lib/active_record/query_cache.rb:64:in `call'
activerecord (3.2.8) lib/active_record/connection_adapters/abstract/connection_pool.rb:473:in `call'
actionpack (3.2.8) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
activesupport (3.2.8) lib/active_support/callbacks.rb:405:in `_run__905330616415270423__call__122903620689906054__callbacks'
activesupport (3.2.8) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.8) lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
activesupport (3.2.8) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.8) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (3.2.8) lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
actionpack (3.2.8) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
actionpack (3.2.8) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
railties (3.2.8) lib/rails/rack/logger.rb:26:in `call_app'
railties (3.2.8) lib/rails/rack/logger.rb:16:in `call'
quiet_assets (1.1.0) lib/quiet_assets.rb:27:in `call_with_quiet_assets'
actionpack (3.2.8) lib/action_dispatch/middleware/request_id.rb:22:in `call'
rack (1.4.7) lib/rack/methodoverride.rb:21:in `call'
rack (1.4.7) lib/rack/runtime.rb:17:in `call'
activesupport (3.2.8) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.4.7) lib/rack/lock.rb:15:in `call'
actionpack (3.2.8) lib/action_dispatch/middleware/static.rb:62:in `call'
rack-cache (1.7.1) lib/rack/cache/context.rb:140:in `forward'
rack-cache (1.7.1) lib/rack/cache/context.rb:249:in `fetch'
rack-cache (1.7.1) lib/rack/cache/context.rb:189:in `lookup'
rack-cache (1.7.1) lib/rack/cache/context.rb:66:in `call!'
rack-cache (1.7.1) lib/rack/cache/context.rb:51:in `call'
railties (3.2.8) lib/rails/engine.rb:479:in `call'
railties (3.2.8) lib/rails/application.rb:223:in `call'
railties (3.2.8) lib/rails/railtie/configurable.rb:30:in `method_missing'
/usr/lib/ruby/vendor_ruby/phusion_passenger/rack/thread_handler_extension.rb:97:in `process_request'
/usr/lib/ruby/vendor_ruby/phusion_passenger/request_handler/thread_handler.rb:152:in `accept_and_process_next_request'
/usr/lib/ruby/vendor_ruby/phusion_passenger/request_handler/thread_handler.rb:113:in `main_loop'
/usr/lib/ruby/vendor_ruby/phusion_passenger/request_handler.rb:416:in `block (3 levels) in start_threads'
/usr/lib/ruby/vendor_ruby/phusion_passenger/utils.rb:113:in `block in create_thread_and_abort_on_exception'
-------------------------------
System error:
-------------------------------
ERROR: Failed to generate exception summary:
ActionView::MissingTemplate: Missing partial exception_notifier/system_error with {:locale=>[:hb], :formats=>[:text], :handlers=>[:erb, :builder, :axlsx, :rjs]}. Searched in:
* "/var/www/html/paam/app/views"
* "/home/paam/.rvm/gems/ruby-1.9.3-p551/gems/exception_notification-3.0.1/lib/exception_notifier/views"
/home/paam/.rvm/gems/ruby-1.9.3-p551/gems/actionpack-3.2.8/lib/action_view/path_set.rb:58:in `find'
/home/paam/.rvm/gems/ruby-1.9.3-p551/gems/actionpack-3.2.8/lib/action_view/lookup_context.rb:109:in `find'
/home/paam/.rvm/gems/ruby-1.9.3-p551/gems/actionpack-3.2.8/lib/action_view/renderer/partial_renderer.rb:339:in `find_template'
/home/paam/.rvm/gems/ruby-1.9.3-p551/gems/actionpack-3.2.8/lib/action_view/renderer/partial_renderer.rb:333:in `find_partial'
/home/paam/.rvm/gems/ruby-1.9.3-p551/gems/actionpack-3.2.8/lib/action_view/renderer/partial_renderer.rb:222:in `render'
/home/paam/.rvm/gems/ruby-1.9.3-p551/gems/actionpack-3.2.8/lib/action_view/renderer/renderer.rb:41:in `render_partial'
/home/paam/.rvm/gems/ruby-1.9.3-p551/gems/actionpack-3.2.8/lib/action_view/helpers/rendering_helper.rb:27:in `render'
/home/paam/.rvm/gems/ruby-1.9.3-p551/gems/prototype-rails-3.2.1/lib/prototype-rails/rendering.rb:8:in `render_with_update'
/home/paam/.rvm/gems/ruby-1.9.3-p551/gems/exception_notification-3.0.1/lib/exception_notifier/views/exception_notifier/exception_notification.text.erb:9:in `block in __home_paam__rvm_gems_ruby_______p____gems_exception_notification_______lib_exception_notifier_views_exception_notifier_exception_notification_text_erb__2382212765454580501_58769400'
/home/paam/.rvm/gems/ruby-1.9.3-p551/gems/exception_notification-3.0.1/lib/exception_notifier/views/exception_notifier/exception_notification.text.erb:7:in `map'
/home/paam/.rvm/gems/ruby-1.9.3-p551/gems/exception_notification-3.0.1/lib/exception_notifier/views/exception_notifier/exception_notification.text.erb:7:in `__home_paam__rvm_gems_ruby_______p____gems_exception_notification_______lib_exception_notifier_views_exception_notifier_exception_notification_text_erb__2382212765454580501_58769400'
/home/paam/.rvm/gems/ruby-1.9.3-p551/gems/actionpack-3.2.8/lib/action_view/template.rb:145:in `block in render'
/home/paam/.rvm/gems/ruby-1.9.3-p551/gems/activesupport-3.2.8/lib/active_support/notifications.rb:125:in `instrument'
/home/paam/.rvm/gems/ruby-1.9.3-p551/gems/actionpack-3.2.8/lib/action_view/template.rb:143:in `render'
/home/paam/.rvm/gems/ruby-1.9.3-p551/gems/actionpack-3.2.8/lib/action_view/renderer/template_renderer.rb:47:in `block (2 levels) in render_template'
/home/paam/.rvm/gems/ruby-1.9.3-p551/gems/actionpack-3.2.8/lib/action_view/renderer/abstract_renderer.rb:38:in `block in instrument'
/home/paam/.rvm/gems/ruby-1.9.3-p551/gems/activesupport-3.2.8/lib/active_support/notifications.rb:123:in `block in instrument'
/home/paam/.rvm/gems/ruby-1.9.3-p551/gems/activesupport-3.2.8/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/home/paam/.rvm/gems/ruby-1.9.3-p551/gems/activesupport-3.2.8/lib/active_support/notifications.rb:123:in `instrument'
/home/paam/.rvm/gems/ruby-1.9.3-p551/gems/actionpack-3.2.8/lib/action_view/renderer/abstract_renderer.rb:38:in `instrument'
/home/paam/.rvm/gems/ruby-1.9.3-p551/gems/actionpack-3.2.8/lib/action_view/renderer/template_renderer.rb:46:in `block in render_template'
/home/paam/.rvm/gems/ruby-1.9.3-p551/gems/actionpack-3.2.8/lib/action_view/renderer/template_renderer.rb:54:in `render_with_layout'
/home/paam/.rvm/gems/ruby-1.9.3-p551/gems/actionpack-3.2.8/lib/action_view/renderer/template_renderer.rb:45:in `render_template'
/home/paam/.rvm/gems/ruby-1.9.3-p551/gems/actionpack-3.2.8/lib/action_view/renderer/template_renderer.rb:18:in `render'
/home/paam/.rvm/gems/ruby-1.9.3-p551/gems/actionpack-3.2.8/lib/action_view/renderer/renderer.rb:36:in `render_template'
/home/paam/.rvm/gems/ruby-1.9.3-p551/gems/actionpack-3.2.8/lib/action_view/renderer/renderer.rb:17:in `render'
/home/paam/.rvm/gems/ruby-1.9.3-p551/gems/actionpack-3.2.8/lib/abstract_controller/rendering.rb:110:in `_render_template'
/home/paam/.rvm/gems/ruby-1.9.3-p551/gems/actionpack-3.2.8/lib/abstract_controller/rendering.rb:103:in `render_to_body'
/home/paam/.rvm/gems/ruby-1.9.3-p551/gems/actionpack-3.2.8/lib/abstract_controller/rendering.rb:88:in `render'
/home/paam/.rvm/gems/ruby-1.9.3-p551/gems/actionmailer-3.2.8/lib/action_mailer/base.rb:684:in `block in collect_responses_and_parts_order'
/home/paam/.rvm/gems/ruby-1.9.3-p551/gems/actionmailer-3.2.8/lib/action_mailer/collector.rb:26:in `call'
/home/paam/.rvm/gems/ruby-1.9.3-p551/gems/actionmailer-3.2.8/lib/action_mailer/collector.rb:26:in `custom'
/home/paam/.rvm/gems/ruby-1.9.3-p551/gems/actionpack-3.2.8/lib/abstract_controller/collector.rb:10:in `text'
/home/paam/.rvm/gems/ruby-1.9.3-p551/gems/exception_notification-3.0.1/lib/exception_notifier/notifier.rb:176:in `block in compose_email'
/home/paam/.rvm/gems/ruby-1.9.3-p551/gems/actionmailer-3.2.8/lib/action_mailer/base.rb:685:in `collect_responses_and_parts_order'
/home/paam/.rvm/gems/ruby-1.9.3-p551/gems/actionmailer-3.2.8/lib/action_mailer/base.rb:636:in `mail'
/home/paam/.rvm/gems/ruby-1.9.3-p551/gems/exception_notification-3.0.1/lib/exception_notifier/notifier.rb:175:in `compose_email'
/home/paam/.rvm/gems/ruby-1.9.3-p551/gems/exception_notification-3.0.1/lib/exception_notifier/notifier.rb:104:in `exception_notification'
/home/paam/.rvm/gems/ruby-1.9.3-p551/gems/actionpack-3.2.8/lib/abstract_controller/base.rb:167:in `process_action'
/home/paam/.rvm/gems/ruby-1.9.3-p551/gems/actionpack-3.2.8/lib/abstract_controller/base.rb:121:in `process'
/home/paam/.rvm/gems/ruby-1.9.3-p551/gems/actionpack-3.2.8/lib/abstract_controller/rendering.rb:45:in `process'
/home/paam/.rvm/gems/ruby-1.9.3-p551/gems/actionmailer-3.2.8/lib/action_mailer/base.rb:457:in `process'
/home/paam/.rvm/gems/ruby-1.9.3-p551/gems/actionmailer-3.2.8/lib/action_mailer/base.rb:452:in `initialize'
/home/paam/.rvm/gems/ruby-1.9.3-p551/gems/actionmailer-3.2.8/lib/action_mailer/base.rb:439:in `new'
/home/paam/.rvm/gems/ruby-1.9.3-p551/gems/actionmailer-3.2.8/lib/action_mailer/base.rb:439:in `method_missing'
/home/paam/.rvm/gems/ruby-1.9.3-p551/gems/exception_notification-3.0.1/lib/exception_notifier.rb:49:in `rescue in call'
/home/paam/.rvm/gems/ruby-1.9.3-p551/gems/exception_notification-3.0.1/lib/exception_notifier.rb:41:in `call'
/home/paam/.rvm/gems/ruby-1.9.3-p551/gems/wicked_pdf-1.1.0/lib/wicked_pdf/middleware.rb:14:in `call'
/home/paam/.rvm/gems/ruby-1.9.3-p551/gems/actionpack-3.2.8/lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
/home/paam/.rvm/gems/ruby-1.9.3-p551/gems/rack-1.4.7/lib/rack/etag.rb:23:in `call'
/home/paam/.rvm/gems/ruby-1.9.3-p551/gems/rack-1.4.7/lib/rack/conditionalget.rb:25:in `call'
/home/paam/.rvm/gems/ruby-1.9.3-p551/gems/actionpack-3.2.8/lib/action_dispatch/middleware/head.rb:14:in `call'
/home/paam/.rvm/gems/ruby-1.9.3-p551/gems/actionpack-3.2.8/lib/action_dispatch/middleware/params_parser.rb:21:in `call'
/home/paam/.rvm/gems/ruby-1.9.3-p551/gems/actionpack-3.2.8/lib/action_dispatch/middleware/flash.rb:242:in `call'
/home/paam/.rvm/gems/ruby-1.9.3-p551/gems/rack-1.4.7/lib/rack/session/abstract/id.rb:210:in `context'
/home/paam/.rvm/gems/ruby-1.9.3-p551/gems/rack-1.4.7/lib/rack/session/abstract/id.rb:205:in `call'
/home/paam/.rvm/gems/ruby-1.9.3-p551/gems/actionpack-3.2.8/lib/action_dispatch/middleware/cookies.rb:339:in `call'
/home/paam/.rvm/gems/ruby-1.9.3-p551/gems/activerecord-3.2.8/lib/active_record/query_cache.rb:64:in `call'
/home/paam/.rvm/gems/ruby-1.9.3-p551/gems/activerecord-3.2.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:473:in `call'
/home/paam/.rvm/gems/ruby-1.9.3-p551/gems/actionpack-3.2.8/lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
/home/paam/.rvm/gems/ruby-1.9.3-p551/gems/activesupport-3.2.8/lib/active_support/callbacks.rb:405:in `_run__905330616415270423__call__122903620689906054__callbacks'
/home/paam/.rvm/gems/ruby-1.9.3-p551/gems/activesupport-3.2.8/lib/active_support/callbacks.rb:405:in `__run_callback'
/home/paam/.rvm/gems/ruby-1.9.3-p551/gems/activesupport-3.2.8/lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
/home/paam/.rvm/gems/ruby-1.9.3-p551/gems/activesupport-3.2.8/lib/active_support/callbacks.rb:81:in `run_callbacks'
/home/paam/.rvm/gems/ruby-1.9.3-p551/gems/actionpack-3.2.8/lib/action_dispatch/middleware/callbacks.rb:27:in `call'
/home/paam/.rvm/gems/ruby-1.9.3-p551/gems/actionpack-3.2.8/lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
/home/paam/.rvm/gems/ruby-1.9.3-p551/gems/actionpack-3.2.8/lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
/home/paam/.rvm/gems/ruby-1.9.3-p551/gems/actionpack-3.2.8/lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
/home/paam/.rvm/gems/ruby-1.9.3-p551/gems/railties-3.2.8/lib/rails/rack/logger.rb:26:in `call_app'
/home/paam/.rvm/gems/ruby-1.9.3-p551/gems/railties-3.2.8/lib/rails/rack/logger.rb:16:in `call'
/home/paam/.rvm/gems/ruby-1.9.3-p551/gems/quiet_assets-1.1.0/lib/quiet_assets.rb:27:in `call_with_quiet_assets'
/home/paam/.rvm/gems/ruby-1.9.3-p551/gems/actionpack-3.2.8/lib/action_dispatch/middleware/request_id.rb:22:in `call'
/home/paam/.rvm/gems/ruby-1.9.3-p551/gems/rack-1.4.7/lib/rack/methodoverride.rb:21:in `call'
/home/paam/.rvm/gems/ruby-1.9.3-p551/gems/rack-1.4.7/lib/rack/runtime.rb:17:in `call'
/home/paam/.rvm/gems/ruby-1.9.3-p551/gems/activesupport-3.2.8/lib/active_support/cache/strategy/local_cache.rb:72:in `call'
/home/paam/.rvm/gems/ruby-1.9.3-p551/gems/rack-1.4.7/lib/rack/lock.rb:15:in `call'
/home/paam/.rvm/gems/ruby-1.9.3-p551/gems/actionpack-3.2.8/lib/action_dispatch/middleware/static.rb:62:in `call'
/home/paam/.rvm/gems/ruby-1.9.3-p551/gems/rack-cache-1.7.1/lib/rack/cache/context.rb:140:in `forward'
/home/paam/.rvm/gems/ruby-1.9.3-p551/gems/rack-cache-1.7.1/lib/rack/cache/context.rb:249:in `fetch'
/home/paam/.rvm/gems/ruby-1.9.3-p551/gems/rack-cache-1.7.1/lib/rack/cache/context.rb:189:in `lookup'
/home/paam/.rvm/gems/ruby-1.9.3-p551/gems/rack-cache-1.7.1/lib/rack/cache/context.rb:66:in `call!'
/home/paam/.rvm/gems/ruby-1.9.3-p551/gems/rack-cache-1.7.1/lib/rack/cache/context.rb:51:in `call'
/home/paam/.rvm/gems/ruby-1.9.3-p551/gems/railties-3.2.8/lib/rails/engine.rb:479:in `call'
/home/paam/.rvm/gems/ruby-1.9.3-p551/gems/railties-3.2.8/lib/rails/application.rb:223:in `call'
/home/paam/.rvm/gems/ruby-1.9.3-p551/gems/railties-3.2.8/lib/rails/railtie/configurable.rb:30:in `method_missing'
/usr/lib/ruby/vendor_ruby/phusion_passenger/rack/thread_handler_extension.rb:97:in `process_request'
/usr/lib/ruby/vendor_ruby/phusion_passenger/request_handler/thread_handler.rb:152:in `accept_and_process_next_request'
/usr/lib/ruby/vendor_ruby/phusion_passenger/request_handler/thread_handler.rb:113:in `main_loop'
/usr/lib/ruby/vendor_ruby/phusion_passenger/request_handler.rb:416:in `block (3 levels) in start_threads'
/usr/lib/ruby/vendor_ruby/phusion_passenger/utils.rb:113:in `block in create_thread_and_abort_on_exception'
更多信息here
注意:我在OP完全改造之前给出了这个答案
答案 1 :(得分:1)
您不能使用javascript为PHP变量赋值,因为它们具有不同的执行时间,并且当您使用脚本标记时,除非浏览器加载它,否则它将只是PHP字符串。我认为您需要更改此项以使用PHP值进行分配。
答案 2 :(得分:1)
你不能这样做:
<select id="field_' + count + '" name="fields[]' + '" class="form-control no_inv" >
<?php
$jj = "<script>var e = document.getElementById('id_barang').value;document.write(e);</script>";
$noInv = $this->modelku->select_inv($jj);
?>
<!-- // ... -->
</select>
由于PHP $jj
变量的内容是纯文本,因此不会选择#id_barang
值。 $jj
将完全返回您引用的内容。
使用POST / GET方法的一种方法是使用Ajax将javascript值传递给PHP文件 。 Here are more details
这个:id="field_' + count + '" name="fields[]' + '"
也不会起作用,因为你将javascript变量用于HTML。您可以使用普通javascript将您的选择ID设置为<script>
标记。