Wat vinden jullie van deze script(s)?
Script 1
Deze script is er om een nieuwe board aan te maken in mijn cms voor de forum. De while controleert of de positie al bezet is, om zo orde te houden in de mysql. Zonder de while kan er namelijk dadelijk niet van boardpositie verschoven worden.
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
//setup load image
echo "
<br />
<br />
<br />
<p align='center'>
<img src='".$themeurl."/images/loading2.gif' style='align:center;'
</p>
";
//setup permanent variables until end of file
$name_new_board = $_POST['name'];
$board_text = $_POST['boardtext'];
$boardposition = 1;
$board_on_cat = $_GET['catid'];
$board_position_free = false;
//check if new position is already under use...
while ($board_position_free==false) //do this system until $board_position_free IS NOT falsen
{
$checkposition = mysql_query("SELECT * FROM ".$table_pref."boards WHERE cat='".$board_on_cat."' AND position='".$boardposition."'"); //get results
$checkposition2 = mysql_num_rows($checkposition); //check if results are already in use
if($checkposition2>=1) //are the results in use?
{
$boardposition++;
}
else //when not...
{
$board_position_free = true; //tell the while it is finished
//insert the board into the mysql
mysql_query("INSERT INTO ".$table_pref."boards (naam, boardtext, cat, position)
VALUES ('".$name_new_board."', '".$board_text."', '".$board_on_cat."', '".$boardposition."')");
//send user back to board& cats index
echo '
<script language="JavaScript">
<!--
window.location="./admin.php?action=forumadmin&i=boardcats";
//-->
</script>
';
}
}
?>
//setup load image
echo "
<br />
<br />
<br />
<p align='center'>
<img src='".$themeurl."/images/loading2.gif' style='align:center;'
</p>
";
//setup permanent variables until end of file
$name_new_board = $_POST['name'];
$board_text = $_POST['boardtext'];
$boardposition = 1;
$board_on_cat = $_GET['catid'];
$board_position_free = false;
//check if new position is already under use...
while ($board_position_free==false) //do this system until $board_position_free IS NOT falsen
{
$checkposition = mysql_query("SELECT * FROM ".$table_pref."boards WHERE cat='".$board_on_cat."' AND position='".$boardposition."'"); //get results
$checkposition2 = mysql_num_rows($checkposition); //check if results are already in use
if($checkposition2>=1) //are the results in use?
{
$boardposition++;
}
else //when not...
{
$board_position_free = true; //tell the while it is finished
//insert the board into the mysql
mysql_query("INSERT INTO ".$table_pref."boards (naam, boardtext, cat, position)
VALUES ('".$name_new_board."', '".$board_text."', '".$board_on_cat."', '".$boardposition."')");
//send user back to board& cats index
echo '
<script language="JavaScript">
<!--
window.location="./admin.php?action=forumadmin&i=boardcats";
//-->
</script>
';
}
}
?>
Wat vind je van het script?
mag ik vragen hoe jij dingen in of uit de mysql haalt of zet?
Zie tweede link.