Let me start by saying I'm extremely new to HTML5, CSS, JS, MySQL, and PHP. I've been working with PHP and MySQL for all of a week now with no proper instruction, so I'm sorry if my code offends you.
First Concern:Which is proper usage of echo in this case? *see code below* I googled and basically the answer was to try to separate the markup and php as much as possible, but I couldn't get it working properly within HTML tags, and I wasn't sure if it's still good practice when you're using this many PHP references.
Near complete separation of markup and PHP. Mostly readable, but constant reuse of <?php ?> seems a bit cluttered.
Code
...
$x = 0;
while($row = mysqli_fetch_array($result))
{
$x++;
?>
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<?php
echo '<a data-toggle="collapse" data-parent="#accordion" href="#collapse' . $x . '">';
?>
<div class="row">
<font face="verdana">
<div class="col-xs-6">
<?php
echo $row['Price'] . '. ' . $row['Name'];
?>
</div>
<div class="col-xs-4">
<?php
echo $row['Type'];
?>
</div>
<div class="col-xs-2">
<?php
echo '*rating*';
?>
</div>
</font>
</div>
<?php
echo '</a>';
?>
</h4>
</div>
<?php
echo '<div id="collapse' . $x . '" class="panel-collapse collapse">';
?>
<div class="panel-body">
<div class="row">
<div class="col-xs-6">
<?php
echo $row['Bio']
?>
</div>
<div class="col-xs-6">
<div class="row">
<div class="col-xs-8">
<?php
echo $row['Address'] . '<br>' .
$row['City'] . ', ' . $row['State'] . ' ' . $row['ZipCode'];
?>
</div>
<div class="col-xs-4">
<?php
echo $row['Phone #'] . '<br>Price(1-5): ' . $row['Price'];
?>
</div>
<div class="form-group row">
<div class="col-xs-4"></div>
<div class="col-xs-6">
<br>
<label class="control-label">Add to Calendar</label>
<div class="input-group date" id="dp3" data-date="11/18/2013" data-date-format="mm/dd/yyyy">
<input class="form-control" type="text" readonly="" value="11/18/2013">
<span class="input-group-addon">
Add
</span>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<?php
echo '</div>';
?>
</div>
<?php
}
if($x == 0) {
echo 'No results found. :(';
}
One big echo block. Inefficient (?) but readable. Sadly no IDE smart suggestions or color coding (at least not with NetBeans).
~yes I know it's slightly different than above, sorry~Code
...
$x = 0;
while($row = mysqli_fetch_array($result))
{
$x++;
echo '
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a data-toggle="collapse" data-parent="#accordion" href="#collapse' . $x . '">
<div class="row">
<font face="verdana">
<div class="col-xs-6">' . $row['Price'] . '. ' . $row['Name'] . '</div>
<div class="col-xs-4">' . $row['Type'] . '</div>
<div class="col-xs-2">' . '*rating*' . '</div>
</font>
</div>
</a>
</h4>
</div>
<div id="collapse' . $x . '" class="panel-collapse collapse">
<div class="panel-body">
<div class="col-xs-6">' . $row['Bio'] . '</div>
<div class="col-xs-4">' . $row['Address'] . '<br>' .
$row['City'] . ', ' . $row['State'] . ' ' . $row['ZipCode'] . '</div>
<div class="col-xs-2">' . $row['Phone #'] . '
<br>
<form role="form">
<div class="checkbox">
<label>
<input type="checkbox">Add to favorites
</label>
</div>
</form>
</div>
</div>
</div>
</div>
';
}
if($x == 0) {
echo 'No results found. :(';
}
Second Concern:If you actually bothered to skim through my crap, please let me know any bad practices you see that can be reconciled! Thank you
Third Concern:Any other standard conventions I should be aware of / things that bother you smart peoples when the less-than-smart-peoples don't do it properly / etc.
I like learning to do things the
proper way, that way there's no unlearning of bad habits.