Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 11-20 of 21 total

Integrating reinvigorate name tags into a PHP site

This is a script which will intergrate reinvigorate name tags into your PHP site using cookies
Put this on any page you want to have visitors enter their name
<FORM ACTION="index.php" METHOD="GET">
<p>Name <INPUT TYPE=TEXT NAME= "n" SIZE=20><br>
<INPUT TYPE=SUBMIT VALUE="Submit!">

Put this on your index.php page at the top before anything. This will set a cookie that will last for 2 months
<?php
$Name = $_GET['n'];
?>
<?php
$inTwoMonths = 60 * 60 * 24 * 60 + time(); 
setcookie('name', $Name, $inTwoMonths); 
?>

Put this at the first line after the <body> tag. You need to change the USER-ID to your user ID that
you can get from the regular reinvigorate code.
<script type="text/javascript" src="http://include.reinvigorate.net/re_.js"></script>
<script type="text/javascript">
var re_name_tag = "<?php echo $Name; ?>";
re_("USER-ID");
</script>


mysqlcode

// description of your code here

// insert code here..

###Commonly SQL statements for MYSQL#############
11/4/2002 - JDM
##################################################
sub alldetails{
#localserver
$DBD = "mysql";
$dbase = "myroseweb";
$dbuser = "root";
$dbpassword = "";
$server = "localhost";
$dbh = DBI->connect
("dbi:$DBD:$dbase",$dbuser,$dbpassword) or die "couldn't do it";
$drh = DBI->install_driver("mysql");
$sth = $dbh->prepare("SELECT tblidx,title,presenter,descrip,mo,dom,yr,loc,ceus from tbltraining order by tblidx DESC") or die;
$sth->execute;
$numrows = $sth->rows();
$looper = 0;
while ($looper < $numrows){
($tid,$ttitle,$tpresenter,$tdescrip,$tmo,$tdom,$tyr,$tloc,$tceus) = $sth->fetchrow_array;
$row = "$tid:$ttitle:$tpresenter:$tdescrip:$tmo:$tdom:$tyr:$tloc:$tceus";
push @alltrngs, $row;
$looper++;
#endwhile
}
$sth->finish;
$dbh->disconnect;
#endsub
}

sub deletetdetail{
&doheader;
if ($step == 1){
&connectdb;
$statement=qq(DELETE FROM tblscd WHERE (indx = '$id'));
$sth = $dbh->prepare($statement);
$sth->execute;
$sth->finish;
print "<font class='shdtxt'>The record has been deleted.</font>";
}else{
print "Are you sure you want to delete this record?<p>";
print "<a href='/mir/scdadmin.cgi?cmd=9&id=$id&step=1'><b>Yes</a><p>";
print "<a href=\"javascript\:history\.go\(-1\)\"><b>No</b></a><p>";

#endstepif
}
&dofooter;

#endsub
}


###SELECT###########
&connectdb;
$sth = $dbh->prepare("SELECT doy,pdate,postby,menu,dy,wk,facility from tblmenu where indx='$id'") or die;
$sth->execute;
($doy,$pdate,$postby,$menu,$dy,$wk,$facility) = $sth->fetchrow_array;
$sth->finish;
$dbh->disconnect;

###########################################
###UPDATE########################

&connectdb;
$qpdate = $dbh->quote( $pdate );
$qbev = $dbh->quote( $bev );
$qentre1 = $dbh->quote( $entre1 );
$qentre2 = $dbh->quote( $entre2 );
$qside1 = $dbh->quote( $side1 );
$qside2 = $dbh->quote( $side2 );
$qside3 = $dbh->quote( $side3 );
$qside4 = $dbh->quote( $side4 );
$qpostby = $dbh->quote( $postby );
#indx,bev,lcbev,entre1,lcent1,entre2,lcent2,side1,lcside1,side2,lcside2,side3,lcside3,side4,
#lcside4,meal,mm,dm,yy,doy,pdate,postby,menu,dy,wk,facility

$sth = $dbh->prepare("UPDATE tblmenu SET bev=$qbev,lcbev='$lcbev',entre1=$qentre1,facility='$facility' WHERE indx='$id'") or die;
$sth->execute;
$sth->finish;

###########################################
###INSERT##################################
&connectdb;
$qpdate = $dbh->quote( $pdate );
$qbev = $dbh->quote( $bev );
$qentre1 = $dbh->quote( $entre1 );
$qentre2 = $dbh->quote( $entre2 );
$qside1 = $dbh->quote( $side1 );
$qside2 = $dbh->quote( $side2 );
$qside3 = $dbh->quote( $side3 );
$qside4 = $dbh->quote( $side4 );
$qpostby = $dbh->quote( $postby );
$indx = "";
$statement=qq
(INSERT INTO tblmenu (indx,bev,lcbev,entre1,lcent1,entre2,lcent2,side1,lcside1,side2,lcside2,side3,lcside3,side4,lcside4,meal,mm,dm,yy,doy,pdate,postby,menu,dy,wk,facility) VALUES('$indx',$qbev,'$lcbev',$qentre1,'$lcent1',$qentre2,'$lcent2',$qside1,'$lcside1',$qside2,'$lcside2',$qside3,'$lcside3',$qside4,'$lcside4','$meal','$mm','$dm','$yy','$doy','$pdate','$postby','$menu','$dy','$wk','$facility')) or die;
$sth = $dbh->prepare($statement);
$sth->execute;
$sth->finish;
$dbh->disconnect;
##call email here

