Re: Help!!! Can anybody help me with my script?
| From: | Tony | Date: | Sat, 21 Jul 2001 01:57:39 +0000 |
| Subject: | Re: Help!!! Can anybody help me with my script? | ||
| References: | 1 2 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-10624@lists.php.net to get a copy of this message | ||
Thanks for your quick respond and your help.
This is great.
I have one more favor to ask you. As you know I am a beginner of PHP &
Mysql, do I put that language on all my product pages? It seems to be too
much work.
Is there way that I can save main language that you wrote in to one file as
"stock.php3", and point a link from product html page with known item number
for "itemx"?
And, print the result back to product html page with "Out of Stock" or "In
Stock".
I will appreciate your help.
Thanks again for your help.
Tony
"Christopher Ostmo" <tech@appideas.com> wrote in message
news:3B5858C3.22011.4C90352@localhost...
> Tony pressed the little lettered thingies in this order...
>
> > I am trying to figure out how to read data base(Mysql) with rows of item
> > number (item) and quantity, so that when item number was given, it
searched
> > for the quantity of the item number. If the quantity number is 0 or
less,
> > it will show "Out of Stock", else will show "In Stock" on my web page.
Here
> > is part of language that I wrote and didn't work. Please help me what to
> > do,
> >
>
> There are two common methods. One uses PHP and the other uses
> MySQL. The one that is most efficient depends largely on the design
> and size of the table and the desired output. See below...
>
> > $result = mysql_query("SELECT * FROM inventory",$link);
> >
>
> Here are the two queries that will work. The first with PHP:
> $result = mysql_query("SELECT * FROM inventory WHERE item =
> '$itemx'",$link);
> $num = mysql_num_rows($result);
> if ($num < 1) {
> echo "Out of stock";
> } else {
> echo "In stock";
> }
>
> This would be very inneficient because it requires MySQL to do a full
> retrieval from the table. The only reason you would want to do it this way
> is if you wanted to relace the "In stock" above with actual results from
> the query.
>
> If you just wanted to say "In stock" it would be more efficient to use
> MySQL's built-in COUNT(*) function:
> $result = mysql_query("SELECT COUNT(*) FROM inventory WHERE
> item = '$itemx'",$link);
> while ($row = mysql_fetch_row($result)) {
> $num = $row[0];
> }
> if ($num < 1) {
> echo "Out of stock";
> } else {
> echo "In stock";
> }
>
> Note that if you use mysql_num_rows() on the second query, you will
> always get a result of one (1) because the number of rows that MySQL
> returns with this query will always be one (it returns how many records
> matched your query as its one row return), assuming that there are no
> errors. In either case, you can echo $num to display the number of
> records returned.
>
> Good luck...
>
> Christopher Ostmo
> a.k.a. tech@AppIdeas.com
> AppIdeas.com
> Innovative Application Ideas
> Meeting cutting edge dynamic
> web site needs since the
> dawn of Internet time (1995)
>
> Business Applications:
> http://www.AppIdeas.com/
>
> Open Source Applications:
> http://open.AppIdeas.com/