News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

get category id from database

Started by yureka, January 19, 2013, 17:27:59 PM

Previous topic - Next topic

yureka

Hello, I wrote the following code to get virtuemart category id with name "app" from database. but its not displaying anything.please help. I use joomla 2.5 and latest version of virtuemart

$db =&  JFactory::getDBO();
$query = $db->getQuery(true);
$query->select('virtuemart_category_id');
$query->from('#__virtuemart_categories_en_gb');
$query->where('category_name = "app" ');   //put your condition here   
$db->setQuery($query);
$o= $db->loadObjectList();
echo $o[0]->virtuemart_category_id;


my database table prefix is nyhar_ . I wrote the above code in category view page and it doesn't show anything.Please help me.

Peter Pillen

I was not able to test this in any way, but maybe it gets you a bit further
<?php
$condition="app";

$o = JFactory::getDBO();
$o->setQuery("SELECT virtuemart_category_id FROM #__virtuemart_categories_en_gb WHERE category_name = ".$condition.";");
$o->query();
$records_containing_condition = $o->loadAssoc(); 

echo $records_containing_condition[0];
?>

yureka

Thanks for your answer.. But I guess there is some little fault in it...its not printing anything.  Anyway I got the answer:
$db = JFactory::getDBO();
$query = $db->getQuery(true);
$query->select('*');
$query->from('#__virtuemart_categories_en_gb');
$query->where('category_name = "app" ');   
$db->setQuery($query);
$o= $db->loadResult();
echo $o;