|
Membro - General
Registrado em: Jun 2009
Posts: 232
Agradecido 83 Vezes em 31 Posts
Achei Ruim:
Acharam ruim Vezes em Posts
|
Seto aqui eu deixei a pasta Script dentro da WWW, editei os Botoes e ficaram assim:
<li class="subNavContainer">
<a class="subNavLink" id="news_from_abroad" href="Script/pvpkills.php">Top PVP</a>
</li>
<li class="subNavContainer">
<a class="subNavLink" id="general_news" href="Script/pkkills">Top PK</a>
</li>
<li class="subNavContainer">
<a class="subNavLink" id="developer_blogs" href="Script/online.php">Top Online</a>
</li>
<li class="subNavContainer">
<a href="Top Voters.html" class="subNavLink" id="developer_blogs">Top Voters</a>
</li>
<li class="subNavContainer">
<a class="subNavLink" id="developer_blogs" href="Script/clan.php">Top Clans</a>
</li>
Mesmo assim ainda ta erro, ele nao consegue carregar a pagina...
Depois de um teste com a opçao de clan
apresentou esse seguinte erro:
meu arquivo Clan.php esta assim:
Meu Arquivo de conexao com banco de dados
Spoiler
[Share]Collection of PHP shares.
« on: August 10, 2009, 05:38:55 AM »
Reply with quoteQuote
1st.5 Star rating system.
How to start?
Well first we have to make a DB and we put this inside:
Code:
CREATE TABLE `star_vote` (
`id` int(15) NOT NULL,
`rating` int(10) NOT NULL default '0',
`Voters` int(5) NOT NULL default '0',
UNIQUE KEY(`id`)
);
CREATE TABLE `star_vote_ip` (
`id` int(15) NOT NULL,
`ip` varchar(30) NOT NULL
);
After we created the table and added the structure inside it the next step is the next file.
You have to create a .php file name it connect.php,put inside this code:
Code:
<?php
define(DB_HOST, "l2batery.servegame.com");
define(DB_USER, "root");
define(DB_PASS, "senha do meu mysql");
define(DB_NAME, "l2jdb");
$conn = @mysql_connect(DB_HOST, DB_USER, DB_PASS) or die(mysql_error());
@mysql_select_db(DB_NAME, $conn) or die(mysql_error());
define(STARS, 5); // From here configure how many stars you want to have.
?>
After you create it config it so it can connect to DB.
Next step is create a file config.php in the file we put:
Code:
<?php
require "connect.php";
$id = $_GET['id']; // we take ID;
$display_rating = false;
if (is_numeric($id) && $id > 0) // check if ID is numeric and if its bigger than 0
{
$display_rating = true;
$vote_allow = true;
$votes = array();
$row = mysql_fetch_object(mysql_query("SELECT `rating`, `Voters`, COUNT(*) as 'kolko' FROM `star_vote` WHERE `id` = '$id' LIMIT 1"));
if ($row -> How many) // Check if you've voted already with 1
{
$rating = @round($row -> rating / $row -> Voters); // ownring the rating in $rating
$votes = array_pad($votes, $rating, "starvoted.png"); // fill the massive $votes with starvoted.png(filled stars)
$ip_vote = @mysql_result(mysql_query("SELECT COUNT(*) FROM `star_vote_ip` WHERE `id` = '$id' AND `ip` = '".$_SERVER['REMOTE_ADDR']."'"), 0);
if ($ip_vote) $vote_allow = false; // check if you already voted with this IP
}
$votes = array_pad($votes, STARS, "starunvoted.png"); // fill the massive with $votes with starunvoted.png(non-filled stars)
}
?>
So we're done with this file too.Now we move to the file: vote_star.js (There is nothing to change in it.)Here is it containing:
Code:
var xmlHttp
function vote_star(id, str)
{
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}
var url="vote_star.php"
url=url "?id=" id
url=url "&str=" str "&sid=" Math.random()
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}
function stateChanged()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
document.getElementById("star_votes").innerHTML=xmlHttp.responseText;
}
}
function GetXmlHttpObject()
{
var objXMLHttp=null
if (window.XMLHttpRequest)
{
objXMLHttp=new XMLHttpRequest()
}
else if (window.ActiveXObject)
{
objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
}
return objXMLHttp
}
Next file we have to create is:
vote_star.php fill it with this:
Code:
<?php
require "connect.php";
$id = $_GET['id'];
$str = $_GET['str'];
$ip = $_SERVER['REMOTE_ADDR'];
if (is_numeric($id) && $id > 0 && in_array($str, range(1,STARS))) //
{ // if OK continue
$votes = array();
$row = mysql_fetch_object(mysql_query("SELECT `rating`, `Voters`, COUNT(*) as 'kolko' FROM `star_vote` WHERE `id` = '$id' LIMIT 1"));
if ($row -> kolko) // check if its already voted with this ID
{ // ??? ? ?????????
$ip_vote = @mysql_result(mysql_query("SELECT COUNT(*) FROM `star_vote_ip` WHERE `id` = '$id' AND `ip` = '$ip'"), 0);
if (!$ip_vote) // check if its already voted with this IP if no continue
{
$new_rating = $row -> rating $str; // add the new vote rating to the old
$new_Voters = $row -> Voters 1; // add 1 to voters
$rating = @round($new_rating / $new_Voters); // calculate middle rating
$votes = array_pad($votes, $rating, "starvoted.png"); // fill $votes with starvoted.png(filled stars)
mysql_query("UPDATE `star_vote` SET `rating` = '$new_rating',`Voters` = '$new_Voters' WHERE `id` = '$id'"); // update the info for the ID
mysql_query("INSERT INTO `star_vote_ip` (`id`,`ip`) VALUES ('$id','$ip')"); // log the IP of the voter
}
}
else // ??? ??? ??? ????? ?? ? ??? ???????? ?? ???? ID
{
$rating = $str;
$votes = array_pad($votes, $rating, "starvoted.png"); // fill the massive $votes with starvoted.png(filled stars)
mysql_query("INSERT INTO `star_vote` (`id`, `rating`, `Voters`) VALUES ('$id', '$str', '1')"); // creating new ID with the vote
mysql_query("INSERT INTO `star_vote_ip` (`id`,`ip`) VALUES ('$id','$ip')"); // log the IP of the voter
}
$votes = array_pad($votes, STARS, "starunvoted.png"); // fill the massive $votes with starunvoted.png(empty stars)
if ($rating)
{
for ($i=0;$i<STARS;$i )
echo "<img src="".$votes[$i]."" border="0">";
}
}
?>
The final step is create a file ex. index.php put this inside it:
Code:
<?php
require "config.php";
?>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title>Demo Vote system by: Flower</title>
<?php
if ($display_rating)
{
?>
<script src="vote_star.js" type="text/javascript"></script>
<script type="text/javascript">
function star_vote(id)
{
for (i=1;i<=<?=STARS?>;i )
{
if (i <= id)
{
document[i].src="starvoted.png";
}
else
{
document[i].src="starunvoted.png";
}
}
}
function normal()
{
<?php
for ($i=0,$i2=1;$i<STARS;$i ,$i2 )
{
echo "document[$i2].src="".$votes[$i]."";n";
}
?>
}
</script>
<?php
}
?>
</head>
<body>
<?php
if ($display_rating)
{
?>
<b>Voters:</b>
<div id="star_votes">
<?php
for ($i=0,$i2=1;$i<STARS;$i ,$i2 )
{
?>
<?php if ($vote_allow) { ?><a href="javascript:void(null)" onMouseOver="star_vote('<?=$i2?>')" onMouseOut="normal()" onClick="vote_star('<?=$id?>', '<?=$i2?>')"><?php } ?><img id="<?=$i2?>" src="<?=$votes[$i]?>" border="0"><?php if ($vote_allow) { ?></a><?php }
}
?>
</div>
<?php
}
else echo "<b>Invalid ID!</b>";
?>
</body>
</html>
How to use it?Open an index.php and put
Code:
?id=[ ID]
Each ID is individual and the rates are invidual for each ID.
----------------------
2.Creating DB with PHP.
The PHP Function "mydql_create_db() tries to create a DB with the name,which u add as argument.The guide down here shows all exsisting DB and after that creates a form,in which you can add the name of the new BD.When the form get accepted,the script tries to create the new BD with the given name.
Code:
<?php
$conn = @mysql_connect("localhost", "test", "test")
or die( "Error, the connection to MySQL cannot be accomplished." );
$rezl = @mysql_create__db ( $_REQUEST['db'] );
$rez2 = @mysql_list_dbs($conn);
$spisyk = "";
for( $row=0; $row < mysql_num_rows( $rez2 ); $row )
{ $spisyk .= raysql_tablename( $rez2, $row ) .
" - "; }
?>
and
Code:
<html>
<head> <title>Create DB with PHP by: Flower</title> </head>
<body>
<form action="<?php echo( $_SERVER['PHP_SELF'] ); ?> " method="post">
Data base: <?php echo( $spisyk ); ?> <hr>
Name:<input type = "text" name = "db"> <br>
<input type = "submit" value = "Create DB.">
</form>
</body>
</html>
P.S2.:If you have any problem use prefix: [Problem] Include full explaination of the problem.If you find a bug write here.Haven't tested it just created it i think there are no bugs inside it!Enjoy!
Keep the topic clean!All useless posts will be deleted without warns!
|