#######################################
####DELETE#########################

sub deletemenu {
&connectdb;
$statement=qq(DELETE FROM tblmenu WHERE (indx = '$id'));
$sth = $dbh->prepare($statement);
$sth->execute;
$sth->finish;
print $query->header;
print $query->start_html;
print "<h3>The menu has been deleted.</h3>";
print "<a href='/cgi-bin/menu.cgi'>View The Menu List</a><p>";
print $query->end_html;
#endsub
}


##############CONNECT TO DB#######################

sub connectdb{
$DBD = "mysql";
$dbase = "misc";
$dbuser = "root";
$dbpassword = "";
$dbh = DBI->connect("dbi:$DBD:$dbase",$dbuser,$dbpassword) or die "couldn't do it";
$drh = DBI->install_driver("mysql");
#endsub
}
sub connectdb{
$DBD = "mysql";
$dbase = "svdb";
$dbuser = "stillmanvalley";
$dbpassword = "magicbox1";
$dbserver = "mysql.stillmanvalley.org";
$dbh = DBI->connect("dbi:$DBD:$dbase:$dbserver",$dbuser,$dbpassword) or die "couldn't do it";
$drh = DBI->install_driver("mysql");
#endsub
}


###load DATA FROM CSV FILE
##############################################
use DBI;

$file = "dcs.csv";
$terminator="\,";
$db="misc";
$tbl="tbldcs";
$dbtbl = "$db"."\."."$tbl";
$fldnames="name,dod,totdays,reasonfordc";

&connectdb;
##$sth = $dbh->prepare("LOAD DATA LOCAL INFILE '$file' INTO TABLE misc.tbladmits FIELDS TERMINATED BY ':' LINES TERMINATED BY '\n' (eid,apid,orgid,last,first,relation,orgname,orgtype,atype,add1,add2,city,state,zip,county,ptype,ac,phone,ext,pid,phid)") or die;
$sth = $dbh->prepare("LOAD DATA LOCAL INFILE '$file' INTO TABLE $dbtbl FIELDS TERMINATED BY '$terminator' LINES TERMINATED BY '\n' ($fldnames)") or die;

$sth->execute;
$sth->finish;
$dbh->disconnect;

#############################################

Integer to alphanumeric character

A function that converts an integer between 0 and 61 into an alphanumberic character. Ranges from 0-9, A-Z, a-z. Very handy for generating random strings and stuff like that.

function map_char($num) { 
   $int = $num; $int+=48;
   ($int > 57) ? $int += 7 : null;
   ($int > 90) ? $int += 6 : null;
   return chr($int);
}

Using multiple tags on Code Snippets

I spent a lot of time trying to select snippets with
contain multiple tags. (series60 and sql)
There is no '+' links I can click anymore.
After about 10 minutes of trial and error, I find out how.
This also answer another question on correct use of URL.
# for tag 'series60' AND 'sql'
http://www.bigbold.com/snippets/tags/series60/sql/

# this doesn't work
http://www.bigbold.com/snippets/tag/series60/sql/

# all of these work (single tag case)
http://bigbold.com/snippets/tag/series60/
http://bigbold.com/snippets/tags/series60/
http://www.bigbold.com/snippets/tag/series60/
http://www.bigbold.com/snippets/tags/series60/

My conclusion is that.
For a single tag, use '/tag/...'.
For multiple tags, use '/tags/...'.
The first is quicker to type, while the second is flexible in case you want to filter further.

collabrank firefox searchengine code

// collabrank firefox searchengine code

# Search plugin for Collaborative Rank [collabrank.org]
# by Soon Van <cog@randomecho.com> - www.randomecho.com
#
# This file is released into the public domain.
#
# Version: 1.0.0 (2005-10-24)
# Country: WW
# Language: en
#
# Note: Appears with several domains pointing to one spot

<search
	version="7.1"
	name="Collaborative Rank"
	description="Collaborative Rank - del.icio.us search engine"
	sourceTextEncoding="0"
	method="GET"
	action="http://collabrank.web.cse.unsw.edu.au/del.icio.us/"
	queryCharset="UTF-8"
	queryEncoding='UTF-8'
	searchForm="http://collabrank.web.cse.unsw.edu.au/del.icio.us/"
>

<input name="query" user>
<input name="cmd" value="search">
<input name="sourceid" value="mozilla-search">


<interpret
	browserResultType="result"
	charset="UTF-8"
	language="en"
#	resultListStart=""
#	resultListEnd=""
#	resultItemStart=""
#	resultItemEnd=""
>

</search>

<browser
	update="http://mycroft.mozdev.org/update.php/id0/collabrank.src"
	updateIcon="http://mycroft.mozdev.org/update.php/id0/collabrank.gif"
	updateCheckDays="7"
>

Yubnub "echoshortcut" to display text stored for alias

<?php

if (!$link = mysql_connect('', '', '')) {
echo 'Could not connect to mysql';
exit;
}

if (!mysql_select_db('yub', $link)) {
echo 'Could not select database';
exit;
}
$sendto1 = mysql_query("select email from yubmail where mail_alias = '$path'");
$sendto2 = mysql_result($sendto1, 0);

if (!$sendto2) {
echo "The alias does not exist! Use the command shortcut to create one.";
exit;
}
echo "$sendto2";
?>

Yubnub "checkshortcut" command to check alias

<?php

if (!$link = mysql_connect('', '', '')) {
   echo 'Could not connect to mysql';
   exit;
}

if (!mysql_select_db('yub', $link)) {
   echo 'Could not select database';
   exit;
}
$sendto1 = mysql_query("select email from yubmail where mail_alias = '$path'");
$sendto2 = mysql_result($sendto1, 0);

if (!$sendto2) {
   echo "The alias does not exist! You can try to create one or send the message to mailinator ailas.";
exit;
}

echo "The alias $path does exist!";
?>

Yubnub "dbsearch" command to search MySQL data

<META HTTP-EQUIV="Refresh" CONTENT="0;URL=
<?php
$compare1 = substr($path, 0, 7);
if ($compare1 == "http://"){
echo $path.'db_search.php?search_option=1&submit_search=Go&db='.$db.'&search_str='.$search;
}

if (!$link = mysql_connect('', '', '')) {
   echo 'Could not connect to mysql';
   exit;
}

if (!mysql_select_db('yub', $link)) {
   echo 'Could not select database';
   exit;
}
$sendto1 = mysql_query("select email from yubmail where mail_alias = '$path'");
$sendto2 = mysql_result($sendto1, 0);
echo $sendto2.'db_search.php?search_option=1&submit_search=Go&db='.$db.'&search_str='.$search;
?>
">

Yubnub "data" command to display MySQL data

<?php
// Yubnub.org command "data" access this show.php file on the server
      
//    $dbname = "";
//    $loginname = "";
//    $loginpass = "";
//    $dbhost = "";
    
    echo('<html><body bgcolor="#FFFFFF">');
    echo('<font face="arial" size="+4"><center>');
    echo(" $dbname");
    
    $id_link = @mysql_connect($dbhost, $login, $password);
    
    $tables = mysql_list_tables($dbname, $id_link);
    
    $num_tables = mysql_num_rows($tables);

    // store table names in an array
    $arr_tablenames[] = '';
    
    // store number of fields per table(index 0,1,2..) in an array
    $arr_num_fields[] = '';
    for ($i=0; $i < $num_tables; $i++) {
        $arr_tablenames[$i] = mysql_tablename($tables, $i);
        $arr_num_fields[$i] = mysql_num_fields(mysql_db_query($dbname, "select * from $arr_tablenames[$i]", $id_link));
    }
    
    // store field names in a multidimensional array:
    // [i] == table number, [ii] == field number for that table
    for ($i=0; $i < $num_tables; $i++) {
        for ($ii=0; $ii < $arr_num_fields[$i]; $ii++) {
            $result = mysql_db_query($dbname, "select * from $arr_tablenames[$i]", $id_link);
            $hash_field_names[$i][$ii] = mysql_field_name($result, $ii);
        }    
    }
    
    for ($i=0; $i < $num_tables; $i++) {
        echo("<center><h2> $arr_tablenames[$i] </h2></center>");
        echo('<table align="center" border="1"><tr>');
        $result = mysql_db_query($dbname, "select * from $arr_tablenames[$i]", $id_link);
        for ($ii=0; $ii < $arr_num_fields[$i]; $ii++) {
            echo("<th>");
            echo $hash_field_names[$i][$ii];
            echo("</th>");
        }
        echo("</tr><tr>");
        $number_of_rows = @mysql_num_rows($result);
        for ($iii = 0; $iii < $number_of_rows; $iii++) {
            $record = @mysql_fetch_row($result);
            for ($ii=0; $ii < $arr_num_fields[$i]; $ii++) {
                echo("<td>");
                // echo $record[$ii];
                $mytext = nl2br($record[$ii]);
                echo $mytext;
                echo("</td>");
            }
        echo("</tr>");
        }
        echo("</table>");
    }
    


    echo('</body></html>');

?>


« Newer Snippets
Older Snippets »
Showing 11-20 of 21 total