Welcome Guest, Not a member yet? Register   Sign In
  A Good Zip Code Database Schema
Posted by: El Forum - 01-02-2009, 10:52 PM - Replies (8)

[eluser]Xeoncross[/eluser]
I found a couple of them but I was wondering if anyone knows a more current copy of the USA (or even better "western world") zipcodes. free-zipcodes.com has a descent(?) copy from 2006 - but I don't want to start with it if there is something better.

I also found these:
micahcarrick.com
phpclasses.com/522
phpZipLocator
populardata


Quote:From Elvix

Another solution to buying a Zip code DB is to use Google Map’s geocoder. I extracted the geocoding functions from a CI-enabled Google Maps API library I found, and just do queries for the Zips as they’re needed, saving the results in a DB table so I don’t have to look them up again. Works great and handles US, Canada, Japan, Europe—well, anywhere Google goes. - http://ellislab.com/forums/viewthread/78436/#393541

Anyone have some advice?


  Strange validation error message issue
Posted by: El Forum - 01-02-2009, 10:45 PM - Replies (4)

[eluser]newbrand[/eluser]
Hello,

I seem to be experiencing some strange issues with CI when creating my first registration script. I'm trying to modify the error message displayed on a callback function to check the availability of a display name.

Here's a quick sampling of the code:

Code:
<?php

class Register extends Controller {

    function Register()
    {
        parent::Controller();    
    }
    
    function index()
    {
        $this->load->library('form_validation');
        $this->load->database();
        $view = array();
        if (isset($_POST['register']))
        {
            $this->form_validation->set_rules('display', 'Display Name', 'trim|required|alpha_numeric|xss_clean|max_length[20]|callback_display_check');
            $this->form_validation->set_rules('email', 'E-Mail', 'trim|required|valid_email|callback_email_check');
            $this->form_validation->set_rules('firstname', 'First Name', 'trim|required|xss_clean');
            $this->form_validation->set_rules('lastname', 'Last Name', 'trim|required|xss_clean');
            $this->form_validation->set_rules('pass', 'Password', 'trim|required|matches[passconfirm]');
            $this->form_validation->set_rules('passconfirm', 'Confirm Password', 'trim|required');
            print_r($this->form_validation);
            if ($this->form_validation->run() == true)
            {
//                $this->db->query("INSERT INTO users SET display = ?, email = ?, firstname = ?, lastname = ?, datereg = ?, password = ?",
//                                 array($_POST['display'],
//                                       $_POST['email'],
//                                       $_POST['firstname'],
//                                       $_POST['lastname'],
//                                       date("Y-m-d H:i:s"),
//                                       md5($_POST['pass'])));
                $this->send_registration($this->db->insert_id(), $_POST['display'], $_POST['email']);
                $view['display'] = $_POST['display'];
                $view['success'] = "Thank you for registering, an activation e-mail has been sent to your inbox. " .
                                   "Follow the link in the e-mail to complete the activation process and login.";
            }
        }
        $this->load->view('register', $view);
    }
    
    function send_registration($id, $display, $email) {
        require_once 'lib/SiteMailer.php';
        $mailer = new SiteMailer();
        $mailer->to($_POST['email']);
        $mailer->message("Dear {$display},<br><br>Thank you for registering for {SITENAME}. To complete the registration process" .
                "follow this link: <a >config->item('base_url')}/activate/{$active_id}'>" .
                "{$this->config->item('base_url')}/register/activate/{$active_id}</a>. Once you have activated the account" .
                "successfully, you may continue to login.<br><br>Thank you,<br><br>{$this->config->item('site_name')}");
        $mailer->send();
    }
    
    function email_check($email)
    {
        $query = $this->db->query("SELECT user_id FROM users WHERE email = '{$email}'");
        if ($query->num_rows() != "0")
        {
            
            $this->form_validation->set_message('email', 'The e-mail address is already registered.');            
            return false;
        }
        return true;
    }
    
