RE: [PHP] Inserting records in a particular way in MySQL
Phillip, You will have to change your code, so the primary key is not an auto incremented value. If you don't, the auto increment will over-ride the 'get next' function. Here is what I use in my code. You just need to change it for your table. //- GetNextKey -// function getnextkey(){ $db = new db(); $query = select max(MemberKey) lastkey from Members; $result=exequery($query); if(@mysql_num_rows($result) 0){ $numrows=mysql_num_rows($result); $flds=mysql_num_fields($result); //Should only be one row, but just in case for($r=0; $r $numrows; $r++){ $row=mysql_fetch_array($result); $lastkey = StripSlashes($row[lastkey]); } } else { return 1; } if (is_numeric($lastkey)) { return $lastkey+1; } else { return 1; } $db-closedb(); } -Original Message- From: Phillip S. Baker [mailto:[EMAIL PROTECTED]] Sent: Sunday, February 16, 2003 12:37 PM To: PHP Email List Subject: [PHP] Inserting records in a particular way in MySQL Greetings all, I have some PHP code that is inserting records into a DB. Most of this is auto increment. However I know there is allot of breaks in the sequencing. I am wondering if there is some way to write the SQL code to search through the existing records in the DB and to find where the next available ID is instead of just inserting the next sequence. So for example if the ID's are. 20453 20454 20458 20459 It would let me know that 20455 is available for use and use the ID number instead of using 20460 Thanks all. Phillip +++ IMPORTANT: This email message (including attachments, if any) is intended for the use of the individual addressee(s) named above and may contain information that is confidential, privileged or unsuitable for overly sensitive persons with low self-esteem, no sense of humor or irrational religious beliefs. If you are not the intended recipient, any dissemination, distribution or copying of this email is not authorized (either explicitly or implicitly) and constitutes an irritating social faux pas. Unless the word absquatulation has been used in its correct context somewhere other than in this warning, it does not have any legal or no grammatical use and may be ignored. No animals were harmed in the transmission of this email, although the barking dachshund next door is living on borrowed time, let me tell you. Those of you with an overwhelming fear of the unknown will be gratified to learn that there is no hidden message revealed by reading this warning backwards, so just ignore that Alert Notice from Microsoft. However, by pouring a complete circle of salt around yourself and your computer you can ensure that no harm befalls you, your family or your pets. If you have received this email in error, please add some nutmeg and egg whites, whisk and place in a warm oven for 40 minutes. +++ -- 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
RE: [PHP] Inserting records in a particular way in MySQL
Miles, I never use auto increment. Not because of gaps, but in case I need to reload the table. They do have meaning if they are foreign keys to another table. - Larry -Original Message- From: Miles Thompson [mailto:[EMAIL PROTECTED]] Sent: Sunday, February 16, 2003 1:14 PM To: Phillip S. Baker; PHP Email List Subject: Re: [PHP] Inserting records in a particular way in MySQL Phillip, It doesn't matter, obviously you're not using the autoincrement ID for a foreign key. All this does is identify a record. If you did a SELECT and found a missing sequence number, what's to say that value would not be inserted by another user before your INSERT? If you have not set up the table with a MyISAM, MySQL will eventually use the missing numbers. These are only identifying tags, with no intrinsic meaning. Miles At 09:37 AM 2/16/2003 -0800, Phillip S. Baker wrote: Greetings all, I have some PHP code that is inserting records into a DB. Most of this is auto increment. However I know there is allot of breaks in the sequencing. I am wondering if there is some way to write the SQL code to search through the existing records in the DB and to find where the next available ID is instead of just inserting the next sequence. So for example if the ID's are. 20453 20454 20458 20459 It would let me know that 20455 is available for use and use the ID number instead of using 20460 Thanks all. Phillip snip overly long sig -- 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 General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Re: SQL Query
Zydox, Please define 'sub-interest'. I've looked at what Uttam gave you, and it looks correct, assuming you want want it limited to the same user. If you result should be 'all with Interest = X and Valid = Y, just remove the userid from the second query. SELECT InterestsList.ID, InterestsList.SubID, InterestsList.Interest, InterestsList.Valid FROM InterestsIndex INNER JOIN InterestList ON InterestIndex.InterestID=InterestList.ID WHERE InterestList.SubID='3' AND InterestList.Valid='1' - Larry -Original Message- From: Zydox [mailto:[EMAIL PROTECTED]] Sent: Saturday, February 15, 2003 7:58 AM To: [EMAIL PROTECTED] Subject: [PHP] Re: SQL Query Those querys work... but they don't get all the Sub Interests... Uttam [EMAIL PROTECTED] wrote in message 97FB62E1E350D511B71F00A0C99D0CC30352D563@MSEXCHANGE">news:97FB62E1E350D511B71F00A0C99D0CC30352D563@MSEXCHANGE... if i understand you correctly then this should give valid interests of a user: SELECT DISTINCT InterestsList.SubID FROM InterestsIndex INNER JOIN InterestList ON InterestIndex.InterestID=InterestList.ID WHERE InterestIndex.UserID='1' AND InterestList.Valid='1' and if the chosen interest is '3' then valid subinterests are: SELECT InterestsList.ID, InterestsList.SubID, InterestsList.Interest, InterestsList.Valid FROM InterestsIndex INNER JOIN InterestList ON InterestIndex.InterestID=InterestList.ID WHERE InterestIndex.UserID='1' AND InterestList.SubID='3' AND InterestList.Valid='1' regds, -Original Message- From: Zydox [mailto:[EMAIL PROTECTED]] Sent: Saturday, February 15, 2003 09:48 To: [EMAIL PROTECTED] Subject: SQL Query I have a problem writing a query that can select a Interest for a specific user... There are tvo tables, IList and IIndex... IList contains this : ID SubID Interest Valid Edit Delete 1 0 Datorer 0 Edit Delete 2 1 Spel 0 Edit Delete 3 2 Strategi 0 Edit Delete 4 3 Star Craft 1 Edit Delete 5 3 Star Wars: Gallactic Battelinggrounds 1 Edit Delete 6 2 Shoot-Em-Up 0 Edit Delete 7 6 Half-Life 0 Edit Delete 8 7 Team Fortress 1 Edit Delete 9 7 Counter-Strike 1 And IIndex contains a UserID And InterestID... this query : SELECT DISTINCTROW InterestsList.ID, InterestsList.SubID, InterestsList.Interest, InterestsList.Valid FROM InterestsList AS II RIGHT JOIN InterestsList ON InterestsList.ID=II.SubID LEFT JOIN InterestsIndex ON InterestsList.ID=InterestsIndex.InterestID AND InterestsIndex.UserID='1' Selects all rows from IList... even if there Is'nt any instans in IIndex.. . this thougt is that a User can choose a Valid Interest and then the query should select all SubInterests... anyone know how to do that ? // Regards Zydox -- 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
RE: [PHP] Re: SQL Query
Zydox, Your request does not make sense. There must be other fields you want to link, because if we go back you your original data, these records are unrelated. The 'SubID' of Star Craft and Star Wars match. The 'Valid' of Star Craft, Star Wars, Team Fortress, and Counter-Strike match. Datorer and Strategi have nothing in common with the other items in your list, or each other. Unless you have another table or additional field that have not been provided in this thread, you have no way to relate those elements to each other. Below is your original data provided: ID SubID Interest Valid 1 0 Datorer 0 2 1 Spel 0 3 2 Strategi 0 4 3 Star Craft 1 5 3 Star Wars: Gallactic Battelinggrounds 1 6 2 Shoot-Em-Up 0 7 6 Half-Life 0 8 7 Team Fortress 1 9 7 Counter-Strike 1 - Larry -Original Message- From: Zydox [mailto:[EMAIL PROTECTED]] Sent: Saturday, February 15, 2003 11:01 AM To: [EMAIL PROTECTED] Subject: Re: [PHP] Re: SQL Query The result recived from that query is this ID SubID Interest Valid Edit Delete 4 3 Star Craft 1 But I want a Query that retrives Star Craft, Strategi, Spel and Datorer... :/ Willie G [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... Zydox, Please define 'sub-interest'. I've looked at what Uttam gave you, and it looks correct, assuming you want want it limited to the same user. If you result should be 'all with Interest = X and Valid = Y, just remove the userid from the second query. SELECT InterestsList.ID, InterestsList.SubID, InterestsList.Interest, InterestsList.Valid FROM InterestsIndex INNER JOIN InterestList ON InterestIndex.InterestID=InterestList.ID WHERE InterestList.SubID='3' AND InterestList.Valid='1' - Larry -Original Message- From: Zydox [mailto:[EMAIL PROTECTED]] Sent: Saturday, February 15, 2003 7:58 AM To: [EMAIL PROTECTED] Subject: [PHP] Re: SQL Query Those querys work... but they don't get all the Sub Interests... Uttam [EMAIL PROTECTED] wrote in message 97FB62E1E350D511B71F00A0C99D0CC30352D563@MSEXCHANGE">news:97FB62E1E350D511B71F00A0C99D0CC30352D563@MSEXCHANGE... if i understand you correctly then this should give valid interests of a user: SELECT DISTINCT InterestsList.SubID FROM InterestsIndex INNER JOIN InterestList ON InterestIndex.InterestID=InterestList.ID WHERE InterestIndex.UserID='1' AND InterestList.Valid='1' and if the chosen interest is '3' then valid subinterests are: SELECT InterestsList.ID, InterestsList.SubID, InterestsList.Interest, InterestsList.Valid FROM InterestsIndex INNER JOIN InterestList ON InterestIndex.InterestID=InterestList.ID WHERE InterestIndex.UserID='1' AND InterestList.SubID='3' AND InterestList.Valid='1' regds, -Original Message- From: Zydox [mailto:[EMAIL PROTECTED]] Sent: Saturday, February 15, 2003 09:48 To: [EMAIL PROTECTED] Subject: SQL Query I have a problem writing a query that can select a Interest for a specific user... There are tvo tables, IList and IIndex... IList contains this : ID SubID Interest Valid Edit Delete 1 0 Datorer 0 Edit Delete 2 1 Spel 0 Edit Delete 3 2 Strategi 0 Edit Delete 4 3 Star Craft 1 Edit Delete 5 3 Star Wars: Gallactic Battelinggrounds 1 Edit Delete 6 2 Shoot-Em-Up 0 Edit Delete 7 6 Half-Life 0 Edit Delete 8 7 Team Fortress 1 Edit Delete 9 7 Counter-Strike 1 And IIndex contains a UserID And InterestID... this query : SELECT DISTINCTROW InterestsList.ID, InterestsList.SubID, InterestsList.Interest, InterestsList.Valid FROM InterestsList AS II RIGHT JOIN InterestsList ON InterestsList.ID=II.SubID LEFT JOIN InterestsIndex ON InterestsList.ID=InterestsIndex.InterestID AND InterestsIndex.UserID='1' Selects all rows from IList... even if there Is'nt any instans in IIndex.. . this thougt is that a User can choose a Valid Interest and then the query should select all SubInterests... anyone know how to do that ? // Regards Zydox -- 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] SESSION variable to pass login ID
Hi, I have been trying to solve the problem of using session variables, but I have not had any luck. What I want to do is simple, I want to set my userid and password in a login screen and use it later (in another php form) to log into the database. In my login PHP file I have the following: if(isset($_POST['userid']) isset($_POST['pword'])){ $_SESSION['user'] = $_POST['userid']; $_SESSION['password'] = $_POST['pword']; } In my connect to database PHP file I have: if(isset($_SESSION['user'])){ $user=$_SESSION['user']; echo Print $user; }else{ echo Print Missing User; } The message I always get is Print Missing User, so I must assume the global variable is not working. Can anyone help me out here? Thanks, Larry -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] SESSION variable to pass login ID
Tom, I do have a session_start() in both files, but it does not seem to help. - Larry -Original Message- From: Tom Rogers [mailto:[EMAIL PROTECTED]] Sent: Sunday, January 12, 2003 11:36 AM To: Willie G Cc: [EMAIL PROTECTED] Subject: Re: [PHP] SESSION variable to pass login ID Hi, Monday, January 13, 2003, 1:04:49 AM, you wrote: WG Hi, WG I have been trying to solve the problem of using session variables, but I WG have not had any luck. What I want to do is simple, I want to set my userid WG and password in a login screen and use it later (in another php form) to log WG into the database. WG In my login PHP file I have the following: WG if(isset($_POST['userid']) isset($_POST['pword'])){ WG $_SESSION['user'] = $_POST['userid']; WG $_SESSION['password'] = $_POST['pword']; WG } WG In my connect to database PHP file I have: WG if(isset($_SESSION['user'])){ WG $user=$_SESSION['user']; WG echo Print $user; WG }else{ WG echo Print Missing User; WG } WG The message I always get is Print Missing User, so I must assume the WG global variable is not working. Can anyone help me out here? WG Thanks, WG Larry Make sure you have session_start() at the begining of the second file. -- regards, Tom -- 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
RE: [PHP] SESSION variable to pass login ID
Hi, I just found my mistake. I added some debug logic, and found that the $_POST logic was in the calling form, not the called form. As soon as I moved the if(isset($_POST['userid']) isset($_POST['pword'])){ to the second form, everything started to work. Thanks to everyone who responded. - Larry -Original Message- From: Nova [mailto:[EMAIL PROTECTED]] Sent: Sunday, January 12, 2003 3:04 PM To: [EMAIL PROTECTED] Subject: Re: [PHP] SESSION variable to pass login ID This statement doesnt look right to me. if(isset($_POST['userid']) isset($_POST['pword'])){ $_SESSION['user'] = $_POST['userid']; $_SESSION['password'] = $_POST['pword']; } the if should be: if ((statement)(statement)) { } so: if ((isset($_POST['userid'])) (isset($_POST['pword']))) { $_SESSION['user'] = $_POST['userid']; $_SESSION['password'] = $_POST['pword']; } That should work. Willie G [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... Tom, I do have a session_start() in both files, but it does not seem to help. - Larry -Original Message- From: Tom Rogers [mailto:[EMAIL PROTECTED]] Sent: Sunday, January 12, 2003 11:36 AM To: Willie G Cc: [EMAIL PROTECTED] Subject: Re: [PHP] SESSION variable to pass login ID Hi, Monday, January 13, 2003, 1:04:49 AM, you wrote: WG Hi, WG I have been trying to solve the problem of using session variables, but I WG have not had any luck. What I want to do is simple, I want to set my userid WG and password in a login screen and use it later (in another php form) to log WG into the database. WG In my login PHP file I have the following: WG if(isset($_POST['userid']) isset($_POST['pword'])){ WG $_SESSION['user'] = $_POST['userid']; WG $_SESSION['password'] = $_POST['pword']; WG } WG In my connect to database PHP file I have: WG if(isset($_SESSION['user'])){ WG $user=$_SESSION['user']; WG echo Print $user; WG }else{ WG echo Print Missing User; WG } WG The message I always get is Print Missing User, so I must assume the WG global variable is not working. Can anyone help me out here? WG Thanks, WG Larry Make sure you have session_start() at the begining of the second file. -- regards, Tom -- 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 General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php