Jump to content
Larry Ullman's Book Forums
Sign in to follow this  
armlocker

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

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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 :)

Share this post


Link to post
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 />";

Share this post


Link to post
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 />";

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
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.

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...