    function display_check($display)
    {
        $query = $this->db->query("SELECT user_id FROM users WHERE display = '{$display}'");
        if ($query->num_rows() != "0")
        {
            $this->form_validation->set_message('display', 'The display name is already in use.');
            return false;
        }
        return true;
    }
    
}

?&gt;

Pretty sure I've got everything in place but I keep getting this error message displaying: Unable to access an error message corresponding to your field name.

So I went ahead to debug it, found a posting on the forum regarding the issue from May 2008 which suggested a hack workaround to modify the reference - implemented it, didn't work. So I dug a bit deeper. If I add the message at line 59 and do a print_r() on the validation object (print_r($this->form_validation)Wink it displays the object accordingly with the _error_messages array in the object set with the proper value. I then do the same thing at line 23 after the validation and it appears as though the message hasn't been carried over.

Thus the message displays in the callback function but not in the main code. This seems to be an issue with references though I'm not 100% sure on how to track it down or solve it. I'm a bit curious however because this is basically the same code as in the user guide - perhaps it's a bug specific to my PHP version?

Using PHP Version 5.2.5 - any ideas for a proper way to fix it (or a hack if I get desperate)?

Loving CI, just want it to work :-p

Cheers,

Dave


  forms in my model?
Posted by: El Forum - 01-02-2009, 09:56 PM - Replies (3)

[eluser]ixxalnxxi[/eluser]
Hello All,

In the site I'm developing there is a comment feature. The comment feature will be used over again for different things such as media, articles, blogs, news, etc. I decided to make only one table for comments and then set table and field_id columns so that comments could be inserted for content in different tables.

Now to the question, I am going to be displaying a form for submitting comments and I would rather not rewrite the code for every time I need it (the benefits of OOP, right?). My plan was to put the form display function in my comments model because anytime the model is loaded it would be necessary to have the form too. Is this a bad idea? I fear I might be blurring views and models.


  codeigniter is not parsing html from db for php tags...?
Posted by: El Forum - 01-02-2009, 07:21 PM - Replies (4)

[eluser]Colin McCubbin[/eluser]
I'm new to codeIgniter and an struggling with this.. :-S

If I put some php code in &lt;?php...?&gt; tags in amongst the html in a view file, codeigniter parses and acts on the php before sending the page to the browser with no problem.

But if I put that same block of mixed html and php in a database field and then get codeigniter to get it from the db, place it in a variable and output it, the php is not parsed and just shows up as text..

EG. I load the html helper in my controller, and in my view.php file have

Code:
&lt;?php echo img('system/application/pics/Aragon.jpg');?&gt;
The image shows up fine in the browser.

If however I place the same line in my db field and get that and output it, it jus appear as a text string... So I get no image in the page, and if I 'view source' I see the php tags in the source..

What am I doing wrong here? Do I have to pass the db contents back into the php parser somehow? I'd have thought that codeigniter would have done that..

Thanks!


  Counting number of results (i.e. rows) returned from a query (not Active Record)
Posted by: El Forum - 01-02-2009, 07:02 PM - Replies (3)

[eluser]fireproofsocks[/eluser]
I've got a complex SQL query, so I'm using the following construct:

Code:
$query = $this->db->query("SELECT stuff [...]");

