just to give you entire picture I need to do this:
I need to place
in either
of forum or in starting post of a forum post by a user/admin etc
imagine you have a list of topics and next to the item starter there is a rating of article
I'll be placing the this in manifest.xml
<hook id="hd_head">
<![CDATA[
$forum_head['ratings'] = '<script type="text/javascript" src="rate.js"></script>';
]]>
</hook>
to get the javascript.
for creating table I will use this
$schema = array(
'FIELDS' => array(
'id' => array(
'datatype' => 'SERIAL',
'allow_null' => false
),
'cat_name' => array(
'datatype' => 'VARCHAR(80)',
'allow_null' => false,
'default' => '\'New Category\''
),
'disp_position' => array(
'datatype' => 'INT(10)',
'allow_null' => false,
'default' => '0'
)
),
'PRIMARY KEY' => array('id')
);
$forum_db->create_table('categories', $schema);
from you
based on the following mysql statment
CREATE TABLE `tableName` (
`ip` varchar(15) NOT NULL,
`rating` varchar(1) NOT NULL,
`page` varchar(99) NOT NULL,
PRIMARY KEY (`ip`,`page`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
in original php I have this
<?
include("include/rate.php");
?>
above header
and this :
<?
writeRate(test);
?>
in body of rate.php
how should I implement this in the manifest.xml
the file include/rate.php looks like this:
$action = $_GET['a'];
if($action==1)
{
rate();
}
if($action==2)
{
reRate();
}
function rate()
{
$star_value = $_GET['r'];
$page = $_GET['p'];
$ip = $_SERVER['REMOTE_ADDR'];
//Add to database
mysql_query("INSERT INTO `".DB_TABLE."` VALUES ('$ip','$star_value','$page')");
$ref = $_SERVER['HTTP_REFERER'];
header("Location: " .$ref);
}
function reRate()
{
$star_value = $_GET['r'];
$page = $_GET['p'];
$ip = $_SERVER['REMOTE_ADDR'];
//Add to database
mysql_query("UPDATE `".DB_TABLE."` SET `rating` = '$star_value' WHERE `ip` = '$ip' AND `page` = '$page'");
$ref = $_SERVER['HTTP_REFERER'];
header("Location: " .$ref);
}
function writeRate($page)
{
$ip = $_SERVER['REMOTE_ADDR'];
$result = mysql_query("SELECT `ip` FROM `".DB_TABLE."` WHERE `ip` = '".$ip."' AND `page` = '$page'");
$num_rows = mysql_num_rows($result);
if($num_rows==1)
{
echo '<p>Your Rating: ';
$result = mysql_query("SELECT `rating` FROM `".DB_TABLE."` WHERE `ip` = '".$ip."' AND `page` = '$page'");
$rating = mysql_result($result, 0);
if($rating == 1)
{
echo '<a href="include/rate.php?p='.$page.'&r=1&a=2"><img src="stars/starCurrent.gif" border="0" name="'.$page.'one" onmouseover="Swap1(\''.$page.'\')" onmouseout="SwapBackOne(\''.$page.'\')" /></a><a href="include/rate.php?p='.$page.'&r=2&a=2"><img src="stars/empty.gif" border="0" name="'.$page.'two" onmouseover="Swap2(\''.$page.'\')" onmouseout="SwapBackOne(\''.$page.'\')" /></a><a href="include/rate.php?p='.$page.'&r=3&a=2"><img src="stars/empty.gif" border="0" name="'.$page.'three" onmouseover="Swap3(\''.$page.'\')" onmouseout="SwapBackOne(\''.$page.'\')" /></a><a href="include/rate.php?p='.$page.'&r=4&a=2"><img src="stars/empty.gif" border="0" name="'.$page.'four" onmouseover="Swap4(\''.$page.'\')" onmouseout="SwapBackOne(\''.$page.'\')" /></a><a href="include/rate.php?p='.$page.'&r=5&a=2"><img src="stars/empty.gif" border="0" name="'.$page.'five" onmouseover="Swap5(\''.$page.'\')" onmouseout="SwapBackOne(\''.$page.'\')" /></a>';
}
if($rating == 2)
and so on for each rating of 5
basically i want to make this into an extension....
the original script has
rate.php
rate.js
/include/rate.php
(and includes/constants.php where db info was placed)
/stars/ (gifs)