Fiji Web Design
Welcome, Guest
Please Login or Register.    Lost Password?
Re:PHP Module Code Examples (1 viewing) (1) Guest
Go to bottom Post Reply Favoured: 0
TOPIC: Re:PHP Module Code Examples
#732
admin (Admin)
Admin
Posts: 475
graph
User Online Now Click here to see the profile of this user
Re:PHP Module Code Examples 2 Years, 11 Months ago Karma: 10  
An object in PHP is accessed with the following syntax:

$Object->property
The property is typed literally by name, just as it is. Arrays are different because the index has to be a datatype, that is an integer or a string etc. So string indexes (associative arrays) need to be enclosed in quotes.
$result = $db->loadObjectList();
will return an Array, containing Objects. Each Object will have properties that reflect the columns from the table you select from. Take for example the users table (jos_users). It has among others the "id", "username" and "name" columns. When you query the table:
$db->setQuery("SELECT id, username, name FROM jos_users LIMIT 10");
You get an Array, with each index in the array, containing an object. Each object has an id, username and name property that holds the corresponding values of the columns in the database. Say you want to output the results to a table:
$result = $db->loadObjectList();

echo '<table>';
echo '<tr>';
echo '<th>ID</th>';
echo '<th>Username</th>';
echo '<th>Name</th>';
echo '</tr>';

echo '<tr>';
foreach($result as $row) {
   echo '<td>'.$row->id.'</td>'; // jos_users.id
   echo '<td>'.$row->username.'</td>'; // jos_users.username
   echo '<td>'.$row->name.'</td>'; // jos_users.name
}
echo '</tr>';

echo '</table>';
Note the $row->id, $row->username and $row->name. These retrieve the values for the columns id, username, and name in the jos_users table.
 
Report to moderator   Logged Logged  
  The administrator has disabled public write access.
#735
tcnrahul (User)
Fresh Boarder
Posts: 5
graphgraph
User Offline Click here to see the profile of this user
Re:PHP Module Code Examples 2 Years, 11 Months ago Karma: 0  
I am most obliged. Thank you for being generous with your time. I will be sure to come back to see how I can reciprocate.

Thanks again.
 
Report to moderator   Logged Logged  
  The administrator has disabled public write access.
#736
admin (Admin)
Admin
Posts: 475
graph
User Online Now Click here to see the profile of this user
Re:PHP Module Code Examples 2 Years, 11 Months ago Karma: 10  
You're most welcome.
 
Report to moderator   Logged Logged  
  The administrator has disabled public write access.
#1181
gillespie (User)
Fresh Boarder
Posts: 1
graphgraph
User Offline Click here to see the profile of this user
Re:PHP Module Code Examples 1 Year, 11 Months ago Karma: 0  
Thanks for sharing nice suggestions..
 
Report to moderator   Logged Logged  
  The administrator has disabled public write access.
#1231
Andreas24105 (User)
Fresh Boarder
Posts: 2
graphgraph
User Offline Click here to see the profile of this user
Re:PHP Module Code Examples 1 Year, 6 Months ago Karma: 0  
Hey there, I am pretty new to this module and got a question: I want to display a dropdown in the left module position below the mainmenue. Depending on the choice I want the result being displayed in the center position then after pressing the "SEND" button.

How do I connect this two scripts in two different module positions? Do I have to use 2 copies of mod_php and connect them via ...itemID? Thanx for help!
 
Report to moderator   Logged Logged  
  The administrator has disabled public write access.
#1351
TommyRay (User)
Fresh Boarder
Posts: 4
graphgraph
User Offline Click here to see the profile of this user
Confirmation Popup with Cookie code 1 Year ago Karma: 0  
Nothing superbly great, but thought this might be useful to someone.

I have a website packed with content. An important message was needed displaying to website visitors, so they wanted a pop-up to display the information.

Here is the result that works great for that purpose. It displays text in the module, and if there is not cookie, it sets one to last 1 hour and displays the popup message box.


<?php
	// ===========================================
	// PHP_Mod Confirmation Message Popup w/Cookie
	// By TommyRay (Visit me at www.TommyRay.net)
	// ------------------------------------------
	// Displays Ad in a Module Position using the
	// Joomla extension Mod_PHP and displays a
	// Confirmation Popup Message with a cookie
	// to not display Popup again for 1 hour.
	// ==========================================
	// Define Functions...
	function confirm($msg) {
		// This is the function to evoke the Confirmation Popup message
		echo "<script langauge=\"javascript\">alert(\"".$msg."\");</script>";
	}
	
	function display() {
		// This is the content to be displayed in the module
		echo "<center><b><u>JAC Awards is Here!</u></b></center><hr><br />";
		echo "Be sure to nominate your favorite artist and attend the premiere UAA Artist Awards event!<br />";
		echo "<br /><a href=\"http://www.rockcountyarts.com/component/content/article/1-latest-news/81-now-taking-jac-awards-nominations\"><br />More Info</a>";
	}
	
	// Start MCP
	// Check for a Cookie...
	if (isset($_COOKIE["UAA-JAC"])) {
		// There IS a cookie, do not display popup
	}
	else {
		// There is NO cookie, so make one to last 1 hour and call the function
		// to display the Confirmation popup...
		setcookie("UAA-JAC", "read", time()+3600, "/", ".rockcountyarts.com");
		// Set the message to be shown in the popup...
		$msg = "JAC awards are almost here!  The Janesville Area Community Awards are fast approaching! " +
                       "Please be sure to nominate your favorite artist and join us for this premier event.  From " +
                       "the nomination form to event details, find everything here on RockCountyArts.com! " +
                       "Thanks for visiting United Arts Alliance website!";
		// Call function to display the confirmation popup...
		confirm($msg); 
	}
	
	// Call the function to display the Module Text...
	display();
	
	// End of line
?>
I plan on improving this later, as you can see it lacks, but this is the basics that work very well. Such as an expiration date to stop displaying the information on. ANYWAY, I wanted to contribute!! Incidentally, I have been working out a neat "virtual pet" type of program that uses NO Database, to teach about pet ownership. (I got so far as being able to teach a trick, High-5, for Cats and Dogs.) If you wanna check it out or have some knowledge and wish to participate in help create it, here's a link... http://www.knotalone.com/vhspets From which I also plan to post snippets of useful stuff. THANKS for the great Joomla Module!!! -TommyRay
 
Report to moderator   Logged Logged  
 
Last Edit: 2011/01/31 14:02 By TommyRay.
  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.