Re: [PHP] Re: PHP and MySQL SELECT COUNT (*)

2008-09-18 Thread Vinny Gullotta
Thanks all, I appreciate the follow ups and the help with the code. I'm 
still relatively new with this stuff, and never had any formal training, 
it's all just been learn as I go, and I have to learn fast as this project 
is relatively urgent to get completed. I plan on going through all of my 
code on all of these pages and cleaning it up at the end to make it more 
efficient, so I will use these tips to help do that.


Thanks again to all who helped troubleshoot this. It is working great now 
and I think my bosses will be happy. =D



"Nathan Rixham" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]

learn something new every day! cheers Micah :)

Micah Gersten wrote:

While it's true that '.' concatenates and ',' is a list separator, The
comma is actually more appropriate in this instance since you are just
outputting each piece.  It saves the overhead of concatenation before
output.

Thank you,
Micah Gersten
onShore Networks
Internal Developer
http://www.onshore.com



Nathan Rixham wrote:

6: " vs '
when you use " php will parse the enclosed string for variables, when
you use ' it won't; so ' leads for faster code, and also encourages
you to code strongly by closing strings and concatenating variables.
Further it allows you to use valid html " around attributes rather
than the invalid '

7: , vs .
there is no vs :) to concatenate we use . (period) not , (comma)

so for 6 & 7..
echo '' . $i['servername'] . '';

I'm going to stop there, hope it helps a little bit; and I won't go
any further as half the fun is learning; so you finding out how to
save time on queries and write your own db handlers etc is not my
domain I reckons

Regards

nathan




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: PHP and MySQL SELECT COUNT (*)

2008-09-17 Thread Chris



1: SQL
in mysql queries /should/ use backticks (`) around database, table and 
column names, stop's them getting confused with variables or reserved 
words (like timestamp) and saves you future trouble :)


.. which is a mysql-ism - no other database supports this. As soon as 
you need to use another db (regardless of whether it's this application 
or not), you're stuffed.


For reserved word column names, you don't have much choice but don't do 
that in the first place ;)


http://dev.mysql.com/doc/refman/5.0/en/reserved-words.html

Other db's will have a similar list - though in most cases, if it's a 
function or sql keyword (eg 'table'), it'll be reserved in all.


further, you'll be needing to use AS to turn COUNT(steps) into a nice 
name like "stepcount"


Which is also a mysql-ism. Most other db's don't let you use aggregate 
aliases in an order by clause (I think because the sql standard says 
don't do that).


--
Postgresql & php tutorials
http://www.designmagick.com/


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: PHP and MySQL SELECT COUNT (*)

2008-09-17 Thread Nathan Rixham

learn something new every day! cheers Micah :)

Micah Gersten wrote:

While it's true that '.' concatenates and ',' is a list separator, The
comma is actually more appropriate in this instance since you are just
outputting each piece.  It saves the overhead of concatenation before
output.

Thank you,
Micah Gersten
onShore Networks
Internal Developer
http://www.onshore.com



Nathan Rixham wrote:

6: " vs '
when you use " php will parse the enclosed string for variables, when
you use ' it won't; so ' leads for faster code, and also encourages
you to code strongly by closing strings and concatenating variables.
Further it allows you to use valid html " around attributes rather
than the invalid '

7: , vs .
there is no vs :) to concatenate we use . (period) not , (comma)

so for 6 & 7..
echo '' . $i['servername'] . '';

I'm going to stop there, hope it helps a little bit; and I won't go
any further as half the fun is learning; so you finding out how to
save time on queries and write your own db handlers etc is not my
domain I reckons

Regards

nathan



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: PHP and MySQL SELECT COUNT (*)

2008-09-17 Thread Micah Gersten
While it's true that '.' concatenates and ',' is a list separator, The
comma is actually more appropriate in this instance since you are just
outputting each piece.  It saves the overhead of concatenation before
output.

Thank you,
Micah Gersten
onShore Networks
Internal Developer
http://www.onshore.com



Nathan Rixham wrote:
>
> 6: " vs '
> when you use " php will parse the enclosed string for variables, when
> you use ' it won't; so ' leads for faster code, and also encourages
> you to code strongly by closing strings and concatenating variables.
> Further it allows you to use valid html " around attributes rather
> than the invalid '
>
> 7: , vs .
> there is no vs :) to concatenate we use . (period) not , (comma)
>
> so for 6 & 7..
> echo '' . $i['servername'] . '';
>
> I'm going to stop there, hope it helps a little bit; and I won't go
> any further as half the fun is learning; so you finding out how to
> save time on queries and write your own db handlers etc is not my
> domain I reckons
>
> Regards
>
> nathan
>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: PHP and MySQL SELECT COUNT (*)

2008-09-17 Thread Nathan Rixham

Vinny Gullotta wrote:
What I want to do is find the top 10 servers where the column steps = 
iisreset. The following code works great except that the page is not 
displaying the servername in the 'Server Name' column of my results 
(nothing appears, the column is just blank).


servername and steps are the important columns in the database table. 
$_POST[time1] and $_POST[time2] come from a form submitted.


When I copy and paste the entire select statement into the SQL tab in 
phpmyadmin (and replace the time variables with actual times 
corresponding to the timestamp column), it displays the correct results 
including servername. Everything works in the php page's results except 
for the servername. I feel like it's right in front of my face and 
that's why I can't see it lol. Any help would be greatly appreciated. 
Thanks in advance =)


My code...

$query = "SELECT servername, COUNT(steps) FROM monitoring WHERE steps 
LIKE 'iisreset' AND timestamp <= '$_POST[time2]' AND timestamp >= 
'$_POST[time1]' GROUP BY servername ORDER BY COUNT(*) DESC LIMIT 10";

$result = mysql_query($query) or die(mysql_error());

# display column titles
echo "";
echo "Count";
echo "Server 
Name";

echo "";

#display results
while($i = mysql_fetch_row($result))
{
echo "", $i[COUNT('steps')], 
"";

echo "", $i[servername] ,"";
}
echo "";


just a few little notes.. because I'm like this today

(none of it is a you must do, or meant badly, just aiming to save you 
some time by passing on a few *things*)


1: SQL
in mysql queries /should/ use backticks (`) around database, table and 
column names, stop's them getting confused with variables or reserved 
words (like timestamp) and saves you future trouble :)


further, you'll be needing to use AS to turn COUNT(steps) into a nice 
name like "stepcount"


so..
$query = 'SELECT `servername`, COUNT(`steps`) AS stepcount FROM 
`monitoring` WHERE `steps` LIKE "iisreset" AND `timestamp` <= ' . 
$_POST[time2] . ' AND `timestamp` >= ' . $_POST[time1] . ' GROUP BY 
`servername` ORDER BY COUNT(*) DESC LIMIT 10';


2: you should be cleaning those posts before you add them to a mysql 
query; this has been covered many times so I won't repost it 
(mysql_real_escape() or sprintf or.. many different methods]


3: Needless multiple echo's; one will suffice just fine and show it up 
in your editor as a nice easily visible block of html :)


echo '
Count
Server Name
';

4: valid xhtml; in my opinion there's no excuse now; it's been years 
since it came out (and you're already using css); this will do the same 
as above:

echo '

Count
Server Name
';

[css to center the table would be]
table.center {
margin: 0 auto;
}

5: mysql_fetch_row() returns a numerical indexed array.. not associative 
thus:

$i = mysql_fetch_row($result)
print_r($i);

will show..
$i[0] => the server name
$i[1] => stepcount value

you'll be needing
$i = mysql_fetch_assoc($result);
print_r($i);

which will show
$i['servername'] => the server name
$i['stepcount'] => stepcount value

6: " vs '
when you use " php will parse the enclosed string for variables, when 
you use ' it won't; so ' leads for faster code, and also encourages you 
to code strongly by closing strings and concatenating variables.
Further it allows you to use valid html " around attributes rather than 
the invalid '


7: , vs .
there is no vs :) to concatenate we use . (period) not , (comma)

so for 6 & 7..
echo '' . $i['servername'] . '';

I'm going to stop there, hope it helps a little bit; and I won't go any 
further as half the fun is learning; so you finding out how to save time 
on queries and write your own db handlers etc is not my domain I reckons


Regards

nathan

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: PHP and mySQL dates

2006-09-13 Thread Colin Guthrie

> "SELECT id FROM dates WHERE FROM_UNIXTIME($date_string) = date"
> 
> then
> 
> "SELECT id FROM dates WHERE UNIX_TIMESTAMP(date) = $date_string"
> 
> neither is working. Am I making some fundamental error here or missing
> something? Any help appreciated!

I know yui've alreayd solved this, but for what it's worth, the first
form of statement is preferred to the second.

In the second you are applying a MYSQL function to a field which will
have to be repeated many times, in the first, you are applying a MYSQL
function to a constant which only has to be computed once.

Even now you have the solution, it may be worth considering the order of
your check and if possible use the MYSQL function ont he constant not
the field to get the additional performance gain.

Col.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: PHP and mySQL getting smashed...

2006-05-18 Thread Robert Samuel White
Upgrade your MySQL distribution to the latest version (5+).

 

Upgrade any shared MySQL libraries to the latest distribute.

 

Recompile MySQL with mysqli support.

 

http://php.net/mysqli

 

And use that instead of the regular MySQL functions.

 

That's what I did and it has made a huge difference.

 

Not to mention, the mysqli library has so many more functions available to
you.

 

~Samuel

 

 



[PHP] Re: PHP and MySQL Installation on Apache for Windows

2004-07-16 Thread Ciprian Constantinescu
PHP doesn't detect anything. You need to have your mysql server running and
you try with mysql_connect() or mysql_pconnect() to see if you can connect
to the server

"Sean Vasey" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Does anyone know how to get PHP to detect MySQL after it has been
installed and is running on an Apache 1.3.1 server for Windows? Any help
would be greatly appreciated.
>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: php and mysql help

2004-04-14 Thread Eric Bolikowski

"Webmaster" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
Hello i need help with mysql_create_db i found the solution once but cant
remember what it was if someone could tell me the proper way to create a
database with php and mysql i would be greatly thankfull.
Thank you.



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: PHP and MySQL date

2003-12-15 Thread John W. Holmes
Cesar Aracena wrote:

I tried what both of you told me and I found very easy to use the datetime
value under MySQL and then fetch it using strtotime() as fireball at
sizzling dot com recommended at the "User Contributed Notes" of php.net's
function.date.php page rather than using mktime() which can output incorrect
dates.
You can also use the MySQL function DATE_FORMAT() to format the MySQL 
timestamp to your liking. It is very similar to the PHP date() function.

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals – www.phparch.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: PHP and MySQL date

2003-12-15 Thread Cesar Aracena
Thanks both of you for the answer.

I tried what both of you told me and I found very easy to use the datetime
value under MySQL and then fetch it using strtotime() as fireball at
sizzling dot com recommended at the "User Contributed Notes" of php.net's
function.date.php page rather than using mktime() which can output incorrect
dates.

Thankis to both and everyone.

"Cesar Aracena" <[EMAIL PROTECTED]> escribió en el mensaje
news:[EMAIL PROTECTED]
> Hi all,
>
> I'm making a site and need some tables from wich I can extract date, time
> and/or date/time later with PHP and I neved had very clear the way the
> possible formats work with each other so my question is what is the best
(or
> recommended) method to store dates and/or times in a MySQL DB for PHP to
> work later?
>
> Thanks in advanced,
> ___
> Cesar L. Aracena
> Commercial Manager / Developer
> ICAAM Web Solutions
> 2K GROUP
> Neuquen, Argentina
> Tel: +54.299.4774532
> Cel: +54.299.6356688
> E-mail: [EMAIL PROTECTED]

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: PHP and MySQL date

2003-12-15 Thread Justin Patrin
Cesar Aracena wrote:

Hi all,

I'm making a site and need some tables from wich I can extract date, time
and/or date/time later with PHP and I neved had very clear the way the
possible formats work with each other so my question is what is the best (or
recommended) method to store dates and/or times in a MySQL DB for PHP to
work later?
Thanks in advanced,
___
Cesar L. Aracena
Commercial Manager / Developer
ICAAM Web Solutions
2K GROUP
Neuquen, Argentina
Tel: +54.299.4774532
Cel: +54.299.6356688
E-mail: [EMAIL PROTECTED]
The best way is to use a datetime or timestamp type in MySql, depending 
on your use of it. Using MySql's types allows you to use MySql's date 
comparison and functions for queries. You can get a UNIX timestamp using 
the UNIX_TIMESTAMP() function in mysql or by using strtotime() in PHP on 
the value.

--
paperCrane 
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: PHP and MYSQL

2003-07-07 Thread jsWalter

"Bob G" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Please help I am going quite mad.

> ... The PHP.INI file is in the PHP directory.

the php.ini in your PHP directory is useless

It needs to be in 1 of 3 places...
 1) the IIS root directory, meaning where IIS EXE is at,
*not* the web root
 2) C:\WINNT (or where ever your system directory is called)
 3) C:\php4 (this is HARD CODED as a last resort)

I have mine in my web server directory *and* in my PHP directory.

That way I can run it via web server or command line.

Walter





-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Re: PHP and MYSQL

2003-07-07 Thread Cybot
Here is the script for what it's worth.
...

IS IT WORKING?
 


and the result is
IS IT WORKING?


are your trying to fool the list?

whate else do you expect than > when you write > ??

would ASP work if your write "<% [ASP-CODE] %>" ??

i think not,

in short just write < and > rather then < and >



IS IT WORKING?
 


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: php and mysql

2003-03-31 Thread Tim Burden
Assuming Month_Start is stored in MySQL date format (-mm-dd) you could
Select blah blah From blah Order By DATE_FORMAT(Month_Start,%m) ASC
The %m will pad on the zeroes.

http://www.mysql.com/doc/en/Date_and_time_functions.html

- Original Message -
From: "Tyler Durdin" <[EMAIL PROTECTED]>
Newsgroups: php.general
To: <[EMAIL PROTECTED]>
Sent: Monday, March 31, 2003 1:53 PM
Subject: php and mysql


