CodeIgniter Forums
search in two tables - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: search in two tables (/thread-53383.html)

Pages: 1 2


search in two tables - El Forum - 07-22-2012

[eluser]anyamanggar[/eluser]
help me pleasee


search in two tables - El Forum - 07-22-2012

[eluser]skunkbad[/eluser]
First, why do you have identical table structure for two tables?

Code:
CREATE TABLE `berita` (
  `id` int(11) NOT NULL auto_increment,
  `title` varchar(200) NOT NULL,
  `slug` varchar(200) NOT NULL,
  `tanggal` datetime default NULL,
  `img_path` text NOT NULL,
  `intro` text NOT NULL,
  `content` text NOT NULL,
  `kategori` varchar(100) NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=19 ;

CREATE TABLE `info` (
  `id` int(11) NOT NULL auto_increment,
  `title` varchar(200) NOT NULL,
  `slug` varchar(200) NOT NULL,
  `tanggal` varchar(100) NOT NULL,
  `img_path` text NOT NULL,
  `intro` text NOT NULL,
  `content` text NOT NULL,
  `kategori` varchar(100) NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=6 ;

As you can see, these tables are identical. It is poor database design to have two tables that are identical, but if this is your only option, then how are the tables related? What is the link between the two tables? In most tables you have a unique ID as a "primary key" and you have a field in the second table that is a "foreign key". Use google for more information about relational database design if these terms are confusing you.

CodeIgniter is meant to be a way to organize code and it more or less creates shortcuts for you. This is the general purpose of a framework in my opinion. It would seem that you may not have enough experience using PHP and MySQL to use CodeIgniter effectively. If the CodeIgniter documentation on Active Record does not allow you to form your query easily, you can always resort to creating a query with raw sql:

Code:
$sql = '
     SELECT * FROM table1 LEFT JOIN table2 ON table1.field = table2.field2 WHERE table1.field3 = "something" LIMIT 1
';

$this->db->query( $sql );

If your problem is that you don't know enough about MySQL / SQL, then I suggest trying to learn more before proceeding with your application. Also, if your PHP skills are lacking, you may find that it is beneficial to learn more about PHP before using CodeIgniter. I'm working full time with PHP, and have been using it for over 6 years, and still have lots to learn. Don't be offended, but I just don't believe that CodeIgniter is for all experience levels.

I can't write your code for you, but willing to help if you have questions that I can answer. I'm in GMT -8:00, so it's time for me to go to sleep. Perhaps somebody else can help you if you have more questions.


search in two tables - El Forum - 07-22-2012

[eluser]anyamanggar[/eluser]
[quote author="skunkbad" date="1343025503"]

I can't write your code for you, but willing to help if you have questions that I can answer. I'm in GMT -8:00, so it's time for me to go to sleep. Perhaps somebody else can help you if you have more questions.[/quote]

thanks skunkbad.. i will more learn for php & mysql