Fiji Web Design
Welcome, Guest
Please Login or Register.    Lost Password?
Re:check user lever and db connect (1 viewing) (1) Guest
Go to bottom Post Reply Favoured: 0
TOPIC: Re:check user lever and db connect
#1061
allos (User)
Fresh Boarder
Posts: 3
graphgraph
User Offline Click here to see the profile of this user
check user lever and db connect 2 Years, 3 Months ago Karma: 0  
First of all i would like to say that this is the most useful component i have ever install on joomla after 5 years of using joomla.

I have two questions.
I create a page with some forms to add some stuff in the database.And the results of the database after the forms.

First i would like to ask how to hide the forms from public so they can see only the results.Is there a check to see if someone is admin to see the forms ?

Second i would like to ask something about the connection to the database. I have to add to the start of my php code the mysql_connect, mysql_select_db.... Is there a way to connect to the database like joomla does ? If i try to connect without these i get "Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource..."

Thanks
 
Report to moderator   Logged Logged  
  The administrator has disabled public write access.
#1062
admin (Admin)
Admin
Posts: 475
graph
User Online Now Click here to see the profile of this user
Re:check user lever and db connect 2 Years, 3 Months ago Karma: 10  
Thanks for the kind words.

To check the user type, use:

$User =& JFactory::getUser();
if ($User->gid == 24 || $User->gid == 25) {
 // administrator
}
Admins have gid of 24 and Super Admins 25. If you want to use an external database:
// your db specific settings
$options = array ( 
  'driver' => 'mysql', 
  'host' => 'your-database-server.com', 
  'user' => 'user', 
  'password' => 'password', 
  'database' => 'database-name', 
  'prefix' => '' 
);
// get a mysql class instance using Joomla DB Factory
$Db =& JDatabase::getInstance( $options );
If you want to use the Joomla database, there is already a connection to it. Retrieve it via:
$Db =& JFactory::getDBO();
 
Report to moderator   Logged Logged  
  The administrator has disabled public write access.
#1063
allos (User)
Fresh Boarder
Posts: 3
graphgraph
User Offline Click here to see the profile of this user
Re:check user lever and db connect 2 Years, 3 Months ago Karma: 0  
Ok the user check part works GREAT !!!!!

but i still get "Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in " if i use $Db =& JFactory::getDBO();

line of error is

$query3= mysql_query("SELECT * FROM wallpapers WHERE enable = '1'") ;
     while($apo = mysql_fetch_array($query3)) {
 
Report to moderator   Logged Logged  
 
Last Edit: 2009/10/23 03:15 By allos.
  The administrator has disabled public write access.
#1064
admin (Admin)
Admin
Posts: 475
graph
User Online Now Click here to see the profile of this user
Re:check user lever and db connect 2 Years, 3 Months ago Karma: 10  
You need to supply the database link as the second parameter to mysql_query();

$query3= mysql_query("SELECT * FROM wallpapers WHERE enable = '1'", $Db->_resource) ;
     while($apo = mysql_fetch_array($query3)) {
You can however user the JDatabase methods to query the db.
$db = JFactory::getDBO();  
$query = "SELECT * FROM wallpapers WHERE enable = '1'";
$db->setQuery( $query );
$result = $db->loadObjectList();
if($db->getErrorNum()) {
   JError::raiseError( 500, $db->stderr());
   jexit();
}
foreach($result as $row) {
  echo $row->field_name; // etc..
  echo '<br />';
}
 
Report to moderator   Logged Logged  
 
Last Edit: 2009/10/23 03:31 By admin.
  The administrator has disabled public write access.
#1065
admin (Admin)
Admin
Posts: 475
graph
User Online Now Click here to see the profile of this user
Re:check user lever and db connect 2 Years, 3 Months ago Karma: 10  
After you get the DB instance, you may also want to check if it was an actual JDatabase instance, or an error (JError instance).

Example:

// your db specific settings  
$options = array (   
  'driver' => 'mysql',   
  'host' => 'your-database-server.com',   
  'user' => 'user',   
  'password' => 'password',   
  'database' => 'database-name',   
  'prefix' => ''   
);  
// get a mysql class instance using Joomla DB Factory  
$Db =& JDatabase::getInstance( $options );  

if (JError::isError($Db)) {
  // we had an error connecting to db
  // Joomla should handle it automatically so just exit
  jexit();
}
 
Report to moderator   Logged Logged  
 
Last Edit: 2009/10/23 03:30 By admin.
  The administrator has disabled public write access.
#1066
allos (User)
Fresh Boarder
Posts: 3
graphgraph
User Offline Click here to see the profile of this user
Re:check user lever and db connect 2 Years, 3 Months ago Karma: 0  
One million thanks !!! it works just great !!!
Thanks a lot for you help .
GREAT support !!!
Keep the good work!
 
Report to moderator   Logged Logged  
  The administrator has disabled public write access.
Go to top Post Reply
Powered by FireBoardget the latest posts directly to your desktop

Joomla Downloads

DownloadsDownload our free Joomla! Components, Modules and Plugins.