Jump to content
Larry Ullman's Book Forums

How Do I Add In Stock To In The View_Cart.Php


Recommended Posts

Guest Deleted

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

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

Guest Deleted

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

Guest Deleted

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

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 :)

  • Upvote 1
Link to comment
Share on other sites

Guest Deleted

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

 Share

×
×
  • Create New...