I'm not so familiar with Active Record (I'm new here), and I don't think it'll work nicely with my query anyway... I got a lot of joins and GROUP_CONCAT's and stuff, so I'd rather just stick to straight SQL statements (I'm more familiar with them anyway).

How can I count the number of records? The following only works for active record queries...
Code:
$this->db->count_all_results();

I'm hoping for something like mysqli's mysqli_num_rows function. Anybody have any suggestions? Thanks.


  Session Assistance/Advice
Posted by: El Forum - 01-02-2009, 06:27 PM - Replies (7)

[eluser]foxman149[/eluser]
I love CI!!!

This is my first post after reading the forum for a couple of months all of my questions have answers in here..all accept this one.

I am using CI 1.7 sessions with DB enabled. My application is a ajax (jquery) heavy application.

Heres the logic
-I have a form that collections information for a search
-I build the sql using active record and store the sql (not the data) in the session
-I present the search results no problem
-The results has a button to print the results in a pdf
-I then grab the sql from session re run the query and build the pdf.

This works beautifully but here is my problem.
The session sql is not being updated all the time. I check the database and the query is there as it should be however when I run it the pdf prints my previous stored session sql. To test the session I print $this->session->userdata('sql') and it shows correctly. I can however get it to run perfect every time if I set $config['sess_time_to_update'] = 1

I am pretty sure setting this to 1 second is not good practise any suggestions? Is it really every second or just everytime the user makes a request? Maybe I should use some other implementations of sessions around the place and from most part that seems like what most people have done...thanks in advance.


  DB Session Using Wrong Database (FIXED)
Posted by: El Forum - 01-02-2009, 05:46 PM - No Replies

[eluser]edwa5823[/eluser]
(UPDATE) It ended up being some crazy piece of data that came from my testing environment (XAMPP). I copied all pertinent files back over from a fresh install and it worked like a charm.

----------------------------------------------------------------------------------

I am sure this is just me missing something, but I have searched the forums and scoured my code and can't figure this one out.

I am on a hosted account and am forced to use a prefix for all of my database tables. I have my session table built correctly as hostaccount_mywebsite.ci_sessions.

Now, when I try to use the database session feature I get the following error:


Code:
A Database Error Occurred

Error Number: 1146

Table 'mywebsite.ci_sessions' doesn't exist

INSERT INTO `ci_sessions` (`session_id`, `ip_address`, `user_agent`, `last_activity`) VALUES ('9bcb8f48b67b70dd251dee0704796adc', '127.0.0.1', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv', 1230939578)

As you can see above (mywebsite.ci_sessions) it is attempting to use a database name that is nowhere in my config files. It is frustrating because I keep checking my database config file but everything there is right, it connects to mysql, but then uses the wrong database.

Does 'Active Tables' require your database to follow a certain naming convention?

Any help would be GREATLY appreciated, thanks in advance!!


  Code to test a database connection
Posted by: El Forum - 01-02-2009, 05:16 PM - Replies (2)

[eluser]martillo[/eluser]
Anyone got a simple set of codes that I can use to initialise and test a database connection?

Ta.


  Upload library - Thumbnails
Posted by: El Forum - 01-02-2009, 04:56 PM - Replies (1)

[eluser]jaswinder_rana[/eluser]
Hi:

Does anybody has a modified Upload Library which also generates thumbnails along with uploading file (if image)?

I was wondering if you can share. I was hoping to avoid coding (or being lazy Smile) if I could.

Thanks


  Documentation Typo: $this->form_validation->set_rule();
Posted by: El Forum - 01-02-2009, 04:39 PM - No Replies

[eluser]Ian Cook[/eluser]
http://ellislab.com/codeigniter/user-gui...nreference

$this->form_validation->set_rule();

should be

$this->form_validation->set_rules();


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

Username
  

Password
  





Latest Threads
Heads up for users using ...
by InsiteFX
34 minutes ago
The Hidden Cost of “Innov...
by fcoder
1 hour ago
tool bar not showing
by InsiteFX
7 hours ago
Tool bar not showing
by InsiteFX
7 hours ago
Validation does not appea...
by grimpirate
Yesterday, 01:55 PM
Block IP addresses of bad...
by grimpirate
Yesterday, 01:47 PM
Override Router
by grimpirate
Yesterday, 01:30 PM
CodeIgniter.com - Report ...
by Vikas Mehta
06-30-2025, 10:30 AM
best way to store tokens ...
by ahallrod
06-30-2025, 10:03 AM
Hey Now it is a time for ...
by J0shflynn
06-29-2025, 06:44 AM

Forum Statistics
» Members: 154,296
» Latest member: kl99onl
» Forum threads: 78,435
» Forum posts: 379,706

Full Statistics

Search Forums

(Advanced Search)


Theme © iAndrew 2016 - Forum software by © MyBB