Page 1 of 1

using appginis mysql built in features

Posted: 2015-06-23 17:56
by 4thstar
Hello.
I have a bit of code here that works for me, however I think I re-invented something already built into appgini.
as I am learning I thought I would post it here in the hope someone would tell me how to do the same but using functions already in place.

It collects the members names and places them into a form option box.

The code :

Code: Select all

	<?php 
	require ('config.php');
	$dbase = mysql_connect($dbServer, $dbUsername, $dbPassword);
	mysql_select_db($dbDatabase, $dbase);
	mysql_query("SET NAMES UTF8");
	unset($array);
	$query = mysql_query("SELECT * FROM membership_users WHERE groupID = '3' ORDER by memberID asc");
	while ($row = mysql_fetch_assoc($query)) {
	    $array[] = $row;
	}
	$num_rows = mysql_num_rows($query);
	for ($i = 0; $i < $num_rows;) {
	    echo '<option value="'.$array[$i]['memberID'].'">'.$array[$i]['memberID'].'</option>';
	  	    $i ++;
	}
	mysql_close($dbase);
		?>
Many thanks in advance.
Carl

Re: using appginis mysql built in features

Posted: 2015-06-24 05:17
by peebee
Member info is available to use in hooks and other code using the $memberInfo array

See here for more: http://bigprof.com/appgini/help/advance ... Info-array

You can retrieve this array in your own code by calling the function getMemberInfo(), which returns this array.

There's plenty of example uses in the Global Hooks support page: http://bigprof.com/appgini/help/advance ... obal-hooks and also a lot of other examples here in this forum: http://forums.appgini.com/phpbb/search. ... memberInfo

Example to echo Username:

Code: Select all

<?php
/* Get MemberInfo  */
   $curr_dir = dirname(__FILE__);
   include("{$curr_dir}/defaultLang.php");
   include("{$curr_dir}/language.php");
   include("{$curr_dir}/lib.php");   
   
   $mi = getMemberInfo();
   echo $mi['username'];
?>

Re: using appginis mysql built in features

Posted: 2015-06-24 10:11
by 4thstar
hello peebee.
thanks for the input..
I will be using an external page, i have also added the code you suggested to link to the main appgini file as above.

the question i have is that the code i supplied is a way of obtaining the data from the table and creating an array, then looping through to create the options inside the dropdown field.

the question though is that appgini has a file called db.php and a wide set of functions dealing with database use..

my code above is a standard way and it works..

BUT

can i shorten it and make use of the functions in db.php, if so how would i restructure my code above to obtain the same results..

What would be useful is a set of examples of how to use all the functions in db.php i.e. what gets put in and what comes out :)

Kind Regards
Carl

Re: using appginis mysql built in features

Posted: 2015-06-24 21:03
by a.gneady
Hello Carl,

You could make use of db.php functions as well the sql() function without having to initiate the connection. First, you should write your custom script like this: http://bigprof.com/appgini/help/advance ... cess-pages

Then instead of your code above, you can use this:

Code: Select all

$query = sql("SELECT * FROM membership_users WHERE groupID = '3' ORDER by memberID asc", $eo);
while ($row = db_fetch_assoc($query)) {
       $array[] = $row;
}

$num_rows = db_num_rows($query);

for ($i = 0; $i < $num_rows;) {
       echo '<option value="'.$array[$i]['memberID'].'">'.$array[$i]['memberID'].'</option>';
       $i ++;
}

Re: using appginis mysql built in features

Posted: 2015-07-13 21:45
by 4thstar
Thank you for that help, that's great, I am still early in the learning process :) thankyou..
Carl

Re: using appginis mysql built in features

Posted: 2017-08-09 14:06
by bambinou
Hopefully this will help someone...

If you are looking at creating SEO friendly URLS, you need to do this:

Code: Select all

<?php
	// For help on using hooks, please refer to https://bigprof.com/appgini/help/working-with-generated-web-database-application/hooks

	function news_init(&$options, $memberInfo, &$args){

		return TRUE;
	}

	function news_header($contentType, $memberInfo, &$args){
		$header='';

		switch($contentType){
			case 'tableview':
				$header='';
				break;

			case 'detailview':
				$header='';
				break;

			case 'tableview+detailview':
				$header='';
				break;

			case 'print-tableview':
				$header='';
				break;

			case 'print-detailview':
				$header='';
				break;

			case 'filters':
				$header='';
				break;
		}

		return $header;
	}

	function news_footer($contentType, $memberInfo, &$args){
		$footer='';

		switch($contentType){
			case 'tableview':
				$footer='';
				break;

			case 'detailview':
				$footer='';
				break;

			case 'tableview+detailview':
				$footer='';
				break;

			case 'print-tableview':
				$footer='';
				break;

			case 'print-detailview':
				$footer='';
				break;

			case 'filters':
				$footer='';
				break;
		}

		return $footer;
	}

	function news_before_insert(&$data, $memberInfo, &$args){

		return TRUE;
	}

	function news_after_insert($data, $memberInfo, &$args){

        update_seo_friendly_url($data);

		return TRUE;
	}

	function news_before_update(&$data, $memberInfo, &$args){


		return TRUE;
	}

	function news_after_update($data, $memberInfo, &$args){

        update_seo_friendly_url($data);

		return TRUE;
	}

	function news_before_delete($selectedID, &$skipChecks, $memberInfo, &$args){

		return TRUE;
	}

	function news_after_delete($selectedID, $memberInfo, &$args){

	}

	function news_dv($selectedID, $memberInfo, &$html, &$args){

	}

	function news_csv($query, $memberInfo, &$args){

		return $query;
	}
	function news_batch_actions(&$args){

		return array();
	}

    function update_seo_friendly_url($data){


    $seo_friendly     = trim($data['google_title']);
    $seo_friendly     = strip_tags($seo_friendly);
    $seo_friendly     = html_entity_decode($seo_friendly, ENT_QUOTES, "UTF-8");
    $seo_friendly     = strtolower($seo_friendly);
    $seo_friendly     = preg_replace('/\s+/', '-', $seo_friendly);




    $query = sql("SELECT seo_friendly_url FROM news group by seo_friendly_url having count(*) >= 2", $eo);
    $num_rows = db_num_rows($query);


    if ($num_rows >=2) {
    $seo_friendly  = $seo_friendly."-".$data['selectedID'];

     }

    sql("UPDATE news SET seo_friendly_url = '{$seo_friendly}'
         WHERE id={$data['selectedID']}", $eo);

    }
I did first generate a micro time number at the end of the url when a similar record was found but it does not make sense.....if you keep changing the number each time, Google will need to reindex the url again and again so instead I linked it to the id of the record, this way it will always be the same one whatever happens.
I have seen some people using $i++ to add a number to the url is a similar record is found, but again, this wont make sense for an SEO purpose.

So now on update or insert, the first google_title field will copy itself to the seo_friendly_url field while being cleaned up and modifyed to soemthing like word1-word2-word3, then if a duplicate title is found, the id of the article will show at the end of the url.



Feel free to change this code and repost better solutions here as there are many ways of doing this.....


Thank again Ahamad for the selectedID, I scratched my head on that one:-)