Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'm not sure if you're following MVC Architecture or not because your post is actually kind of confusing.</p> <p>However, this is what I would do -- in Codeigniter. I'll try and match your code style as best as possible. Also there are a ton of ways you can do this, some might be way more efficient than this, but this will get the job done. I never ran this script, so it might have errors or require a little debugging:</p> <pre><code>&lt;?php /* Controller *************************/ class Something extends CI_Controller { function coord_check() { //Form Validation -- if necessary $this-&gt;form_validation-&gt;set_rules('X', 'X', 'required|xss_clean'); $this-&gt;form_validation-&gt;set_rules('Xm', 'Y', 'require|xss_clean'); $this-&gt;form_validation-&gt;set_rules('Y', 'Y', 'require|xss_clean'); $this-&gt;form_validation-&gt;set_rules('Ym', 'Ym', 'require|xss_clean'); if ($this-&gt;form_validation-&gt;run() == FALSE) { $this-&gt;load-&gt;view('your_view'); } else { $this-&gt;load-&gt;model('num'); $X = $this-&gt;input-&gt;post('X'); $Xm = $this-&gt;input-&gt;post('Xm'); $Y = $this-&gt;input-&gt;post('Y'); $Ym = $this-&gt;input-&gt;post('Ym'); $X_result = $this-&gt;num-&gt;check_if_coord_thingy_exists('xone', $X); $Xm_result = $this-&gt;num-&gt;check_if_coord_thingy_exists('xtwo', $Xm); $Y_result = $this-&gt;num-&gt;check_if_coord_thingy_exists('yone', $Y); $Ym_result = $this-&gt;num-&gt;check_if_coord_thingy_exists('ytwo', $Ym); /* if ($X_result == TRUE &amp;&amp; $Xm_result == TRUE &amp;&amp; $Y_result == TRUE &amp;&amp; $Ym_result == TRUE) { //all things inputed match database } else { //all values don't match database } if ($X_result == TRUE &amp;&amp; $Xm_result == TRUE) : //all X things inputed match database endif; if ($Y_result == TRUE &amp;&amp; $Ym_result == TRUE) : //all X things inputed match database endif; */ $data['X_repsonse'] = ($X_result == TRUE ? 'X exist' : 'X doesn\'t exist'; $data['Xm_repsonse'] = ($Xm_result == TRUE ? 'Xm exist' : 'Xm doesn\'t exist'; $data['Y_repsonse'] = ($Y_result == TRUE ? 'Y exist' : 'Y doesn\'t exist'; $data['Ym_repsonse'] = ($Ym_result == TRUE ? 'Ym exist' : 'Ym doesn\'t exist'; $this-&gt;load-&gt;view('your_view', $data); } } ?&gt; &lt;?php /* Model *************************/ class Num extends CI_Model { function check_if_coord_thingy_exists($value, $variable) { $this-&gt;db-&gt;select($value); $this-&gt;db-&gt;where($value, $variable); $query = $this-&gt;db-&gt;get('num'); if ($query-&gt;num_rows() &gt; 0) { //Value exists in database return TRUE; } else { //Value doesn't exist in database return FALSE; } } } ?&gt; &lt;?php /* View -&gt; your_view.php *************************/ echo validation_errors('&lt;div class="message"&gt;', '&lt;/div&gt;'); if (!empty($X_response)) echo '&lt;div class="message"&gt;X: '.$X_response.'&lt;/div&gt;'; if (!empty($X_response)) echo '&lt;div class="message"Xm: &gt;'.$Xm_response.'&lt;/div&gt;'; if (!empty($X_response)) echo '&lt;div class="message"&gt;Y: '.$Y_response.'&lt;/div&gt;'; if (!empty($X_response)) echo '&lt;div class="message"&gt;Ym: '.$Ym_response.'&lt;/div&gt;'; ?&gt; &lt;?php echo form_open('something/coord_check'); ?&gt; &lt;?php echo form_label('First Coord', 'X'); ?&gt;&lt;br&gt; &lt;?php $first_coord = array('name' =&gt; 'X', 'id' =&gt; 'X', 'value' =&gt; set_value('X')); ?&gt; &lt;?php echo form_input($first_coord); ?&gt;&lt;br&gt; &lt;?php echo form_label('Second Coord', 'Xm'); ?&gt;&lt;br&gt; &lt;?php $second_coord = array('name' =&gt; 'Xm', 'id' =&gt; 'Xm', 'value' =&gt; set_value('Xm')); ?&gt; &lt;?php echo form_input($second_coord); ?&gt;&lt;br&gt; &lt;?php echo form_label('Third Coord', 'Y'); ?&gt;&lt;br&gt; &lt;?php $third_coord = array('name' =&gt; 'Y', 'id' =&gt; 'Y', 'value' =&gt; set_value('Y')); ?&gt; &lt;?php echo form_input($third_coord); ?&gt;&lt;br&gt; &lt;?php echo form_label('Fourth Coord', 'Ym'); ?&gt;&lt;br&gt; &lt;?php $fourth_coord = array('name' =&gt; 'Ym', 'id' =&gt; 'Ym', 'value' =&gt; set_value('Ym')); ?&gt; &lt;?php echo form_input($fourth_coord); ?&gt;&lt;br&gt; &lt;?php echo form_submit('submit', 'Coord Check or Whatever'); ?&gt; &lt;?php echo form_close(); ?&gt; </code></pre> <p>Hopefully this helps. This is all assuming you autoload your database and form_validation libraries.</p> <p>Lastly, your database is strange. X and Y I feel should be different tables. I don't know the extent of your project though. Good luck!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload