Location: PHPKode > scripts > Wordgraph > kbwordgraph/kbwordgraph/index.php
<?php include "config.php"; ?>
<html>
<head>
  <title>KB Wordgraph PHP Script!</title>

</head>
<body>
<h1>Demo Wordgraph</h1>
<p>The demo here shows that you choose any name from the list and based in the number of times an item has been chosen decides the word graph. Here, out of 50 words top 20 are being displayed.</p>


<table border='0' cellspacing='0' cellpadding='0' width='100%'>
<tr>
<td class='wordgraph'>
<?php

function wgdtl($wgid, $mode, $arr)
{
	$qrywgdtl="SELECT * FROM scrwordgraph WHERE wgid='$wgid'";
	$rslwgdtl=mysql_query($qrywgdtl);
	$nwgdtl = mysql_num_rows($rslwgdtl);
	$arrwgdtl =  mysql_fetch_row($rslwgdtl);
	
		if($mode=='0')
		{
		return($arrwgdtl[$arr]);
		}
		elseif($mode=='1')
		{
		echo "$arrwgdtl[$arr]";
		}

}


 	$qry_wg="SELECT * FROM scrwordgraph
	WHERE wgact='1'
	ORDER BY wgfreq desc LIMIT 20"; 
	$rsl_wg=mysql_query($qry_wg); 	
	$n_wg = mysql_num_rows($rsl_wg); 
	//$arr_wg =  mysql_fetch_row($rsl_wg);
	
	if($n_wg=='0')
	{
	echo "Nothing to Display<br>";
	}
	else
	{
	$words_arr=array();	

	static $wg_max_count;
	
	for ($i=0; $i<$n_wg; $i++)
	{
		$arr_wg =  mysql_fetch_row($rsl_wg);	
		
		$itmid=$arr_wg[0];
		$word_count=$arr_wg[3];
		$words_arr[$itmid]=$word_count;	
		
		//echo "$itmid $word_count<br>";
		if($word_count>	$wg_max_count)
		{
		$wg_max_count=$word_count;
		}	
	}
	
$wg_min_size = 8;
$wg_max_size_rel = 34;	
$wg_max_size = $wg_min_size+$wg_max_size_rel;	

$wg_size=$wg_max_size_rel/($wg_max_count+1);

$words_keys = array_keys($words_arr);
//sort($words);

$itmnam_arr=array();

foreach ( $words_keys as $words_key )
{
$itmnam=wgdtl($words_key,0,2);
$itmnam_arr[$itmnam]=$words_key;
}

$itmnam_keys = array_keys($itmnam_arr);
sort($itmnam_keys);

foreach ( $itmnam_keys as $itmnam_key )
{
$itm_id=$itmnam_arr[$itmnam_key];
$itm_count=$words_arr[$itm_id];
$font_size=round($wg_min_size+($itm_count*$wg_size));
//$itmnam=wgdtl($itm_id,0,3);
echo "<a href='#' style='font-size:".$font_size."px;'>$itmnam_key</a> ";
}
	}

?>
</td>
</tr>
</table>



<?php

if(isset($_REQUEST['wgsub']))
{

$err="0";
$crr="0";
$err1="";
$err1_1="";
$err2="";
$err3="";
$err4="";
$err5="";
$crr1="";


	$wgid=$_POST['wgid'];
	if($wgid=='')
	{
		$err="1";
		$err2="Please select a Name from the List<br>";
	}
	
}


if(isset($_REQUEST['wgsub']) && $err=="0")
{
	$qrywgchk="SELECT * FROM scrwordgraph WHERE wgid='$wgid'";
	$rslwgchk=mysql_query($qrywgchk);
	$nwgchk = mysql_num_rows($rslwgchk);
	$arrwgchk =  mysql_fetch_row($rslwgchk);
	
	if($nwgchk=='0')
	{
		$err="1";
		$err3="No Wordgraph name found.<br>";	
	}
	else
	{
	$wg_nam=$arrwgchk[2];
	$wg_freq=$arrwgchk[3];
	$wg_ctgid=$arrwgchk[4];
	
	$new_wg_freq=$wg_freq+1;;
	
	$wg_greq_upd=mysql_query("UPDATE scrwordgraph SET wgfreq=$new_wg_freq WHERE wgid='$wgid'");
	
	if($wg_greq_upd)
	{
	echo "Your selected item $wg_nam was chosen.<br>";
	}
	else
	{
	echo "Your selected item $wg_nam was not chosen.<br>";
	}
	
	}
	
	

}




if( (isset($_REQUEST['wgsub']) && $err!="0") || (!isset($_REQUEST['wgsub'])) )
{
	if(isset($_REQUEST['wgsub']) && $err!="0")
	{
	echo "<font color='red'>
	$err1_1 $err1_2 $err2 $err3 $err4 $err5
	</font><br>";
	}

?>

<table  border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%">
		<tr>
        <td width="60%" valign="top">
        
		<form method="POST" action="" onsubmit="return wgverify(this.wgid)">
         <table width="70%" border="1">
            	<tr>
			<td width="40%">Select a Name</td>
			<td width="60%">
    <select size="1" name="wgid"> 
    <option value=''>Select a Name</option> 
<?php

$qrywglist="SELECT * FROM scrwordgraph WHERE wgact='1' ORDER BY scrwordgraph.wgnam";
$rslwglist=mysql_query($qrywglist);
$nwglist = mysql_num_rows($rslwglist);
for ($i=0; $i<$nwglist ; $i++)
{
$arrwglist =  mysql_fetch_row($rslwglist);
	
	if($wglist==$arrwglist[0])
	{
	echo "<option value='$arrwglist[0]' selected>$arrwglist[2]</option>";
	}
	else
	{
	echo "<option value='$arrwglist[0]'>$arrwglist[2]</option>";
	}
}
?>
	</select>
	</td>
    </tr>          	


<?php		
		echo "	          
            <tr>
			<td colspan='2'>
			<input type='submit' value='Select' name='wgsub'>
			<input type='reset' value='Reset' name='reset'>
			</td>
			</tr>
			";
?>            
      	  	
        </table>
        </form>
<?php
}
	elseif(isset($_REQUEST['wgsub']) && $crr!="0")
	{
	echo "<font color='green'>
	$crr1
	</font><br>";
	}

?>        
     </td>
    </tr>
   </table>
   <script>

function wgverify(wgid)
//(suf, nam,element1, msg,count)
{
	var passed=false
	
 	if (wgid.value=='')
 			{
  			alert("Please select a Wordgraph Name")
  			wgid.focus()
 			}
	else
  		passed=true
return passed
}
</script>
</body>
</html>
Return current item: Wordgraph