The Joomla! Forum ™



Forum rules


Please use the mailing list here: http://groups.google.com/group/joomla-dev-general rather than this forum.



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 19 posts ] 
Author Message
PostPosted: Wed Feb 04, 2009 11:53 am 
Joomla! Apprentice
Joomla! Apprentice

Joined: Fri Dec 05, 2008 2:11 pm
Posts: 18
i had created a table jos_mytable now i want to insert data into that table using joomla functions,
i had tried the following code
$db = JFactory::getDBO();
$query = "insert into #__mytable values('val1', 'val2', 'val3')";
$db->setQuery($query);

But this is not working for me;


Top
 Profile  
 
PostPosted: Wed Feb 04, 2009 12:06 pm 
User avatar
Joomla! Explorer
Joomla! Explorer

Joined: Sun Mar 18, 2007 12:50 pm
Posts: 332
Location: Netherlands
This should work:

Code:
$data =new stdClass();
$data->id = null;
$data->field1 = 'val1';
$data->field2 = 'val2';
$data->field3 = 'val3';

$db = JFactory::getDBO();
$db->insertObject( '#__mytable', $data, id );


'id' is the name for your primary key, change that if you're using a different name. Of course you need to also change the name of your other fields.

_________________
Cheers, Babs
-------------------
http://crossinghippos.com


Top
 Profile  
 
PostPosted: Wed Feb 04, 2009 12:11 pm 
User avatar
Joomla! Explorer
Joomla! Explorer

Joined: Sun Mar 18, 2007 12:50 pm
Posts: 332
Location: Netherlands
dinakar wrote:
$query = "insert into #__mytable values('val1', 'val2', 'val3')";


Incidently, your query syntax is off, it should be like:
Code:
"INSERT INTO #__mytable (field1, field2, field3) VALUES ('val1', 'val2', 'val3')"

_________________
Cheers, Babs
-------------------
http://crossinghippos.com


Top
 Profile  
 
PostPosted: Wed Feb 04, 2009 12:12 pm 
User avatar
Joomla! Explorer
Joomla! Explorer

Joined: Sun Mar 18, 2007 12:50 pm
Posts: 332
Location: Netherlands
One more thing: check this page for more refs: http://api.joomla.org/Joomla-Framework/Table/JTable.html

_________________
Cheers, Babs
-------------------
http://crossinghippos.com


Top
 Profile  
 
PostPosted: Fri Feb 20, 2009 6:10 am 
Joomla! Apprentice
Joomla! Apprentice

Joined: Sun Feb 15, 2009 3:37 am
Posts: 8
I'd like to continue this thread since I am having the same problem. I posted here once already but it didn't seem to show up so forgive me I double post.
My SQL works directly against the MYSQL server just not through joomla.

$database = JFactory::getDBO();
$sql = "INSERT INTO jos_cust_pictures (PicturePath) VALUES ('c:pictures')";
$database->setQuery($sql);

I browsed through the last link and being new to php and joomla it didn't ring a bell on anything I'm doing wrong and I did try the other code suggested above.

One thing I do notice is that if I go to joomla and reclick my link to the code multiple times when I go back to the server and run the insert on the server no records will show from the joomla action but the auto-increment has incremented like it did.

So for example:
SQL run on the server gives me a record for autoID = 4.
If I click on my code in joomla 5 times and then go back to the server and run the query local again I will only see one additional record after 4 but that new record will have autoID = 10.
So MYSQL has to registering the hit but not taking the data.

Any ideas? Do I need to make sure that anything specific is included to make this work?


Top
 Profile  
 
PostPosted: Fri Feb 20, 2009 8:36 am 
User avatar
Joomla! Exemplar
Joomla! Exemplar

Joined: Fri Sep 09, 2005 2:13 pm
Posts: 7962
Location: The Netherlands
did you look into any documentation.
Joomla! has his own classes to insert/update queries.
Start here for example: viewtopic.php?f=231&t=136576

_________________
Robert Dam - Joomla Forum Moderator
Dutch Boards | Joomla Coding Boards | English Support Boards


Top
 Profile  
 
PostPosted: Fri Feb 20, 2009 3:12 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Sun Feb 15, 2009 3:37 am
Posts: 8
Brother I didn't catch anything on that link that was lightbulb helpful. The link within the link that directs me to the where the thread has been redirected is also broken. Is the concept for the INSERT lengthy or can you help me out.


Top
 Profile  
 
PostPosted: Fri Feb 20, 2009 7:48 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Sun Feb 15, 2009 3:37 am
Posts: 8
I did find this documentation:
http://help.joomla.org/content/view/712/125/

But that code still doesn't insert the row. I am able to create the DB object and look at properties like DB prefix so the object is good. Do I need to make reference to the table somewhere so Joomla knows about it? The table is a custom table.


Top
 Profile  
 
PostPosted: Sat Feb 21, 2009 3:13 am 
Joomla! Apprentice
Joomla! Apprentice

Joined: Sun Feb 15, 2009 3:37 am
Posts: 8
Never mind. I'm using SQL Manager 2007 Lite and the SELECT query only shows changes made in the console. So the joomla code was working all along I just couldn't see it in the MYSQL admin app I'm using. I must be missing something on the functionality of the app. After a close it and open it again the SELECT statement shows the records.