>
> I have a db with events in it. i would like to pull the events out via
php,
> but i would like them to be ordered by month number (1-12). When I do this
> (Select blah blah From blah Order By Month_Start ASC) it orders the months
> by number, but it starts with october (month 10) I am pretty sure it is
> doing this because I have no events until april (month 4). So how can i
get
> it to order the months by their numbers starting with january (1) and
going
> to december (12) even if I do not have events until april (4)?
>
>
>
>
> _
> The new MSN 8: advanced junk mail protection and 2 months FREE*
> http://join.msn.com/?page=features/junkmail
>


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: PHP and MySQL bug

2003-01-08 Thread Nuno Lopes
Doesn't you have any simpler answer??


Maybe installing the new version of mysql server - I have version 3.23.49 -
should do the trick



- Original Message -
From: "Larry Brown" <[EMAIL PROTECTED]>
To: "Nuno Lopes" <[EMAIL PROTECTED]>; "MySQL List" <[EMAIL PROTECTED]>
Sent: Tuesday, January 07, 2003 4:12 PM
Subject: RE: [PHP] Re: PHP and MySQL bug


> Since nobody is jumping in to say it is some simple configuration/setting
> personally my next step would be to shut down all services on the box that
> aren't absolutely necessary and stop everything in the registry under run
> and stop anything in the start folder of the start menu and run the same
> tests.  If no positive results I would uninstall php completely and clean
> any reference in the registry of it and then install with everything still
> shut down.  Retest, if no progress do the same with mysql.  These are
> radical and time-consuming methods, but it seems as though it is broken.
If
> you absolutely need this fixed fast you might resort to paying the
> developers to give you a solution, although it may end up being what I
just
> listed, or it could be some simple fix that we aren't aware of.
>
> Larry S. Brown
> Dimension Networks, Inc.
> (727) 723-8388
>
> -Original Message-
> From: Nuno Lopes [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, January 07, 2003 4:31 AM
> To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
> Subject: Re: [PHP] Re: PHP and MySQL bug
>
> I have the latest version of PHP (4.3.0) as module in apache 2.0.43 and
> mysql 3.23.49.
> Everything is working fine, except this.
> With pconnect the error is the same!
>
>
> - Original Message -----
> From: "Larry Brown" <[EMAIL PROTECTED]>
> To: "MySQL List" <[EMAIL PROTECTED]>
> Sent: Monday, January 06, 2003 6:28 PM
> Subject: RE: [PHP] Re: PHP and MySQL bug
>
>
> > This definitely sounds like a buggy installation or there may be some
> > problem with the communication between the web server and the mysqld.
Is
> > the db on a different machine?  Try using mysql_pconnect instead of
> connect
> > just to see what result you get.  I have read some unfavorable
statements
> > about using pconnect with a large number of hits so if it works you
should
> > read the comments about it on php.net.  Do a search for mysql_pconnect.
> >
> > Larry S. Brown
> > Dimension Networks, Inc.
> > (727) 723-8388
> >
> > -Original Message-
> > From: Nuno Lopes [mailto:[EMAIL PROTECTED]]
> > Sent: Monday, January 06, 2003 1:09 PM
> > To: MySQL List; [EMAIL PROTECTED]
> > Subject: [PHP] Re: PHP and MySQL bug
> >
> > The problem is if I close the connection and reopen it the query is
done,
> > but if I remain with the same connection has the previous query, mysql
> > returns an error.
> >
> >
> > - Original Message -
> > From: "Larry Brown" <[EMAIL PROTECTED]>
> > To: "MySQL List" <[EMAIL PROTECTED]>
> > Sent: Sunday, January 05, 2003 4:16 PM
> > Subject: Re:PHP and MySQL bug
> >
> >
> > > Try replacing the following line...
> > >
> > > @MYSQL_QUERY("UPDATE d SET h='$h' WHERE id='$id'"); // this query
> doesn't
> > > work
> > >
> > > With...
> > >
> > > $query = "UPDATE d SET h='$h' WERE id='$id'";
> > > $queryr = mysql_query($query) or die("The sql statement does not
> > execute");
> > >
> > > if(mysql_affected_rows() !== 1)
> > > {
> > >die("The sql statement is successfully run however either h did not
> > > change or there is an internal error.  Try executing the sql from the
> > > command line to make sure it otherwise works.");
> > > }
> > >
> > > and see which is coming back.
> > >
> > >
> > > Larry S. Brown
> > > Dimension Networks, Inc.
> > > (727) 723-8388




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Re: PHP and MySQL bug

2003-01-08 Thread Nuno Lopes
@mysql_select_db("be"); // this doesn't fail, because only the second
(UPDATE) query fails. The first query (SELECT) is done!


- Original Message -
From: "Marek Kilimajer" <[EMAIL PROTECTED]>
To: "Nuno Lopes" <[EMAIL PROTECTED]>
Cc: "MySQL List" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
Sent: Tuesday, January 07, 2003 5:06 PM
Subject: Re: [PHP] Re: PHP and MySQL bug


> @mysql_select_db("be"); -- this failed
> do echo mysql_error(); to see what went wrong
>
>
>
> Nuno Lopes wrote:
>
> >I done a echo of Mysql_error and it returned:
> >'Nenhum banco de dados foi selecionado'
> >
> >(I have the mysql server in portuguese, but the translation is something
> >like 'no db was selected')
> >
> >
> >----- Original Message -
> >From: "David Freeman" <[EMAIL PROTECTED]>
> >To: <[EMAIL PROTECTED]>
> >Sent: Sunday, January 05, 2003 10:29 PM
> >Subject: RE: [PHP] Re: PHP and MySQL bug
> >
> >
> >
> >
> >> > @MYSQL_QUERY("UPDATE d SET h='$h' WHERE id='$id'"); // this
> >> > query doesn't work
> >>
> >>Personally, I'd call it bad programming practice to do a database update
> >>and not check to see if it worked or not.  In this case, how are you
> >>determining that the query did not work?  Are you manually checking the
> >>database?  You don't have anything in your code to check the status of
> >>this query.
> >>
> >>Perhaps this might get you somewhere:
> >>
> >>$qid = @mysql_query("UPDATE d SET h = '$h' WHERE id = '$id'");
> >>
> >>if (isset($qid) && mysql_affected_rows() == 1)
> >>{
> >>  echo "query executed";
> >>} else {
> >>  echo "query failed: " . mysql_error();
> >>}
> >>
> >>At least this way you might get some indication of where the problem is.
> >>
> >>CYA, Dave



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Re: PHP and MySQL bug

2003-01-07 Thread Nuno Lopes
I'm using Windows 2000.


- Original Message -
From: "Cleber" <[EMAIL PROTECTED]>
To: "Nuno Lopes" <[EMAIL PROTECTED]>
Sent: Tuesday, January 07, 2003 10:23 AM
Subject: Re: [PHP] Re: PHP and MySQL bug


> Try add to /etc/hosts the name and ip of DB is located
>
>
> - Original Message -
> From: "Nuno Lopes" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
> Sent: Tuesday, January 07, 2003 7:31 AM
> Subject: Re: [PHP] Re: PHP and MySQL bug
>
>
> > I have the latest version of PHP (4.3.0) as module in apache 2.0.43 and
> > mysql 3.23.49.
> > Everything is working fine, except this.
> > With pconnect the error is the same!
> >
> >
> > - Original Message -
> > From: "Larry Brown" <[EMAIL PROTECTED]>
> > To: "MySQL List" <[EMAIL PROTECTED]>
> > Sent: Monday, January 06, 2003 6:28 PM
> > Subject: RE: [PHP] Re: PHP and MySQL bug
> >
> >
> > > This definitely sounds like a buggy installation or there may be some
> > > problem with the communication between the web server and the mysqld.
> Is
> > > the db on a different machine?  Try using mysql_pconnect instead of
> > connect
> > > just to see what result you get.  I have read some unfavorable
> statements
> > > about using pconnect with a large number of hits so if it works you
> should
> > > read the comments about it on php.net.  Do a search for
mysql_pconnect.
> > >
> > > Larry S. Brown
> > > Dimension Networks, Inc.
> > > (727) 723-8388
> > >
> > > -Original Message-
> > > From: Nuno Lopes [mailto:[EMAIL PROTECTED]]
> > > Sent: Monday, January 06, 2003 1:09 PM
> > > To: MySQL List; [EMAIL PROTECTED]
> > > Subject: [PHP] Re: PHP and MySQL bug
> > >
> > > The problem is if I close the connection and reopen it the query is
> done,
> > > but if I remain with the same connection has the previous query, mysql
> > > returns an error.
> > >
> > >
> > > - Original Message -
> > > From: "Larry Brown" <[EMAIL PROTECTED]>
> > > To: "MySQL List" <[EMAIL PROTECTED]>
> > > Sent: Sunday, January 05, 2003 4:16 PM
> > > Subject: Re:PHP and MySQL bug
> > >
> > >
> > > > Try replacing the following line...
> > > >
> > > > @MYSQL_QUERY("UPDATE d SET h='$h' WHERE id='$id'"); // this query
> > doesn't
> > > > work
> > > >
> > > > With...
> > > >
> > > > $query = "UPDATE d SET h='$h' WERE id='$id'";
> > > > $queryr = mysql_query($query) or die("The sql statement does not
> > > execute");
> > > >
> > > > if(mysql_affected_rows() !== 1)
> > > > {
> > > >die("The sql statement is successfully run however either h did
not
> > > > change or there is an internal error.  Try executing the sql from
the
> > > > command line to make sure it otherwise works.");
> > > > }
> > > >
> > > > and see which is coming back.
> > > >
> > > >
> > > > Larry S. Brown
> > > > Dimension Networks, Inc.
> > > > (727) 723-8388



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Re: PHP and MySQL bug

2003-01-07 Thread Marek Kilimajer
@mysql_select_db("be"); -- this failed
do echo mysql_error(); to see what went wrong



Nuno Lopes wrote:


I done a echo of Mysql_error and it returned:
'Nenhum banco de dados foi selecionado'

(I have the mysql server in portuguese, but the translation is something
like 'no db was selected')


- Original Message -
From: "David Freeman" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Sunday, January 05, 2003 10:29 PM
Subject: RE: [PHP] Re: PHP and MySQL bug


 

> @MYSQL_QUERY("UPDATE d SET h='$h' WHERE id='$id'"); // this
> query doesn't work

Personally, I'd call it bad programming practice to do a database update
and not check to see if it worked or not.  In this case, how are you
determining that the query did not work?  Are you manually checking the
database?  You don't have anything in your code to check the status of
this query.

Perhaps this might get you somewhere:

$qid = @mysql_query("UPDATE d SET h = '$h' WHERE id = '$id'");

if (isset($qid) && mysql_affected_rows() == 1)
{
 echo "query executed";
} else {
 echo "query failed: " . mysql_error();
}

At least this way you might get some indication of where the problem is.

CYA, Dave
   




 



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Re: PHP and MySQL bug

2003-01-07 Thread Nuno Lopes
I have the latest version of PHP (4.3.0) as module in apache 2.0.43 and
mysql 3.23.49.
Everything is working fine, except this.
With pconnect the error is the same!


- Original Message -
From: "Larry Brown" <[EMAIL PROTECTED]>
To: "MySQL List" <[EMAIL PROTECTED]>
Sent: Monday, January 06, 2003 6:28 PM
Subject: RE: [PHP] Re: PHP and MySQL bug


> This definitely sounds like a buggy installation or there may be some
> problem with the communication between the web server and the mysqld.  Is
> the db on a different machine?  Try using mysql_pconnect instead of
connect
> just to see what result you get.  I have read some unfavorable statements
> about using pconnect with a large number of hits so if it works you should
> read the comments about it on php.net.  Do a search for mysql_pconnect.
>
> Larry S. Brown
> Dimension Networks, Inc.
> (727) 723-8388
>
> -Original Message-
> From: Nuno Lopes [mailto:[EMAIL PROTECTED]]
> Sent: Monday, January 06, 2003 1:09 PM
> To: MySQL List; [EMAIL PROTECTED]
> Subject: [PHP] Re: PHP and MySQL bug
>
> The problem is if I close the connection and reopen it the query is done,
> but if I remain with the same connection has the previous query, mysql
> returns an error.
>
>
> - Original Message -
> From: "Larry Brown" <[EMAIL PROTECTED]>
> To: "MySQL List" <[EMAIL PROTECTED]>
> Sent: Sunday, January 05, 2003 4:16 PM
> Subject: Re:PHP and MySQL bug
>
>
> > Try replacing the following line...
> >
> > @MYSQL_QUERY("UPDATE d SET h='$h' WHERE id='$id'"); // this query
doesn't
> > work
> >
> > With...
> >
> > $query = "UPDATE d SET h='$h' WERE id='$id'";
> > $queryr = mysql_query($query) or die("The sql statement does not
> execute");
> >
> > if(mysql_affected_rows() !== 1)
> > {
> >die("The sql statement is successfully run however either h did not
> > change or there is an internal error.  Try executing the sql from the
> > command line to make sure it otherwise works.");
> > }
> >
> > and see which is coming back.
> >
> >
> > Larry S. Brown
> > Dimension Networks, Inc.
> > (727) 723-8388



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] Re: PHP and MySQL bug

2003-01-06 Thread Jennifer Goodie
It would be helpful if you posted that error.  You can get it by changing
the die to

$queryr = mysql_query($query) or die(mysql_error());

Without knowing the error, you problem will be harder for everyone to debug.


-Original Message-
From: Nuno Lopes [mailto:[EMAIL PROTECTED]]
Sent: Monday, January 06, 2003 10:09 AM
To: MySQL List; [EMAIL PROTECTED]
Subject: Re: PHP and MySQL bug

The problem is if I close the connection and reopen it the query is done,
but if I remain with the same connection has the previous query, mysql
returns an error.


- Original Message -
From: "Larry Brown" <[EMAIL PROTECTED]>
To: "MySQL List" <[EMAIL PROTECTED]>
Sent: Sunday, January 05, 2003 4:16 PM
Subject: Re:PHP and MySQL bug


> Try replacing the following line...
>
> @MYSQL_QUERY("UPDATE d SET h='$h' WHERE id='$id'"); // this query doesn't
> work
>
> With...
>
> $query = "UPDATE d SET h='$h' WERE id='$id'";
> $queryr = mysql_query($query) or die("The sql statement does not
execute");
>
> if(mysql_affected_rows() !== 1)
> {
>die("The sql statement is successfully run however either h did not
> change or there is an internal error.  Try executing the sql from the
> command line to make sure it otherwise works.");
> }
>
> and see which is coming back.
>
>
> Larry S. Brown
> Dimension Networks, Inc.
> (727) 723-8388
>



-
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/   (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail
<[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] Re: PHP and MySQL bug

2003-01-06 Thread Nuno Lopes
The problem is if I close the connection and reopen it the query is done,
but if I remain with the same connection has the previous query, mysql
returns an error.


- Original Message -
From: "Larry Brown" <[EMAIL PROTECTED]>
To: "MySQL List" <[EMAIL PROTECTED]>
Sent: Sunday, January 05, 2003 4:16 PM
Subject: Re:PHP and MySQL bug


> Try replacing the following line...
>
> @MYSQL_QUERY("UPDATE d SET h='$h' WHERE id='$id'"); // this query doesn't
> work
>
> With...
>
> $query = "UPDATE d SET h='$h' WERE id='$id'";
> $queryr = mysql_query($query) or die("The sql statement does not
execute");
>
> if(mysql_affected_rows() !== 1)
> {
>die("The sql statement is successfully run however either h did not
> change or there is an internal error.  Try executing the sql from the
> command line to make sure it otherwise works.");
> }
>
> and see which is coming back.
>
>
> Larry S. Brown
> Dimension Networks, Inc.
> (727) 723-8388
>



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Re: PHP and MySQL bug

2003-01-06 Thread Nuno Lopes
I done a echo of Mysql_error and it returned:
'Nenhum banco de dados foi selecionado'

(I have the mysql server in portuguese, but the translation is something
like 'no db was selected')


- Original Message -
From: "David Freeman" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Sunday, January 05, 2003 10:29 PM
Subject: RE: [PHP] Re: PHP and MySQL bug


>
>  > @MYSQL_QUERY("UPDATE d SET h='$h' WHERE id='$id'"); // this
>  > query doesn't work
>
> Personally, I'd call it bad programming practice to do a database update
> and not check to see if it worked or not.  In this case, how are you
> determining that the query did not work?  Are you manually checking the
> database?  You don't have anything in your code to check the status of
> this query.
>
> Perhaps this might get you somewhere:
>
> $qid = @mysql_query("UPDATE d SET h = '$h' WHERE id = '$id'");
>
> if (isset($qid) && mysql_affected_rows() == 1)
> {
>   echo "query executed";
> } else {
>   echo "query failed: " . mysql_error();
> }
>
> At least this way you might get some indication of where the problem is.
>
> CYA, Dave



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] Re: PHP and MySQL bug

2003-01-05 Thread David Freeman

 > @MYSQL_QUERY("UPDATE d SET h='$h' WHERE id='$id'"); // this
 > query doesn't work

Personally, I'd call it bad programming practice to do a database update
and not check to see if it worked or not.  In this case, how are you
determining that the query did not work?  Are you manually checking the
database?  You don't have anything in your code to check the status of
this query.

Perhaps this might get you somewhere:

$qid = @mysql_query("UPDATE d SET h = '$h' WHERE id = '$id'");

if (isset($qid) && mysql_affected_rows() == 1)
{
  echo "query executed";
} else {
  echo "query failed: " . mysql_error();
}

At least this way you might get some indication of where the problem is.

CYA, Dave




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] Re: PHP and MySQL bug

2003-01-05 Thread Nuno Lopes
Here is the source code:

Seleccione a localização para o download:Localização Principal";
if ($mirrors) {
echo " Mirrors";
$m=explode("»",$mirrors);
foreach ($m as $v) {
$m2=explode("!",$v);
echo "$m2[0]";
}
echo "Nota: Deve escolher o mirror mais próximo da sua localização,
para acelerar o dowload. No caso de um mirror estar indisponível, utilize
outro.";
}
}
@MYSQL_CLOSE();
?>



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Re: PHP and MySQL bug

2003-01-04 Thread Michael J. Pawlowsky

Personally I think the problem lies somewhere between the chair and the keyboard

(Sorry, couldn't resist)  :-)



*** REPLY SEPARATOR  ***

On 04/01/2003 at 4:58 PM Stefan Hinz, iConnect (Berlin) wrote:

>It doesn't work because of the /* Some code including ... */ part ;-)
>




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] Re: PHP and MySQL bug

2003-01-04 Thread Stefan Hinz, iConnect \(Berlin\)
Nuno,

> $r=MYSQL_QUERY("SELECT n,u,m,h FROM d WHERE id='$id'");
>
> /* Some code including "mysql_num_rows" and "mysql_fetch_array($r,
> MYSQL_NUM)"
> And the another query:
> */
>
> MYSQL_QUERY("UPDATE d SET h='$h' WHERE id='$id'");
>
> /* i don't know why but this doesn't work!*/

It doesn't work because of the /* Some code including ... */ part ;-)

First thing, I would check if $h and $id really are what you expect them
to be, like:

$sql = "UPDATE d SET h='$h' WHERE id='$id'";
echo $sql;
MYSQL_QUERY($sql);

If this part is okay, then the problem lies within this myterious /*
Some code */.

Regards,
--
  Stefan Hinz <[EMAIL PROTECTED]>
  Geschäftsführer / CEO iConnect GmbH 
  Heesestr. 6, 12169 Berlin (Germany)
  Tel: +49 30 7970948-0  Fax: +49 30 7970948-3

- Original Message -
From: "Nuno Lopes" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
Sent: Saturday, January 04, 2003 11:46 AM
Subject: PHP and MySQL bug


> Dear Sirs,
>
> I'm using PHP and MySQL to make my programs. But I think I discovered
a bug
> in PHP or in MySQL (I don't know!).
>
> In one of my files I have the following:
>
> MYSQL_CONNECT("localhost", "**user**", "**pass**");
> mysql_select_db("be");
> $r=MYSQL_QUERY("SELECT n,u,m,h FROM d WHERE id='$id'");
>
> /* Some code including "mysql_num_rows" and "mysql_fetch_array($r,
> MYSQL_NUM)"
> And the another query:
> */
>
> MYSQL_QUERY("UPDATE d SET h='$h' WHERE id='$id'");
>
> /* i don't know why but this doesn't work! But if I close the
connection and
> open another te query is done:*/
>
> MYSQL_CLOSE();
> MYSQL_CONNECT("localhost", "**user**", "**pass**");
> mysql_select_db("be");
> MYSQL_QUERY("UPDATE d SET h='$h' WHERE id='$id'");
>
> ---
> I don't know why is this? Because I'm used to do more than a query per
> connection and this never happened!
> I'm using Win 2k, Apache 2.0.43, MySQL 3.23.49-nt and PHP 4.3.
>
>
> I hope you solve this,
> Nuno Lopes
>
>
>
> -
> Before posting, please check:
>http://www.mysql.com/manual.php   (the manual)
>http://lists.mysql.com/   (the list archive)
>
> To request this thread, e-mail <[EMAIL PROTECTED]>
> To unsubscribe, e-mail
<[EMAIL PROTECTED]>
> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
>


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Re: PHP and MySQL bug

2003-01-04 Thread Michael J. Pawlowsky

Personally I say get yourself a good simple dbconnect class and make life easy.
Also if you ever change users, database name etc, you onlu have one place to replace 
it in your code.

I wrote mine based on http://www.vtwebwizard.com/tutorials/mysql/

Take a look at it.  Nice and simple.


Mike



*** REPLY SEPARATOR  ***

On 04/01/2003 at 1:09 PM OrangeHairedBoy wrote:

>You really should be using a $link variable...it's good habit:
>
>$link = mysql_connect(...);
>mysql_select_db( "mydb" , $link);
>$query = mysql_query( "select..." , $link );
>$result = mysql_fetch_array($query);




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] Re: PHP and MySQL bug

2003-01-04 Thread OrangeHairedBoy
You really should be using a $link variable...it's good habit:

$link = mysql_connect(...);
mysql_select_db( "mydb" , $link);
$query = mysql_query( "select..." , $link );
$result = mysql_fetch_array($query);

Lewis

"Nuno Lopes" <[EMAIL PROTECTED]> wrote in message
003a01c2b3de$95004650$0100a8c0@pc07653">news:003a01c2b3de$95004650$0100a8c0@pc07653...
> Dear Sirs,
>
> I'm using PHP and MySQL to make my programs. But I think I discovered a
bug
> in PHP or in MySQL (I don't know!).
>
> In one of my files I have the following:
>
> MYSQL_CONNECT("localhost", "**user**", "**pass**");
> mysql_select_db("be");
> $r=MYSQL_QUERY("SELECT n,u,m,h FROM d WHERE id='$id'");
>
> /* Some code including "mysql_num_rows" and "mysql_fetch_array($r,
> MYSQL_NUM)"
> And the another query:
> */
>
> MYSQL_QUERY("UPDATE d SET h='$h' WHERE id='$id'");
>
> /* i don't know why but this doesn't work! But if I close the connection
and
> open another te query is done:*/
>
> MYSQL_CLOSE();
> MYSQL_CONNECT("localhost", "**user**", "**pass**");
> mysql_select_db("be");
> MYSQL_QUERY("UPDATE d SET h='$h' WHERE id='$id'");
>
> ---
> I don't know why is this? Because I'm used to do more than a query per
> connection and this never happened!
> I'm using Win 2k, Apache 2.0.43, MySQL 3.23.49-nt and PHP 4.3.
>
>
> I hope you solve this,
> Nuno Lopes
>
>



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] Re: PHP and MySQL

2002-08-02 Thread Monty

Indexes

Putting strings in single quotes instead of double (WHERE id = 'something')

Normalized database design.

- Monty

> From: [EMAIL PROTECTED] (Erich Kolb)
> Organization: R&B Receivables Management, Inc.
> Reply-To: "Erich Kolb" <[EMAIL PROTECTED]>
> Newsgroups: php.general
> Date: Fri, 2 Aug 2002 15:13:24 -0500
> To: [EMAIL PROTECTED]
> Subject: PHP and MySQL
> 
> Is there any way to speed up MySQL queries?
> 
> 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] Re: PHP and mySQL

2002-05-14 Thread Hugh Bothwell


"City Colleges Of Chicago - Mannheim" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> if there is a booktitle and a quantity chosen, then go to that booktitle
and
> adjust the quantity in the database.


 0) {
$query =
"UPDATE Book2"
." SET stock=(stock-".(int)$quantity.")"
." WHERE bookID=".(int)$bookID
." AND stock >=".(int)$quantity;
$result = mysql_query($query, $link);

if (mysql_affected_rows($link) == 1)
echo "Your order has been placed.";
else
echo "There was an error in placing the order.";
}
}
else {
echo "Your order has not been placed.";
}
?>


NOTE:
1.  We work with a unique book-id, not a book title;
this is (a) faster for the database and (b) eliminates
problems dealing with several books of the same
name (ie multiple editions, hard-cover/soft-cover/trade,
etc).
2.  We add quantity-checking to the query - before an
order is placed, we ensure there are sufficient books
on hand.  Because this is done as a single operation,
we don't have to worry about transaction-safety.
3.  When composing the query, all values are cast to int,
foiling would-be hack attempts.



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] Re: PHP and mySQL

2002-05-14 Thread David Robley

In article <[EMAIL PROTECTED]>, 
[EMAIL PROTECTED] says...
> I am getting a parse error on line 75. I am trying to say:
> 
> if there is a booktitle and a quantity chosen, then go to that booktitle and
> adjust the quantity in the database.
> 
> Thanks!
> Renee
> 
> 
>   $user = "adminer";
>  $pass = "hoosiers";
>  $db = "Book Store1";
>  $local = "jolinux";
>  $link = mysql_connect( "$local", $user, $pass   );
>  if (! $link )
>die ( "Couldn't open the database" );
>  mysql_select_db( $db, $link )
>  or die ( "Couldn't open the $db: ".mysql_error() );
> 
>  if ($submit){
>  if( $booktitle, "quantity" ){
> $sql = "UPDATE Book2 SET stock ='$stock-quantity' WHERE booktitle=$booktitle
> AND quantity=quantity";
>  }
> // $result = mysql_query($mysql);
>  }else if(!$submit){
>   echo "Your order has not been placed.";
>  }
>  ?>
> 
> 

There don't seem to be 75 lines there? But I think you _might_ be missing 
a closing }

I suspect you will then encounter problems with your SQL: you might want 
to add  mysql_error() after your update call, and ensure that the variable 
you are using as your sql query is the variable you have assigned the sql 
query to :-)

-- 
David Robley
Temporary Kiwi!

Quod subigo farinam

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] Re: PHP and mySQL

2002-05-13 Thread John Holmes

Why can't you use one query?

UPDATE Book2 SET stock = stock - $quantity WHERE stock >= $quantity AND
booktitle = '$booktitle'

---John Holmes...

> -Original Message-
> From: Matthew Ward [mailto:[EMAIL PROTECTED]]
> Sent: Monday, May 13, 2002 11:52 AM
> To: [EMAIL PROTECTED]
> Subject: [PHP] Re: PHP and mySQL
> 
> I presume that "quantity" is the number of books that the person has
> ordered, and therefore it needs to be a variable (ie with a $ infront
of
> it)
> and its also best to do the calculation outside of the SQL statement
just
> to
> be sure it works, eg:
> 
> if ($submit){
>if(isset($booktitle) && isset($quantity)){
>   $retrievestock = mysql_query("SELECT stock FROM Book2 WHERE
> booktitle
> = '$booktitle'");
>   while($getstock = mysql_fetch_array($retrievestock)) {
>  $stockamount = $getstock[stock];
>   }
> 
>   $newamount = $stockamount - $quantity;
> 
>   $sql = mysql_query("UPDATE Book2 SET stock = '$newamount' WHERE
> booktitle= '$booktitle'");
>   if(! $sql) { print("Could not update stock amount.");
> } elseif(! $submit) {
>print("Your order has not been placed.");
> }
> 
> 
> "City Colleges Of Chicago - Mannheim" <[EMAIL PROTECTED]> wrote in
> message
> [EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> > I am a student working on a practicum problem. I have a mySQL
database
> that
> > contains the books, their title, and how many are in stock.  When a
> person
> > orders one of the books, I want the stock to be adjusted by how
many,
> > quantity, that they chose when the submit button is clicked.  The
> scripts
> > are written in PHP.
> > Here is part of my code:
> > The book you are ordering:
> >
> >  > echo " $booktitle ";
> >  ?>
> >
> > Additional Message:
> >  
> > 
> > 
> > 
> > 
> >
> >  >  $user = "adminer";
> >  $pass = "hoosiers";
> >  $db = "Book Store1";
> >  $local = "jolinux";
> >  $link = mysql_connect( "$local", $user, $pass   );
> >  if (! $link )
> >die ( "Couldn't open the database" );
> >  mysql_select_db( $db, $link )
> >  or die ( "Couldn't open the $db: ".mysql_error() );
> >
> >  if ($submit){
> >  if( $booktitle, 'quantity' ){
> > $sql = "UPDATE Book2 SET stock ='$stock-quantity' WHERE
> booktitle=$booktitle
> > AND quantity=quantity";
> >  }
> > // $result = mysql_query($mysql);
> >  }else if(!$submit){
> >   echo "Your order has not been placed.";
> >  }
> >  ?>
> > 
> > 
> >
> >
> 
> 
> 
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] Re: PHP and mySQL

2002-05-13 Thread Matthew Ward

I presume that "quantity" is the number of books that the person has
ordered, and therefore it needs to be a variable (ie with a $ infront of it)
and its also best to do the calculation outside of the SQL statement just to
be sure it works, eg:

if ($submit){
   if(isset($booktitle) && isset($quantity)){
  $retrievestock = mysql_query("SELECT stock FROM Book2 WHERE booktitle
= '$booktitle'");
  while($getstock = mysql_fetch_array($retrievestock)) {
 $stockamount = $getstock[stock];
  }

  $newamount = $stockamount - $quantity;

  $sql = mysql_query("UPDATE Book2 SET stock = '$newamount' WHERE
booktitle= '$booktitle'");
  if(! $sql) { print("Could not update stock amount.");
} elseif(! $submit) {
   print("Your order has not been placed.");
}


"City Colleges Of Chicago - Mannheim" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> I am a student working on a practicum problem. I have a mySQL database
that
> contains the books, their title, and how many are in stock.  When a person
> orders one of the books, I want the stock to be adjusted by how many,
> quantity, that they chose when the submit button is clicked.  The scripts
> are written in PHP.
> Here is part of my code:
> The book you are ordering:
>
>  echo " $booktitle ";
>  ?>
>
> Additional Message:
>  
> 
> 
> 
> 
>
>   $user = "adminer";
>  $pass = "hoosiers";
>  $db = "Book Store1";
>  $local = "jolinux";
>  $link = mysql_connect( "$local", $user, $pass   );
>  if (! $link )
>die ( "Couldn't open the database" );
>  mysql_select_db( $db, $link )
>  or die ( "Couldn't open the $db: ".mysql_error() );
>
>  if ($submit){
>  if( $booktitle, 'quantity' ){
> $sql = "UPDATE Book2 SET stock ='$stock-quantity' WHERE
booktitle=$booktitle
> AND quantity=quantity";
>  }
> // $result = mysql_query($mysql);
>  }else if(!$submit){
>   echo "Your order has not been placed.";
>  }
>  ?>
> 
> 
>
>



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] Re: PHP and mySQL

2002-03-05 Thread Dan Vande More

Max,
PHP.net says:

"Calls to mysql_result() should not be mixed with calls to other functions
that deal with the result set. "

I would use mysql_fetch_array which they say is MUCH faster, example of how
you could use it:


username='me' GROUP BY username";

$number_of_rows=mysql_num_rows($sqlinfo)
if($number_of_rows != '0')
{
while ($row = mysql_fetch_array($sqlinfo)) 
{
 echo "count: ".$row["count"]."\n";
 echo "username: ".$row["username"]."\n";
}
}
mysql_free_result($result);
?>


-Original Message-
From: David Robley [mailto:[EMAIL PROTECTED]] 
Sent: Tuesday, March 05, 2002 8:29 PM
To: [EMAIL PROTECTED]
Subject: [PHP] Re: PHP and mySQL

In article <180f01c1c403$2ac62820$[EMAIL PROTECTED]>, 
[EMAIL PROTECTED] says...
> I have a little problem when trying to count the number of results
returned
> in a mysql query. I was using mysql_num_rows() to do it with no problems,
> but this isn't as quick as using mySQL's COUNT(*), or so I have been told
so
> I swtiched. Here's a snipit of the code...
> 
> $sqlinfo = "SELECT username, COUNT(username) as count FROM usertable WHERE
> username='me' GROUP BY username";
> $sqlresult = mysql_query($sqlinfo)
>   or die(mysql_error());
> 
> $count = mysql_result($sqlresult,0,"count");
> 
> if ($count <= 0) {
>   FAILED
> } else {
>   while ($row = mysql_fetch_array($sqlresult)) {
> $username = $row['username'];
>   }
> }
> 
> The count value is set correctly but:  when the while() loop is
> executed...no values are set (there are a lot more, but I shortened it for
> spaces sake). So, $username is null. If I remove the $count line, it
> worksany suggestions?
> 
> Max

Assuming that your username is unique, I would expect that you would only 
get one row returned from that query? In which case much of your SQL is 
redundant.

Anyhow, your $count line reads the first row of the result, then sets the 
pointer to the next row in the result set - if this is empty (ie only one 
row retrieved) then you will get a null result for your while loop as 
there are no more results to display. Try using mysql_data_seek to return 
the pointer to row 0 before your while loop.


-- 
David Robley
Temporary Kiwi!

Quod subigo farinam

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] Re: PHP and mySQL

2002-03-05 Thread David Robley

In article <180f01c1c403$2ac62820$[EMAIL PROTECTED]>, 
[EMAIL PROTECTED] says...
> I have a little problem when trying to count the number of results returned
> in a mysql query. I was using mysql_num_rows() to do it with no problems,
> but this isn't as quick as using mySQL's COUNT(*), or so I have been told so
> I swtiched. Here's a snipit of the code...
> 
> $sqlinfo = "SELECT username, COUNT(username) as count FROM usertable WHERE
> username='me' GROUP BY username";
> $sqlresult = mysql_query($sqlinfo)
>   or die(mysql_error());
> 
> $count = mysql_result($sqlresult,0,"count");
> 
> if ($count <= 0) {
>   FAILED
> } else {
>   while ($row = mysql_fetch_array($sqlresult)) {
> $username = $row['username'];
>   }
> }
> 
> The count value is set correctly but:  when the while() loop is
> executed...no values are set (there are a lot more, but I shortened it for
> spaces sake). So, $username is null. If I remove the $count line, it
> worksany suggestions?
> 
> Max

Assuming that your username is unique, I would expect that you would only 
get one row returned from that query? In which case much of your SQL is 
redundant.

Anyhow, your $count line reads the first row of the result, then sets the 
pointer to the next row in the result set - if this is empty (ie only one 
row retrieved) then you will get a null result for your while loop as 
there are no more results to display. Try using mysql_data_seek to return 
the pointer to row 0 before your while loop.


-- 
David Robley
Temporary Kiwi!

Quod subigo farinam

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] Re: PHP and mySQL

2002-01-17 Thread Gary

that is nix command. On window you need to start MySQL one of two ways.
http://www.mysql.com/doc/W/i/Windows.html

HTH
Gary

Morten Nielsen wrote:

> Hi,
> 
> I try to use mySQL through PHP, but I can't get it to work.
> Both PHP and mySQL is installed on my computer (win2k). The PHP manual says
> I should run php.exe --with-mysql. But I can't figure out what that means.
> I am using a graphical development environment for PHP, where I have told
> where my php.exe file is located, but when I add the --with-mysql nothing
> happens.
> 
> Please help
> 
> Thanks,
> Morten
> 
> 
> 


-- 
PHP General 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]




[PHP] Re: PHP and MySQL

2001-09-10 Thread Pieter Philippaerts

We have never used mysql_pconnect.

Regards,
Pieter Philippaerts

"Stefan De Wal" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> check your connection string and if it something like mysql_pconnect
change
> it in mysql_connect
>
> Stefan de Wal



-- 
PHP General 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]




[PHP] Re: PHP and MySQL

2001-09-10 Thread Stefan de Wal

check your connection string and if it something like mysql_pconnect change
it in mysql_connect

Stefan de Wal

"Pieter Philippaerts" <[EMAIL PROTECTED]> schreef in bericht
([EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> Unfortunately, I can't access these settings. It's not our computer that
> hosts
> our website.
>
> Regards,
> Pieter Philippaerts
>
> "Richard Lynch" <[EMAIL PROTECTED]> wrote in message
> 01e501c138ce$f3008300$6401a8c0@Lynchux100">news:01e501c138ce$f3008300$6401a8c0@Lynchux100...
> > Options:
> > Increase the settings in MySQL that limit how many databases can be open
> at
> > once.
> > Decrease the number of Apache children running.
> >
> > Basically, as long as you have more Apache children than MySQL
connections
> > available, you can get this message.
> >
> > Actually, have a few spare MySQL connections, so you can telnet/SSH in
and
> > use the monitor as well, and cron jobs using MySQL can run.
> >
> > --
> > WARNING [EMAIL PROTECTED] address is an endangered species -- Use
> > [EMAIL PROTECTED]
> > Wanna help me out?  Like Music?  Buy a CD: http://l-i-e.com/artists.htm
> > Volunteer a little time: http://chatmusic.com/volunteer.htm
> > - Original Message -
> > From: Pieter Philippaerts <[EMAIL PROTECTED]>
> > Newsgroups: php.general
> > To: <[EMAIL PROTECTED]>
> > Sent: Friday, September 07, 2001 11:30 PM
> > Subject: PHP and MySQL
> >
> >
> > > Hello,
> > > we're using our MySQL database quite extensively from our PHP scripts,
> > > but sometimes everything stops working and it says "Too many
> connections".
> > > Is there a problem with MySQL support from within PHP? Doesn't it
close
> > > its connections with the database when the script stops executing?
> > > Is there anything I can do to resolve this problem?
> > >
> > > Regards,
> > > Pieter Philippaerts
> > >
> > >
> >
>
>



-- 
PHP General 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]




[PHP] Re: PHP and MySQL

2001-09-08 Thread Pieter Philippaerts

Unfortunately, I can't access these settings. It's not our computer that
hosts
our website.

Regards,
Pieter Philippaerts

"Richard Lynch" <[EMAIL PROTECTED]> wrote in message
01e501c138ce$f3008300$6401a8c0@Lynchux100">news:01e501c138ce$f3008300$6401a8c0@Lynchux100...
> Options:
> Increase the settings in MySQL that limit how many databases can be open
at
> once.
> Decrease the number of Apache children running.
>
> Basically, as long as you have more Apache children than MySQL connections
> available, you can get this message.
>
> Actually, have a few spare MySQL connections, so you can telnet/SSH in and
> use the monitor as well, and cron jobs using MySQL can run.
>
> --
> WARNING [EMAIL PROTECTED] address is an endangered species -- Use
> [EMAIL PROTECTED]
> Wanna help me out?  Like Music?  Buy a CD: http://l-i-e.com/artists.htm
> Volunteer a little time: http://chatmusic.com/volunteer.htm
> - Original Message -
> From: Pieter Philippaerts <[EMAIL PROTECTED]>
> Newsgroups: php.general
> To: <[EMAIL PROTECTED]>
> Sent: Friday, September 07, 2001 11:30 PM
> Subject: PHP and MySQL
>
>
> > Hello,
> > we're using our MySQL database quite extensively from our PHP scripts,
> > but sometimes everything stops working and it says "Too many
connections".
> > Is there a problem with MySQL support from within PHP? Doesn't it close
> > its connections with the database when the script stops executing?
> > Is there anything I can do to resolve this problem?
> >
> > Regards,
> > Pieter Philippaerts
> >
> >
>



-- 
PHP General 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]




[PHP] Re: PHP and MySQL

2001-09-08 Thread Richard Lynch

Options:
Increase the settings in MySQL that limit how many databases can be open at
once.
Decrease the number of Apache children running.

Basically, as long as you have more Apache children than MySQL connections
available, you can get this message.

Actually, have a few spare MySQL connections, so you can telnet/SSH in and
use the monitor as well, and cron jobs using MySQL can run.

--
WARNING [EMAIL PROTECTED] address is an endangered species -- Use
[EMAIL PROTECTED]
Wanna help me out?  Like Music?  Buy a CD: http://l-i-e.com/artists.htm
Volunteer a little time: http://chatmusic.com/volunteer.htm
- Original Message -
From: Pieter Philippaerts <[EMAIL PROTECTED]>
Newsgroups: php.general
To: <[EMAIL PROTECTED]>
Sent: Friday, September 07, 2001 11:30 PM
Subject: PHP and MySQL


> Hello,
> we're using our MySQL database quite extensively from our PHP scripts,
> but sometimes everything stops working and it says "Too many connections".
> Is there a problem with MySQL support from within PHP? Doesn't it close
> its connections with the database when the script stops executing?
> Is there anything I can do to resolve this problem?
>
> Regards,
> Pieter Philippaerts
>
>


-- 
PHP General 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]




[PHP] Re: PHP and Mysql

2001-09-05 Thread Ron Wills

Aloysius wrote:

> my mysql database just won't work .. i think i have configured it correctly cause i 
>can see  a page but the codes are messed up ..
> i can confirm that the servers supports php . both php and php3 extension because 
>i've tried uploading simple codes and it appears correctly ...
>

You might want to recheck your server. The php is definitaly not being parced, I 
should not be able to see any of the php code within the HTML. A
simple test would be to create a file like test.php with a single line
. This should display everything about your php interpreter, if php is 
not running only that line will be displayed in your browser.
I hopes this helps locate your problem

>
> can anyone help ? thanks
>
> the link is
> http://www.arkman.f2s.com/database/index.php
>
> aloysius

--
Ron Wills
DMS Control Programmer
[EMAIL PROTECTED]




-- 
PHP General 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]