Re: [PHP-DB] Help!!! Can anybody help me with my script?

2001-07-20 Thread Christopher Ostmo

Tony pressed the little lettered thingies in this order...

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

Take a look at function()
http://php.he.net/manual/en/functions.php
and require:
http://php.he.net/manual/en/function.require.php

Define the code in the file you are requiring:
function inStock($itemx) {
...do query here...
...echo result here...
}

And in your regular pages:
require("file_with_functions.php");
inStock($itemx);

That's about it.

Good luck...

Christopher Ostmo
a.k.a. [EMAIL PROTECTED]
AppIdeas.com
Innovative Application Ideas
Meeting cutting edge dynamic
web site needs since the 
dawn of Internet time (1995)

For a good time,
http://www.AppIdeas.com/

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP-DB] Help!!! Can anybody help me with my script?

2001-07-20 Thread Tony

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" <[EMAIL PROTECTED]> wrote in message
3B5858C3.22011.4C90352@localhost">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. [EMAIL PROTECTED]
> 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/



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP-DB] Help!!! Can anybody help me with my script?

2001-07-20 Thread Christopher Ostmo

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. [EMAIL PROTECTED]
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/

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]