armlocker Posted June 1, 2013 Share Posted June 1, 2013 How do I add " In Stock" to in the view_cart.php on page 642? Adding the "in stock" field in MySQL is easy enough, but how do you add the link in the shopping car? Link to comment Share on other sites More sharing options...
HartleySan Posted June 2, 2013 Share Posted June 2, 2013 When you query the DB, you need to check the in_stock column as well, and if an item is in fact in stock, you mark it accordingly in your markup. Link to comment Share on other sites More sharing options...
Guest Deleted Posted June 2, 2013 Share Posted June 2, 2013 I guess you could just have an if statement that tells PHP: "If stock is greater than 0, say that it's in stock." Something like this: //lets pretend you got the item info from the database and put it in $item_info if ($item_info['stock'] > 0) { echo 'In stock'; }I don't have the book, so I don't know if this is what it wants you to do, but it seems like this would work if your database keeps track of how much of each item you have in stock Link to comment Share on other sites More sharing options...
armlocker Posted June 2, 2013 Author Share Posted June 2, 2013 Thank guys. I managed to figure this out: here's what I ended up doing which worked: echo (is_null($row['size'])) ? '(No size information available)' : $row['size']; echo "<br />£{$row['price']} "; if($row['in_stock']=='no') echo "<br>Out of stock. Email us to let us know and we will do everything we can to get it for you."; else echo "<a href=\"add_cart.php?pid=$pid\">Add to Cart</a>"; echo "<br >"; echo "Items in stock: ".$row['stock_available']; echo "</div><br />"; Link to comment Share on other sites More sharing options...
HartleySan Posted June 2, 2013 Share Posted June 2, 2013 Well played. Link to comment Share on other sites More sharing options...
Guest Deleted Posted June 2, 2013 Share Posted June 2, 2013 Hartley, am I correct in my observation that amlocker's code doesn't need an echo for every new line of output? I ask because I just corrected a friend of mine the other day, when she did this. She was using echo over and over and over when just one echo or a HEREDOC could have sufficed.Maybe amlocker could have done this? echo (is_null($row['size'])) ? '(No size information available)' : $row['size']; echo "<br />£{$row['price']} "; if($row['in_stock']=='no') echo "<br>Out of stock. Email us to let us know and we will do everything we can to get it for you. <a href=\"add_cart.php?pid=$pid\">Add to Cart</a> <br > Items in stock: ".$row['stock_available']." </div><br />"; Link to comment Share on other sites More sharing options...
HartleySan Posted June 3, 2013 Share Posted June 3, 2013 You are right in that armlocker can combine some of his echo statements, but your code is slightly different from his. You're missing the else statement, etc. Link to comment Share on other sites More sharing options...
Guest Deleted Posted June 3, 2013 Share Posted June 3, 2013 Oh! I didn't look closely enough at that. I thought it was an echo. LOL maybe I should not be replying to forum questions when I've only had four hours of sleep. Okay then I guess only the last two echos should be combined? I'll read your answer when I'm more rested. Link to comment Share on other sites More sharing options...
margaux Posted June 3, 2013 Share Posted June 3, 2013 Okay then I guess only the last two echos should be combined? I'll read your answer when I'm more rested. You are correct in that some of the echo statements could be combined - in this case it comes down to the developer's preference as it won't impact on performance. As you know there are several ways the echo statement can be coded. I like the HEREDOC approach when echoing out lots of HTML but going by comments on some other forums I am definitely in a minority 1 Link to comment Share on other sites More sharing options...
Guest Deleted Posted June 3, 2013 Share Posted June 3, 2013 I would use HEREDOC more but I have a heavily ingrained habit of using echo (or print, I'm not consistent) and single quotes for everything xD This is typical of what I do on my site: print ' <br /> <table class="table rounded" style="width: 600px"> <tr> <td class="header1 align-center" colspan="2"> <strong>'.$post['title'].'</strong> </td> </tr> <tr> <td class="post-sidebar align-center rounded" style="width:175px"> <div style="text-align:center"> '.timezone_convert($post['timestamp'], $this->user_info['timezone']).'<br />'.display_avatar($post['avatar_url']).' <a href="'.base_url().'user/profile/'.$post['author_id'].'">'.$post['display_name'].'</a></div> </td> <td class="post-content" style="width:475px"> <div class="post_cushion">'.nl2br($post['message']).'</div> </td> </tr> <tr> <td class="header2" colspan="2"> <div style="text-align:center; font-weight:bold"> '.$rating_html.$comments_link.$extra_links.'</div> </td> </tr> </table> '.$last_brs; Speaking of which, I don't even think I know how you'd use this mess with HEREDOC. Any suggestions? It's probably high time I learn xD lol Link to comment Share on other sites More sharing options...
HartleySan Posted June 3, 2013 Share Posted June 3, 2013 Check the documentation: http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc Link to comment Share on other sites More sharing options...
Recommended Posts