RE: [PHP-DB] finding ID's

2002-02-17 Thread Howard Picken

Hi Jon

Try using something like 

$getlist = mysql_query(SELECT id FROM yourdb,$dbconnectetc);
$numrows = mysql_num_rows($getlist);
echo $numrows\n;

This will give you the number of records in your db.
If you use autoincrement for the id field your will not have to 
worry about your ++.

If you delete any records numrows will always be correct.

HTH

Howard


First off, sorry for the newbie question... :(.

I want to be able to query the database and find the record with the 
highest ID value. Example... each row ideally has an incremented integer 
ID (1, 2, 3, 4...) but I am running into problems when I try and delete 
a row (let's say row 2). My PHP currently selects all of the rows and 
formulates the ID off of that... This I found out is bad because when I 
delete row 2 the query says there are 3 rows so my PHP will try to make 
the ID = 4. I just need the code to find the highest ID so I can ++ it. 
Sorry again for the easy question!

-Jon Gales
http://www.macmerc.com



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




Re: [PHP-DB] finding ID's

2002-02-17 Thread DL Neil

Hi Jon, and Howard,
(comments interposed, below)

 Try using something like
 $getlist = mysql_query(SELECT id FROM yourdb,$dbconnectetc);
 $numrows = mysql_num_rows($getlist);
 echo $numrows\n;

 This will give you the number of records in your db.
 If you use autoincrement for the id field your will not have to
 worry about your ++.

 If you delete any records numrows will always be correct.

=this is correct, but COUNT(*) is optimised/more efficient (RTFM: 6.3.7  Functions for 
Use with GROUP BY
Clauses)

 
 First off, sorry for the newbie question... :(.

 I want to be able to query the database and find the record with the
 highest ID value. Example... each row ideally has an incremented integer
 ID (1, 2, 3, 4...) but I am running into problems when I try and delete
 a row (let's say row 2). My PHP currently selects all of the rows and
 formulates the ID off of that... This I found out is bad because when I
 delete row 2 the query says there are 3 rows so my PHP will try to make
 the ID = 4. I just need the code to find the highest ID so I can ++ it.
 Sorry again for the easy question!

=no need to apologise, we all have to start somewhere.

=It is an FAQ. By asking it you indicate that you don't (yet) understand the 
philosophy of the AUTO_INCREMENT
facility. It is there to provide an ID for new rows of data, not to be a 'count' of 
the rows. If you consider
that this ID may be used as a key into this table's data from another table (foreign 
key), then you will realise
that changing ID values to reflect intermediate deletions is less than logical. (RTFM: 
3.5.9  Using
AUTO_INCREMENT, although it doesn't seem to get into this point - the annotated 
comments are worth a read
though). I've just a had a quick look to see where the manual discusses the 
'philosophy' and have come up
empty - perhaps someone else can steer you right, if you need more.

=It is worth reading through PHP's large collection of built-in MySQL_ functions. 
There are specific functions
that will return various 'numbers of rows' to the script to suit various situations.

=Regards,
=dn


=Regards,
=dn



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




[PHP-DB] Session End

2002-02-17 Thread Hayan Al Mamoun

Hi,
I want to know if there is a way in PHP to sence that the visitor left the
site, I think the answer is in PHP-Sessions, but I don't know how, Any help
please??

Best Regards
Hayan


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




Re: [PHP-DB] Session End

2002-02-17 Thread Greg Donald

 I want to know if there is a way in PHP to sence that the visitor left the
 site, I think the answer is in PHP-Sessions, but I don't know how, Any
help
 please??

Use cookies.

http://www.php.net/manual/en/features.cookies.php


Greg Donald - http://destiney.com/
http://phprated.com/ | http://phplinks.org/ | http://phptopsites.com/



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




[PHP-DB] Beginner query about mysql...

2002-02-17 Thread michele

I have a table with a ID field 'auto_increment',
  when i insert a record in the table,
  how can i know the value of the ID inserted by the mySQL?
Thank's,
Michele.


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




Re: [PHP-DB] Beginner query about mysql...

2002-02-17 Thread ted

The manual is at http://www.php.net/manual/en

The function you need is mysql_insert_id.

On Mon, 18 Feb 2002, michele wrote:

 I have a table with a ID field 'auto_increment',
   when i insert a record in the table,
   how can i know the value of the ID inserted by the mySQL?
 Thank's,
 Michele.


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




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




RE: [PHP-DB] Session confusion :-(

2002-02-17 Thread Beau Lebens

are you always refreshing the session on each page dave?

i am pretty sure you need to call session_start() on every page that you
will be accessing the session-based variables.

HTH

beau

// -Original Message-
// From: Dave Carrera [mailto:[EMAIL PROTECTED]]
// Sent: Saturday, 16 February 2002 10:56 PM
// To: php List
// Subject: [PHP-DB] Session confusion :-(
// 
// 
// Hi All
// 
// I am send variable values via set links i.e.:
// 
// http://domian_name.com/page.php?category=1
// 
// http://domian_name.com/page.php?category=2
// 
// http://domian_name.com/page.php?category=3
// 
// Etc etc
// 
// The value is sent to a session. THIS WORKS BUT.
// 
// If I click on the first link session variable category is set to 1.
// 
// But if I then click on the send , third, forth or whatever link
// Session variable is still set to 1.
// 
// I have tried
// 
// If(ISSET($category)){
// Unset($category);
// Session_register(category) // hoping it would accept the new 
// sent value.
// }
// 
// No Go
// 
// Can anyone throw some light on this please.
// 
// As Always I am grateful for any pointers or exampled help
// 
// :-)
// 
// Dave Carrera
// Php / MySql Development
// Web Design
// Site Marketing
// http://www.davecarrera.com
//  
// 
// 
// 
// -- 
// PHP Database Mailing List (http://www.php.net/)
// To unsubscribe, visit: http://www.php.net/unsub.php
// 

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




[PHP-DB] HELP: php4.1.1, oci8 functions, Oracle 9i and VARCHAR2 selects not working

2002-02-17 Thread Bradley Goldsmith

Hi All,

I have seen a lot of discussion about this - but no real solutions
:)

I am getting a two task communication error whenever I try to select
a varchar2 element in a query in php4. I seem to be able to select any other
kinds of data without hassle.

All of my environment variables are set correctly, and I have
experimented at length with different NLS_LANG values.

The client machine is Mandrake Linux, running php 4.1.1 with oracle
and oci8 support compiled in. SQL*Net is able to query the remote db server
without any problems at all.

Has *anyone* got any experience with Oracle9i and PHP that might be
able to help? I would rather use MySQL in a heartbeat, but Oracle9i is a
client requirement. 

Cheers,
Brad




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




[PHP-DB] Updating Database at a specified time

2002-02-17 Thread Jennifer Downey

Would someone please help? I have looked everywhere and can not find how to
update a database at a certain time.

I am trying to get this to update at midnight instead of every time the
browser refreshes. My hosting service has cron jobs
but I don't understand how to set them up. Is there a way to set this code
up to do what I need?

?php
global $session;


$db[points]=(UPDATE wt_users set points = points + 1000 WHERE
uid={$session[uid]});
$result=mysql_query($db[points]);

$query=SELECT  points FROM wt_users WHERE uid={$session[uid]};

$ret = mysql_query($query);
while(list($points)=
mysql_fetch_row($ret))


print(SP: $points);


?

Thanks in advance!

Jennifer Downey




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




[PHP-DB] HELP: php4.1.1, oci8 functions, Oracle 9i and VARCHAR2 selects not working

2002-02-17 Thread Bradley Goldsmith

Hi All,

I have seen a lot of discussion about this - but no real solutions
:)

I am getting a two task communication error whenever I try to select
a varchar2 element in a query in php4. I seem to be able to select any other
kinds of data without hassle.

All of my environment variables are set correctly, and I have
experimented at length with different NLS_LANG values.

The client machine is Mandrake Linux, running php 4.1.1 with oracle
and oci8 support compiled in. SQL*Net is able to query the remote db server
without any problems at all.

Has *anyone* got any experience with Oracle9i and PHP that might be
able to help? I would rather use MySQL in a heartbeat, but Oracle9i is a
client requirement. 

Cheers,
Brad




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