php: Simple War script for your website

Forum for anything hard- or software related.

Moderator: Moderators

Den
something dur dur
Posts: 2616
Joined: Fri Jul 25, 2003 8:56 am
Location: nl
Contact:

php: Simple War script for your website

Post 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]
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
Image
ettan
is connecting
Posts: 2
Joined: Mon Jul 28, 2003 11:24 am
Location: se

Post by ettan »

Thanks den`!
WOlz
is connecting
Posts: 17
Joined: Mon Jul 28, 2003 10:56 pm
Location: fi
Contact:

Post by WOlz »

hmm, why u dont use GET, POST...? :(
I do not know with what weapons World War 3 will be fought, but World War 4 will be fought with sticks and stones.
Rallu
hit the ground hard, real hard
Posts: 93
Joined: Thu Jul 31, 2003 11:36 pm
Location: fi
Contact:

Post by Rallu »

uitto, becouse they are n00bs with PHP and don't understand security things :)
Clown
unpossible??!?!!
Posts: 1750
Joined: Sun Jul 27, 2003 7:38 am
Location: en

Post by Clown »

Would you like to help instead of making fun out of people? :)
I don't give a shit.
Den
something dur dur
Posts: 2616
Joined: Fri Jul 25, 2003 8:56 am
Location: nl
Contact:

Post by Den »

uhu im a noob..
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
Image
Clement
Master of the Universe
Posts: 743
Joined: Fri Jul 25, 2003 10:27 pm
Location: dk
Contact:

Post by Clement »

oh yes you are.. :)
WOlz
is connecting
Posts: 17
Joined: Mon Jul 28, 2003 10:56 pm
Location: fi
Contact:

Post by WOlz »

but nice script, gj den :)
I do not know with what weapons World War 3 will be fought, but World War 4 will be fought with sticks and stones.
blissard
tried to put the pin back in
Posts: 291
Joined: Tue Oct 07, 2003 5:47 pm
Location: no

Post by blissard »

so, how do i go about getting this script to work? :?
hehehHEheheHheh GOGOGO Head shot !
Den
something dur dur
Posts: 2616
Joined: Fri Jul 25, 2003 8:56 am
Location: nl
Contact:

Post by Den »

well u need to create a table in ur mysql :)



change the ****** and there u go
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
Image
keffo
hit the ground hard, real hard
Posts: 80
Joined: Sun Dec 21, 2003 9:10 pm
Location: se

Post by keffo »

Can someone make a pagin-system for the script? (1,2,3,4,5)

my old-one wont work with it :(
Eg har blitt norrbagge :<
Den
something dur dur
Posts: 2616
Joined: Fri Jul 25, 2003 8:56 am
Location: nl
Contact:

Post 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.
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
Image
keffo
hit the ground hard, real hard
Posts: 80
Joined: Sun Dec 21, 2003 9:10 pm
Location: se

Post by keffo »

ok, your right. you've got my private message? or else, go check your inbox bish :>
Eg har blitt norrbagge :<
keffo
hit the ground hard, real hard
Posts: 80
Joined: Sun Dec 21, 2003 9:10 pm
Location: se

Post 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 :(
Eg har blitt norrbagge :<
Den
something dur dur
Posts: 2616
Joined: Fri Jul 25, 2003 8:56 am
Location: nl
Contact:

Post by Den »

$select1 ="SELECT * FROM $table ORDER BY id DESC limit 0, 5";
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
Image
Post Reply