Welcome Guest, Not a member yet? Register   Sign In
  CI 1.7 active record database join error
Posted by: El Forum - 10-26-2008, 09:58 AM - Replies (2)

[eluser]Dewos[/eluser]
Backtrick broken?

Error on CI1.7 with table.* select:

Code:
$query = $this->db->select('news.*, comments.title AS comment_title')
        ->join('comments', 'news.id = comments.news_id', 'left')
        ->from($this->table)
        ->get();
                          
        return $query->row();

For Fix:
Code:
$query = $this->db->select('news.*', FALSE)
                ->select('comments.title AS comment_title')
        ->join('comments', 'news.id = comments.news_id', 'left')
        ->from($this->table)
        ->get();
                          
        return $query->row();


  How to rename table row while joining
Posted by: El Forum - 10-26-2008, 09:40 AM - Replies (4)

[eluser]Gewa[/eluser]
Hi, I have such problem in my controller. When I take an info of company and join city
Both of them have in the table row “id”
How to rename the ID in City and Region tables while joining them?

Here is part of code


Code:
$this->db->select('*');
                 $this->db->from('fa_user_profile');
                 $this->db->where('type','company');
                 $this->db->join('city','fa_user_profile.city_id=city.id','left');
                 $this->db->join('fa_user','fa_user_profile.id=fa_user.id','left');
                 $this->db->join('t_categories','fa_user_profile.subcat_id=t_categories.subcat_id','left');
                 $this->db->join('t_main_category','fa_user_profile.cat_id=t_main_category.cat_id','left');



                 $query=$this->db->get();
                 $qanak=$query->num_rows();


  Best Practices for Lookup Tables
Posted by: El Forum - 10-26-2008, 09:02 AM - No Replies

[eluser]ladyj001[/eluser]
I have a product table with several foreign keys to lookup tables (e.g., categories, formats, etc.)

