Page 1 of 3

php: Simple War script for your website

Posted: Wed Dec 10, 2003 1:56 pm
by Den
Simple War script for your website, easy to add / remove things



quick coding, some bad things :D



This script is for the ppl who are allowed to add wars, for the normal viewers just copy and paste the part where it says: " // The war list " and add it ur page.



[php]<?php

$db = mysql_connect("******", "******", "******"); // DB ip, user en pw

mysql_select_db("******",$db); // DB naam

$table = "******";



function auto_link($text) {

RETURN eregi_replace("(http://([a-zA-z0-9_-]+[\.]{1})*[\.]{0,1}[a-z]{2,3})","<a href=\"\\1\" target=\"_BLANK\">\\1</a>",$text);

}



if ($submit) {

// Edit part

if ($id) {

$sql = "UPDATE $table SET date='$date',tag='$tag',opponent='$opponent',type='$type',score='$score',wld='$wld',report='$report' WHERE id=$id";

}

else {

$sql = "INSERT INTO $table (date,tag,opponent,type,score,wld,report) VALUES ('$date','$tag','$opponent','$type','$score','$wld','$report')";

}

$result = mysql_query($sql);

echo "War $sql";

echo "<br><a href='$PHP_SELF'>Back</a>";

}

elseif ($add) {

// Edit a war

$date = $myrow["date"];

$tag = $myrow["tag"];

$opponent = $myrow["opponent"];

$type = $myrow["type"];

$score = $myrow["score"];

$wld = $myrow["wld"];

$report = $myrow["report"];

echo "<form method='post' action='$PHP_SELF'><br>

Date:<input type='Text' name='date'><br>

Tag:<input type='Text' name='tag'><br>

Opponent:<input type='Text' name='opponent'><br>

Type:<select name='type' size='1' id='type'><option>Official</option><option>Unofficial</option><option>EAQL</option><option>NAQL</option></select><br>

Result:<input type='Text' name='score'><br>

Outcome:<select name='wld' size='1' id='wld'><option selected>won</option><option>lost</option><option>draw</option></select><br>

Report:<br>

<textarea name='report' cols='100' rows='10'></textarea><br>

<input type='Submit' name='submit' value='Add'>

</form>";

}

elseif ($delete) {

// Delete a war

$sql = "DELETE FROM $table WHERE id=$id";

$result = mysql_query($sql);

echo "$sql <br><br>War Deleted";

echo "<br><a href='$PHP_SELF'>Back</a>";

}

elseif ($edit) {

// Edit a war

$sql = "SELECT * FROM $table WHERE id=$id";

$result = mysql_query($sql);

$myrow = mysql_fetch_array($result);



$date = $myrow["date"];

$tag = $myrow["tag"];

$opponent = $myrow["opponent"];

$type = $myrow["type"];

$score = $myrow["score"];

$wld = $myrow["wld"];

$report = $myrow["report"];



echo "<form method='post' action='$PHP_SELF'>

<input type=hidden name='id' value='$id'>

Date:<input type='Text' name='date' value='$date'><br>

Tag:<input type='Text' name='tag' value='$tag'><br>

Opponent:<input type='Text' name='opponent' value='$opponent'><br>

Type:<select name='type' size='1' id='type'><option>Official</option><option>Unofficial</option><option>EAQL</option><option>NAQL</option></select><br>

Result:<input type='Text' name='score' value='$score'><br>

Outcome:<select name='wld' size='1' id='wld'><option selected>won</option><option>lost</option><option>draw</option></select><br>

Report:<br><textarea name='report' cols='100' rows='10'>$report</textarea><br>

<input type='Submit' name='submit' value='Add'>

</form>";

}

else {

// The detailed warlist

if ($id) {

$result = mysql_query("SELECT * FROM $table WHERE id=$id");

$myrow = mysql_fetch_array($result);



$date = $myrow["date"];

$tag = $myrow["tag"];

$opponent = $myrow["opponent"];

$type = $myrow["type"];

$score = $myrow["score"];

$wld = $myrow["wld"];

$report = $myrow["report"];



echo "Date: $date<br>

Opponent: <b>$tag</b> $opponent<br>

Type: $type<br>

Result: $score<br>

Outcome: $wld<br>

Report<br>";

echo auto_link($report);

}

else{

// The war list

$select1 ="SELECT * FROM $table ORDER BY id DESC";

$query1 = mysql_query($select1);



echo "<a href='?add=yes'>Add</a><br><hr><tr><td valign='top'><table width='660'

border='0' cellspacing='1' cellpadding='1'><tr><td class='title' width='23'>#</td><td>

<b>Date</b></td><td class='title' width='300'><b>Opponent</b></td><td class='title' width='52'><b>Type</b></td>

<td class='title' width='48'><b>Result</b></td><td class='title' width='38'><b>Report</b></td><td class='title' width='38'></td><td></td></tr>";

if (mysql_num_rows($query1) == 0) {

echo "<td>No wars in DB</td>";

}

else {

while ($list = mysql_fetch_object($query1)) {

echo "<tr><td>$list->id</td>

<td>$list->date</td>

<td>$list->tag $list->opponent</td>

<td>$list->type</td>

<td>$list->score</td>

<td>";

if ($list->report == " ") {

echo " "; }

else {

echo "<a href='?id=$list->id'><img src='http://www.clanbase.com/report.gif' border='0'></a>";

}

echo "</td>";

echo "<td><a href='?id=$list->id&edit=yes'>edit</a></td>";

echo "<td><a href='?id=$list->id&delete=yes'>delete</a></td></tr>";

}

}

}

}

?>

[/php]

Posted: Wed Dec 10, 2003 2:06 pm
by ettan
Thanks den`!

Posted: Wed Dec 10, 2003 3:35 pm
by WOlz
hmm, why u dont use GET, POST...? :(

Posted: Sat Dec 13, 2003 8:10 am
by Rallu
uitto, becouse they are n00bs with PHP and don't understand security things :)

Posted: Sat Dec 13, 2003 9:33 am
by Clown
Would you like to help instead of making fun out of people? :)

Posted: Sat Dec 13, 2003 12:09 pm
by Den
uhu im a noob..

Posted: Sat Dec 13, 2003 7:28 pm
by Clement
oh yes you are.. :)

Posted: Mon Dec 15, 2003 3:49 am
by WOlz
but nice script, gj den :)

Posted: Mon Dec 15, 2003 8:49 am
by blissard
so, how do i go about getting this script to work? :?

Posted: Mon Dec 15, 2003 9:12 am
by Den
well u need to create a table in ur mysql :)



change the ****** and there u go

Posted: Mon Dec 22, 2003 8:54 am
by keffo
Can someone make a pagin-system for the script? (1,2,3,4,5)

my old-one wont work with it :(

Posted: Mon Dec 22, 2003 1:12 pm
by Den
page-scripts arent the best for wars :P just limit the war records to 100 or so, then make a link like [view all wars] somewhere on ur screen and set no limit for that.

Posted: Mon Dec 22, 2003 5:02 pm
by keffo
ok, your right. you've got my private message? or else, go check your inbox bish :>

Posted: Mon Dec 22, 2003 5:07 pm
by keffo
oh! i have one more question, how do i make a shortness of the script?

like on cows page they have 5 latest cws and a link to the report.



how do i manage to make that? and view the full cw page without

the script crashes :(

Posted: Mon Dec 22, 2003 5:53 pm
by Den
$select1 ="SELECT * FROM $table ORDER BY id DESC limit 0, 5";