Top
 Profile  
 
PostPosted: Wed Mar 18, 2009 9:42 am 
Joomla! Apprentice
Joomla! Apprentice

Joined: Fri Dec 05, 2008 2:11 pm
Posts: 18
i had impleted the below code for updation a row in a table but row was not updated how can i do this

$db =& JFactory::getDBO();
$query = "UPDATE #__ecom_id_generate SET TABLE_NAME=$tableName WHERE ID_VALUE=$id";
$db->setQuery($query);
$db->query();


Top
 Profile  
 
PostPosted: Fri Mar 12, 2010 10:27 am 
Joomla! Fledgling
Joomla! Fledgling

Joined: Fri Mar 05, 2010 1:37 am
Posts: 2
Thanks for the posts! How can I retrieve the ID of the new table row that has been created?


Top
 Profile  
 
PostPosted: Sat Apr 10, 2010 4:22 pm 
Joomla! Fledgling
Joomla! Fledgling

Joined: Sat Apr 10, 2010 4:19 pm
Posts: 1
$db =& JFactory::getDBO();
$query = "SELECT userid FROM #__acctexp_subscr where type != 'free' and userid = '$get_logged_user_id' ";
$db->setQuery($query);
$result = $db->loadObjectList();

foreach($result as $result_value){
foreach($result_value as $result_value_2){
$result_value_2.'<br />';

}

}

my name is Mohamed Ragab Dahab
email: m_ragab333@hotmail.com


Top
 Profile  
 
PostPosted: Mon May 09, 2011 3:34 pm 
Joomla! Fledgling
Joomla! Fledgling

Joined: Mon May 09, 2011 3:29 pm
Posts: 1
Thnkx for the post..:)


Top
 Profile  
 
PostPosted: Wed May 11, 2011 12:13 pm 
User avatar
Joomla! Guru
Joomla! Guru

Joined: Wed Sep 07, 2005 10:18 pm
Posts: 617
Location: London
Hi
I want to preserve simple links and html in a field I am trying the following but it gets stripped to plain text no tags....

Code:
$dataX =new stdClass();
...
$dataX->introtext = mysql_escape_string($data['introtext']);
...

$db->insertObject( '#__content', $dataX, id );


thanks

_________________
Check out the 'bad toilet' online !


Top
 Profile  
 
PostPosted: Wed Aug 31, 2011 9:03 am 
User avatar
Joomla! Fledgling
Joomla! Fledgling

Joined: Wed Aug 31, 2011 8:57 am
Posts: 1
Testado no Joomla 1.6.6 e (MySQLi)... OK

$database =& JFactory::getDBO();
$sql = "INSERT INTO #__minhaTabela (meu_campo) VALUES ('valor')";
$database->setQuery($sql);
$database->query(); //<<< confirmação


Espero ter ajudado!

[PT-BR]


Top
 Profile  
 
PostPosted: Wed Aug 31, 2011 9:18 am 
Joomla! Apprentice
Joomla! Apprentice

Joined: Mon Aug 29, 2011 12:55 pm
Posts: 20
Macsimice wrote:
dinakar wrote:
$query = "insert into #__mytable values('val1', 'val2', 'val3')";


Incidently, your query syntax is off, it should be like:
Code:
"INSERT INTO #__mytable (field1, field2, field3) VALUES ('val1', 'val2', 'val3')"


thanks Macsimice its very usefull fo me

_________________
http://www.dr-shadabi.ir
http://www.zarvansaffron.ir


Top
 Profile  
 
PostPosted: Wed Oct 31, 2012 11:44 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Sat Feb 28, 2009 11:04 am
Posts: 16
Location: London, UK
Can anybody tell me where in the MVC framework to add code to achieve the following as I'm quite new to the Joomla Development environment:

1. Read data from an existing table
2. Put that data in a new table
3. Output that data in a view page from the new table
4. Assign data to a unique user id in the new table

The data that is read and put in a the new table from an existing table must be connected, so for example if that data is deleted from the existing table, then the data in the new table should also be automatically deleted. I presume in MySQL speak that this is a JOIN or maybe not.

P.S. To the keen eyed person and admin, I've already mentioned a similar thread, but I didn't get any decent replies. I'm hoping this thread will be successful for me.


Top
 Profile  
 
PostPosted: Sat Nov 03, 2012 11:55 am 
Joomla! Apprentice
Joomla! Apprentice

Joined: Fri Aug 31, 2012 11:04 am
Posts: 43
hello evr1
i am trying to create a component in joomla 2.5 and i dont know how to get the data from for the <select>. i have created <select name="name"> in my default view and i want to insert that selected value in database, i know how to insert static value inside database using InsertObject as explaind by Macsimice and its working also but the null values coming inside the database ...
plz help me to store the selected value into database ..


Top
 Profile  
 
PostPosted: Tue Nov 06, 2012 7:30 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Sat Feb 28, 2009 11:04 am
Posts: 16
Location: London, UK
After many days of no response from anyone, especially a helpful developer, I don't think this is a good forum for Joomla talk. Stack Overflow forum is one of the best, at least you get a decent response.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 19 posts ] 



Who is online

Users browsing this forum: No registered users and 12 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group