php: Simple War script for your website
Moderator: Moderators
php: Simple War script for your website
Simple War script for your website, easy to add / remove things
quick coding, some bad things
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]
quick coding, some bad things
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]
Last edited by Den on Thu Mar 18, 2004 3:00 am, edited 10 times in total.
There's a chopper coming in 3 days and there's a katana on top of the cafe and that's all you need to know