Welcome Guest, Not a member yet? Register   Sign In
How to Update a Record
#1

[eluser]Greg Aker[/eluser]
Hello,
First off, I have pretty limited PHP/MySQL knowledge, and after watching the tutorials on this site and doing some searching on php.net, I'm getting the swing of building an admin app that will work for me. For now, there are only two admins that will need to access a table that will line up with my ee db, the table is "outside" (b/c I can not dissect the {exp:weblog:entries} tags to make it work for me) of ee, so I am building a simple backend to access it. I am not having to duplicating any services between ee & ci, they will compliment each other well. Anyway, getting onto my question.
On the tutorial, following the "blog $_POST" part, I am able to insert information into my db table. now, I'd REALLY like to figure out how to (in another function) to be able to call that info by the auto-incrementing id, display all of the info in the row into the <table> I put it in with. I have tried to add things like:
Code:
value="&lt;?=$row->row_name?&gt;"
Into my inputs, but they all seem to throw php errors.
Can anyone help with that?
When I can get this working, I'll add form validation.
Here is the code from my controller, as it is now.
Code:
function update()
    {
        $data['title'] = "Update the Question";
        $data['heading'] = "Update the Question";
        $data['query'] = $this->db->get('test');

        $this->db->where('ques_num', $this->uri->segment(3));    
        $this->load->view('questionUpdate_view', $data);
    }

here's my view file:
Code:
&lt;?php include('includes/phpIncludes/top.inc.php');?&gt;
&lt;body&gt;
<div class="masthead">
    <div class="mastheadLogo"></div>
&lt;?php include('includes/phpIncludes/nav.inc.php');?&gt;    
</div>

<div class="wrapper">
         <div id="box-top">
        <h1>&lt;?=$title?&gt;</h1>
            &lt;?php foreach($query->result as $row): ?&gt;
                <h2>Category: &lt;?=$row->cat_id?&gt;</h2>
                <div style="float:left;">
                <p>&lt;?=$row->question?&gt;</p>
                <ol>
                    <li>&lt;?=$row->ans_1?&gt;</li>
                    <li>&lt;?=$row->ans_2?&gt;</li>
                    <li>&lt;?=$row->ans_3?&gt;</li>
                    <li>&lt;?=$row->ans_4?&gt;</li>
                </ol>
                </div>
                <div style="float:right; margin:0 0 10px 10px;">
                
                &lt;?php if (file_exists('full_server_path/images/practice_test/$row->img ')) {
                    echo "<img src=/images/practice_test/$row->img />";
                    }
                ?&gt;
                
                </div>
                <div style="clear:both"></div>
                <p><strong>Answer:</strong>&nbsp;&nbsp;&lt;?=$row->real_ans?&gt;,
                
                &lt;?php if ($row->real_ans == 1) {echo $row->ans_1;}elseif($row->real_ans == 2){echo $row->ans_2;}elseif ($row->real_ans == 3){echo $row->ans_3;}elseif ($row->real_ans == 4){echo $row->ans_4;}?&gt;</p>
                
                
                <p><strong>Reasoning:</strong><br />
                &lt;?=$row->extra?&gt;</p>
                <hr />                

            &lt;?=form_open('questions/questionInsert');?&gt;
            <table width="800px" border="0" cellspacing="0" cellpadding="3px">
              <tr>
                <td><strong>Category ID</strong></td>
                <td><select name="cat_id">
                        <option value="1">Basic Sciences (Anatomy, physiology, pathophysiology)</option>
                        <option value="2">Equipment, Instrumentation, Technology</option>
                        <option value="3">Basic Principles</option>
                        <option value="4">Advanced Principles</option>
                        <option value="5">Professional Aspects</option>
                    </select>
                </td>
              </tr>
              <tr>
                <td><strong>Question:</strong></td>
                <td>&lt;textarea name="question" rows="6" cols="43"&gt;&lt;/textarea&gt;</td>
              </tr>
              <tr>
                <td><strong>Possible Answer 1:</strong></td>
                <td>&lt;textarea name="ans_1" rows="2" cols="43"&gt;&lt;/textarea&gt;</td>
              </tr>
              <tr>
                <td><strong>Possible Answer 2:</strong></td>
                <td>&lt;textarea name="ans_2" rows="2" cols="43"&gt;&lt;/textarea&gt;</td>
              </tr>
              <tr>
                <td><strong>Possible Answer 3:</strong></td>
                <td>&lt;textarea name="ans_3" rows="2" cols="43"&gt;&lt;/textarea&gt;</td>
              </tr>
              <tr>
                <td><strong>Possible Answer 4:</strong></td>
                <td>&lt;textarea name="ans_4" rows="2" cols="43"&gt;&lt;/textarea&gt;</td>
              </tr>
              <tr>
                <td><strong>Real Answer:</strong></td>
                <td><select name="real_ans">
                        <option value="1">1</option>
                        <option value="2">2</option>
                        <option value="3">3</option>
                        <option value="4">4</option>
                    </select>
                </td>
              </tr>
              <tr>
                <td><strong>Justification &amp; Further Reading:</strong></td>
                <td>&lt;textarea name="extra" rows="10" cols="43"&gt;&lt;/textarea&gt;</td>
              </tr>
              <tr>
                <td><strong>Image URL:</strong></td>
                <td>&lt;input type="text" name="img"  cols="43" /&gt;</td>
              </tr>
            </table>
            &lt;input type="submit" value="Submit New Question" /&gt;
            &lt;/form&gt;
            &lt;?php endforeach;?&gt;
        </div>
        <div class="clear"></div>
           </div> &lt;!-- END .wrapper --&gt;
    <div class="containerBottom"></div>
&lt;/body&gt;
&lt;/html&gt;
I really hope everything above makes sense.
In advance, many thanks,
-greg
#2

[eluser]Alexxz[/eluser]
If &lt;?=$row->row_name?&gt; throws some errors, may be there is switched off short syntax. Try to enable $config['rewrite_short_tags'] in config file.
Or you can use full version &lt;?php echo $row->row_name; ?&gt;

If you can edit your php.ini, the best way is enable short syntax.
#3

[eluser]Greg Aker[/eluser]
I am using short tags in other places with no problem.

Thanks,

-greg

[quote author="Alexxz" date="1198848146"]If &lt;?=$row->row_name?&gt; throws some errors, may be there is switched off short syntax. Try to enable $config['rewrite_short_tags'] in config file.
Or you can use full version &lt;?php echo $row->row_name; ?&gt;

If you can edit your php.ini, the best way is enable short syntax.[/quote]
#4

[eluser]Chris Newton[/eluser]
Code:
$this->db->where('ques_num', $this->uri->segment(3));  
        $data['query'] = $this->db->get('test');

Shouldn't those 2 items be switched? Also, what PHP errors are you getting?




Theme © iAndrew 2016 - Forum software by © MyBB