Code: Select all
I've developed a website myself over the last 6 months. I've gotten some investment to develop it further and will now have 2 develoeprs working with me. Its a market place style website so high hits are expected and speed is a must. I was wondering, is my code up to scratch? what exactly are best practices in php? Here's an example of how i get all products on the index page:
Code: Select all
$sql = "SELECT si.Name, si.ShopItemID, si.Active, si.InStock, si.DateAdded, si.Price, s.CountyID, si.Url as ItemUrl, s.Url as ShopUrl, si.Approved, ii.Url, ii.Active, ii.Front, ii.Thumb, ii.OrderImage, s.CategoryID, s.ShopID, s.Active ";
$sql = $sql."FROM shopitem si ";
$sql = $sql."Inner Join shop s On (s.ShopID = si.ShopID) ";
$sql = $sql."left Join itemimage ii on (ii.ShopItemID = si.ShopItemID And ii.OrderImage = 1) Where 1=1 and si.Active = 1 and si.InStock > 0 and s.Active = 1 and si.Approved = 1 ";
if(!$categoryId==0 and !$categoryId==""){
$sql = $sql."And CategoryID = ".mysql_real_escape_string($categoryId);
}
$sql .= " Group By si.ShopItemID ";Code: Select all
while ($row = mysql_fetch_array($result)) {
echo "<div class='shopItems'>";
echo "<div id='itemIndex'>".$x.".</div>";
if(!$row['Url']==NULL){
echo "<div id='centered'><a href='".WEBSITE_DOMAIN."shops/".$row['ShopUrl']."/".$row['ItemUrl']."'><img alt='".htmlspecialchars($row['Name'])."' title='".htmlspecialchars($row['Name'])."' height='135' width='170' src='images/".htmlspecialchars($row['Front'])."'/></a></div>";
}
else{
echo "<div id='centered'><a href='".WEBSITE_DOMAIN."shops/".$row['ShopUrl']."/".$row['ItemUrl']."'><img alt='".htmlspecialchars($row['Name'])."' title='".htmlspecialchars($row['Name'])."' height='135' width='170' src='images/no-img.jpg'/></a></div>";
}
echo "<div id='centered'><a href='".WEBSITE_DOMAIN."shops/".$row['ShopUrl']."/".$row['ItemUrl']."'>".htmlspecialchars($row['Name'])."</a></div>";
echo "<p id='centered'>€".htmlspecialchars($row['Price'])."</p>";
echo "</div>";
If($x%4==0){
echo "<div id='clear'></div>";
echo "<div id='divider'></div>";
}
$x++;
}thanks
Mark