patternphpMinor
Monopoly: Board creation
Viewed 0 times
boardmonopolycreation
Problem
After initially struggling with the board size, I have now decided the dimension. Please review my code. In the code I am generating HTML code using PHP and MySql. I have not added the database, please let me know how to add it in my question.
The key functionality is
Please let me know if further clarification is required. I have also omitted the generated HTML instead here is a picture of what the output looks like. Let me know if generated HTML is needed?
I am looking for ways to improve the code and would like to know whether a more quicker loading time can be achieved. Any general suggestions are also welcome.
Index.php
functions.php
CSS
```
span{
display: block;
font: bold 10px "Arial", "Helvetica", sans-serif;
color: #000;
text-align: center;
}
/***
Board Structure
****/
.board {
background: #EBEBE0;
width: 845px;
}
.row{
background: #fff;
float: left;
width: 100%;
}
.left-column{
width: 75px;
float: left;
}
.center-column{
float: left;
width: 20px;
}
.right-column{
float: right;
width: 75px;
}
/****
Board Positions
****/
.position {
border: 1px solid #CFCFCF;
float: left;
The key functionality is
drawBoard() it has 3 parameters, 1is to determine whether I will increment or decrease,
2determines where to start from
3determines where to end at
Please let me know if further clarification is required. I have also omitted the generated HTML instead here is a picture of what the output looks like. Let me know if generated HTML is needed?
I am looking for ways to improve the code and would like to know whether a more quicker loading time can be achieved. Any general suggestions are also welcome.
Index.php
functions.php
">
">
">
">
">
">
">
">
">
CSS
```
span{
display: block;
font: bold 10px "Arial", "Helvetica", sans-serif;
color: #000;
text-align: center;
}
/***
Board Structure
****/
.board {
background: #EBEBE0;
width: 845px;
}
.row{
background: #fff;
float: left;
width: 100%;
}
.left-column{
width: 75px;
float: left;
}
.center-column{
float: left;
width: 20px;
}
.right-column{
float: right;
width: 75px;
}
/****
Board Positions
****/
.position {
border: 1px solid #CFCFCF;
float: left;
Solution
When mixing if statements and HTML I and others often use the alternative syntax, which makes it easier to spot what's being closed even though the brackets might have a great deal of distance between them:
I like the idea of using semantic variables instead of
To fix the problem that you mention in your edit you could do for example:
If it doesn't matter in which order you loop through the elements. In this case I guess it does, so you would have to get the sign of the difference ($stop-$start):
Finally I think that the default values of
if( condition ): ?>
HTML
<?php endif;I like the idea of using semantic variables instead of
$row[index] but I think there are more elegant ways of making the assignments. For example by using mysqli_fetch_assoc you might get a semantic associative array that you could use and skip the extra assignments, or you could uselist($posid, $title, ...,...) = $row;To fix the problem that you mention in your edit you could do for example:
for ($i = min($start,$stop); $i != max($start, $stop); $i += 1){If it doesn't matter in which order you loop through the elements. In this case I guess it does, so you would have to get the sign of the difference ($stop-$start):
$diff = ($stop > $start) ? 1 : -1;Finally I think that the default values of
drawBoard should be numeric.Code Snippets
if( condition ): ?>
HTML
<?php endif;list($posid, $title, ...,...) = $row;for ($i = min($start,$stop); $i != max($start, $stop); $i += 1){$diff = ($stop > $start) ? 1 : -1;Context
StackExchange Code Review Q#40654, answer score: 4
Revisions (0)
No revisions yet.