In my Product_model class, I have a function that returns a product as an associative array (i.e., $product['name'], $product['price'], etc.

With regards to lookup fields, sometimes I want the foreign key (e.g., $product['category_id'] as in the case of generating an update form with a category drop down list. Other times, I want the lookup name as in the case of simple text output. For some views, I may actually need both (e.g., views with text output and form elements).

My question is what is the best way to implement lookup table relationships? There doesn’t seem to be a de facto standard.

Option 1 – In the past, I would simply do a join and return both the lookup id and name (e.g., $product['category_id'] and $product['category_name']). But something has always bothered me about having two fields that reference the same thing. In theory, one could change the value of $product['category_id'] without changing $product['category_name'].

Option 2 – Still use joins; but, for each lookup relationship create a sub-associative array (e.g., $product['category']['id'] and $product['category']['name']

Option 2 – Create a lookup helper or library that would load all needed lookup tables when loaded. Then in my views I could do something like

$this->load->helper('lookup',array('category','format'));

Product Category: <?php echo lookup($product['category_id']) ?>

The helper could also have a select_list function to be used to create arrays for dropdown lists e.g., form_dropdown('category_id',select_list('category'),$product['category_id'])

Just curious how other people deal with lookup tables.


  form_validation on forms that handle add+edit
Posted by: El Forum - 10-26-2008, 07:10 AM - Replies (13)

[eluser]chrisco23[/eluser]
Hi all,

I've been rebuilding my largest CI app.

In the old (currently live, working) version, I have a number of forms that serve the dual purpose of adding and editing records.

In my view files, I have code like the following:

Code:
<input type="text" name="username" value="<?php echo
isset($this->validation->name) ? $this->validation->name : NULL?>" />

In the case of "Edit" functionality, I would assign, for example, some existing database value to $this->validation->name before displaying my form. I was never very happy with the way the code read because I have a lot of lines of code with "validation" in the syntax before any validation is taking place.

With the new form_validation class though, it seems even more awkward due to the extent of abstraction.

How are people going about this? I can think of a few ways but I don't like any of them:

1. When reading fields from the db (edit mode), assign them to $_POST before calling the view file. The HTML looks like:
Code:
<input type="text" name="myVar" value="<?php echo set_value('myVar',
$_POST['myVar']);?>" />
2. When reading fields from the db (edit mode), assign each to $this->myVar in my controller, then the view file HTML looks like:
Code:
<input type="text" name="myVar" value="<?php echo set_value('myVar', $this->myVar)?>" />
3. When reading fields from the db (edit mode), assign them directly to $this->_field_data[fieldname]['postdata']. This is kinda similar to #1 but it's ugly to access "private" vars in this way.

Maybe it's from being up all night then running into this new library. Anybody see a better way?

I'm thinking Option #2 is probably the best I can come up with right now but even that is a pita because I have many optional fields and I have to either set a lot of fields to '' (empty quotes) to avoid error, or put a bunch of isset()'s in my view file...

Somebody see a cleaner way?


Thanks,
Chris


  Code for www.haughin.com Screencasts?
Posted by: El Forum - 10-26-2008, 06:27 AM - Replies (3)

[eluser]Sean Cannon[/eluser]
I have been working with CI for about 2 weeks now and have been digging through code, etc and I was wondering if anyone knew if the code for these screencasts was available. I am mainly interested in how he "modularized" CI but I couldn't figure out exactly what changes needed to be made.

If someone could point in the right direction I would appreciate it! :-)


  MySQLi Connection error
Posted by: El Forum - 10-26-2008, 06:01 AM - Replies (8)

[eluser]Atasa[/eluser]
Hello everyone,
I was very happy to see all these changes and progress to ci with version 1.7,
especially to the Validation class.
Please someone can confirm this...
There is an error coming out saying that Unable to connect to database with the provided settings.
For sure in 1.6.3 I was able to connect therefor I enabled the logs to see what's wrong.

Surprisingly the error was:

Severity: Warning --> mysqli_connect() expects parameter 5 to be long, string given /srv/www/ci/admin/system/database/drivers/mysqli/mysqli_driver.php 63

On line 63 exists the function db_connect(), and I am not using it.
I use the function db_pconnect() beacause I have set it to TRUE in my config file.

Any comment will be appreciated

A.


  Having little trouble getting data from database
Posted by: El Forum - 10-26-2008, 05:34 AM - Replies (4)

[eluser]faxtion[/eluser]
Got the following code but does not display anything in view, neither does it give me and error, any help appreciated

Code:
Controller

class Parts extends Controller {

    function index() {
        echo 'Hello World!';
    }
    
    function view() {
        $this->load->model('Parts_model');
        $data['parts'] = $this->Parts_model->get_parts();
        $this->load->view('parts_view', $data);
    }
}
?>

Code:
Model

<?php
class Parts_model extends Model {
    
    function Parts_model()
    {
        // Call the Model constructor
        parent::Model();
    }

    function get_parts() {
        //$query = $this->db->query('SELECT title FROM parts');
        $query = $this->db->get('parts', 10);
        return $query->result();
    }

}
?>


Code:
View


<html>
<head>
<title>Rally Parts Auction</title>
</head>
<body>
<h3>Parts</h3>  

<ul>
&lt;?php foreach($parts as $part):?&gt;

<h4>&lt;?=$part['postid']?&gt;</h4>
<p>&lt;?=$part['title']?&gt;</p>
<p>&lt;?=$part['description']?&gt;</p>
<p>&lt;?=$part['category']?&gt;</p>
<p>&lt;?=$part['image']?&gt;</p>
<p>&lt;?=$part['image1']?&gt;</p>
<p>&lt;?=$part['image2']?&gt;</p>

&lt;?php endforeach;?&gt;
</ul>

&lt;/body&gt;
&lt;/html&gt;


  Searching by tags with special characters?
Posted by: El Forum - 10-26-2008, 03:57 AM - Replies (4)

[eluser]gRoberts[/eluser]
hi all,

I've implemented a simple tag search for a clients site which works fine unless you type in characters like "'@# etc.

I then urlencoded the tag being used as the parameter but its still not working properly.

How do people handle tags with special characters in?

Cheers

Gavin


  jQuery Kills PHP Variables
Posted by: El Forum - 10-25-2008, 10:22 PM - Replies (9)

[eluser]spamguy[/eluser]
This is an odd one.

Let's say I have a page consisting of jQuery UI tabs. One of the tabs fetches a PHP doc that looks like this:

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

&lt;html&gt;
    &lt;head&gt;
        &lt;title&gt;View&lt;/title&gt;
    &lt;/head&gt;
    &lt;body&gt;
        &lt;?= $myvar ?&gt;
    &lt;/body&gt;
&lt;/html&gt;

$myvar is set in the appropriate controller:

Code:
function view()
        {
            $data['myvar'] = 1234;
            
                $this -> load -> view('view', $data);
        }

When view.php is viewed by itself (that is, not through jQuery tabs), $myvar prints properly. When it's viewed as an AJAX tab, though, I get a PHP error:

Quote:A PHP Error was encountered

Severity: Notice

Message: Undefined variable: myvar

Filename: confession/view.php

What can I do to fix or circumvent this?

Thanks!


  New CI 1.7 session class database error
Posted by: El Forum - 10-25-2008, 07:09 PM - Replies (29)

[eluser]CIfan1000[/eluser]
Hi,
I started using the new CI 1.7 session class with database based session variable storage, and got this error:

Quote:A Database Error Occurred

Error Number: 1364

Field 'user_data' doesn't have a default value

INSERT INTO `ci_sessions` (`session_id`, `ip_address`, `user_agent`, `last_activity`) VALUES ('5aa4c19ec6e1b86e0401e23f3dc27508', '127.0.0.1', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv', 1224982938)
I am not an experienced user/programmer but I think this is happening because the SQL query does not insert anything into the user_data field of the ci_sessions table. I looked at the design of this table and this field is set to NOT NULL so maybe it is expecting a value during an INSERT query.

Please please help. Thank you for your time and effort in advance.


Welcome, Guest
You have to register before you can post on our site.

Username
  

Password
  





Latest Threads
Codeigniter 4 Model set()...
by MZahov
58 minutes ago
CI Builder Question
by InsiteFX
4 hours ago
SecurityException Status ...
by kenjis
11 hours ago
E-mail and UTF-8, mb_, et...
by joho
Yesterday, 07:13 AM
Shield validation questio...
by Codinglander
Yesterday, 07:07 AM
CI4 support MariaDB?
by joho
Yesterday, 07:06 AM
Using phpCas in CI4 (Comp...
by Zeff
Yesterday, 04:55 AM
where clause with order_b...
by kenjis
Yesterday, 01:55 AM
Transient support for Set...
by kenjis
Yesterday, 01:52 AM
Sharing things between CI...
by joho
Yesterday, 01:39 AM

Forum Statistics
» Members: 82,313
» Latest member: ruksarkhanm20
» Forum threads: 77,479
» Forum posts: 375,528

Full Statistics

Search Forums

(Advanced Search)


Theme © iAndrew 2016 - Forum software by © MyBB