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
I will appreciate your help.
Thanks again for your help.

"Christopher Ostmo" <[EMAIL PROTECTED]> wrote in message
> 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
> > for the quantity of the item number. If the quantity number is 0 or
> > it will show "Out of Stock", else will show "In Stock" on my web page.
> > 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
> Innovative Application Ideas
> Meeting cutting edge dynamic
> web site needs since the
> dawn of Internet time (1995)
> Business Applications:
> Open Source Applications:

PHP Database Mailing List (
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to