[PHP-DB] Hi, simple question
Hi, im adding a post to the database, is there any way to retrive back the ID for the post that i just created? the id is auto_increment and primary key. like $sql = insert into test (namn, www) values('test', 'test.com'); mysql_query($sql); $row = mysql_get_post(id); ? the only way i could think of was to create a tempfield in the database and each time you post you give the temp field a unique value, like: $sql = insert into test (namn, www, unique) values('test', 'test.com','25323324'); mysql_query($sql); $sql = select id from test where unique = '25323324'; $res = mysql_query($sql); regards patrick -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Hi, simple question
see mysql_insert_id($link_identifier) -- rylin Patrik Fomin wrote: Hi, im adding a post to the database, is there any way to retrive back the ID for the post that i just created? the id is auto_increment and primary key. like $sql = insert into test (namn, www) values('test', 'test.com'); mysql_query($sql); $row = mysql_get_post(id); ? the only way i could think of was to create a tempfield in the database and each time you post you give the temp field a unique value, like: $sql = insert into test (namn, www, unique) values('test', 'test.com','25323324'); mysql_query($sql); $sql = select id from test where unique = '25323324'; $res = mysql_query($sql); regards patrick -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] Hi, simple question
There's two methods I use, depending on the situations I need. What it sounds like you want is this: $sql = SELECT id FROM test ORDER BY id DESC LIMIT 1; Often when I need to know the next avaliable ID prior to making an insert, I'll do this-- $sql =SHOW TABLE STATUS LIKE 'test'; $array = $this-sql-getRow($sql); echo $array['Auto_increment']; Either way will get you a number you can work with, the first gets you the last inserted number and the second way gets you the number of what the next entry will be. --Nick Pappas -Original Message- From: Patrik Fomin [mailto:[EMAIL PROTECTED] Sent: Tuesday, July 01, 2003 9:04 PM To: [EMAIL PROTECTED] Subject: [PHP-DB] Hi, simple question Hi, im adding a post to the database, is there any way to retrive back the ID for the post that i just created? the id is auto_increment and primary key. like $sql = insert into test (namn, www) values('test', 'test.com'); mysql_query($sql); $row = mysql_get_post(id); ? the only way i could think of was to create a tempfield in the database and each time you post you give the temp field a unique value, like: $sql = insert into test (namn, www, unique) values('test', 'test.com','25323324'); mysql_query($sql); $sql = select id from test where unique = '25323324'; $res = mysql_query($sql); regards patrick -- 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] A Simple Question
Just a correction you can use arrays with querystrings page.php?var1[]=firstvar1[]=secondvar1[]=third $var1 Array ( [0] = first [1] = second [2] = third ) OR page.php?var1[]=firstvar2[2]=secondvar2[]=third $var 1 Array ( [0] = first ) $var2 Array ( [2] = second [3] = third ) You can also have multidimensional arrays, but not associative arrays. But you do have the 255 character limitation (can be a bummer). Adam Also, as far as limitations go, the following are considerations; 1. You can't pass an array using the querystring 2. Multiline variables (ie. textarea contents) are bad 3. There is a limit of 255 or something characters to a URI (someone?) 4. Be careful with the $_GET[] array that Tony mentions, it is only available on more recent versions of PHP, before that it was $HTTP_GET_VARS and a lot of people had been using just plain $var1 or whatever, assuming that register_globals would always be ON in the php.ini file (which also changed in recent versions). HTH Beau
RE: [PHP-DB] A Simple Question
Ahhh - good correction Adam, I forgot about that method :) So I suppose if you already have an array and wanted to pass it in a link/URL then you could do something like foreach($array as $value) { $qstring .= 'array[]=' . $value . ''; } echo 'a href=link.php?' . $qstring . 'link/a'; then on link.php you'd have the array $array[] (with globals) or $_GET['array'][] cool Beau -Original Message- From: Adam Royle [mailto:[EMAIL PROTECTED]] Sent: Wednesday, 10 July 2002 9:05 PM To: Beau Lebens; [EMAIL PROTECTED] Subject: RE: [PHP-DB] A Simple Question Just a correction you can use arrays with querystrings page.php?var1[]=firstvar1[]=secondvar1[]=third $var1 Array ( [0] = first [1] = second [2] = third ) OR page.php?var1[]=firstvar2[2]=secondvar2[]=third $var 1 Array ( [0] = first ) $var2 Array ( [2] = second [3] = third ) You can also have multidimensional arrays, but not associative arrays. But you do have the 255 character limitation (can be a bummer). Adam Also, as far as limitations go, the following are considerations; 1. You can't pass an array using the querystring 2. Multiline variables (ie. textarea contents) are bad 3. There is a limit of 255 or something characters to a URI (someone?) 4. Be careful with the $_GET[] array that Tony mentions, it is only available on more recent versions of PHP, before that it was $HTTP_GET_VARS and a lot of people had been using just plain $var1 or whatever, assuming that register_globals would always be ON in the php.ini file (which also changed in recent versions). HTH Beau
[PHP-DB] A Simple Question
I recently discovered that you can pass variables through hyperlinks. (I didn't know this could be done) This will be very helpful for the project I'm working on but I cannot find any information on this subject. Does anybody know where I can find information on the syntax and limitations of this feature? - Do You Yahoo!? New! SBC Yahoo! Dial - 1st Month Free unlimited access
Re: [PHP-DB] A Simple Question
Suppose you are using PHP. A link like this: http://yourdomain.com/yourpage.php?var1=value1var2=value2var3=value3 will do the trick. And in the page that receives this link (yourpage.php that is), use $_GET[] to get the value: $var1 = $_GET[var1]; $var2 = $_GET[var2]; $var3 = $_GET[var3]; Tony S. Wu Manuel at [EMAIL PROTECTED] wrote: I recently discovered that you can pass variables through hyperlinks. (I didn't know this could be done) This will be very helpful for the project I'm working on but I cannot find any information on this subject. Does anybody know where I can find information on the syntax and limitations of this feature? - Do You Yahoo!? New! SBC Yahoo! Dial - 1st Month Free unlimited access -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] A Simple Question
Also, as far as limitations go, the following are considerations; 1. You can't pass an array using the querystring 2. Multiline variables (ie. textarea contents) are bad 3. There is a limit of 255 or something characters to a URI (someone?) 4. Be careful with the $_GET[] array that Tony mentions, it is only available on more recent versions of PHP, before that it was $HTTP_GET_VARS and a lot of people had been using just plain $var1 or whatever, assuming that register_globals would always be ON in the php.ini file (which also changed in recent versions). HTH Beau // -Original Message- // From: Tony [mailto:[EMAIL PROTECTED]] // Sent: Wednesday, 10 July 2002 7:42 AM // To: Manuel; [EMAIL PROTECTED] // Subject: Re: [PHP-DB] A Simple Question // // // Suppose you are using PHP. // A link like this: // // http://yourdomain.com/yourpage.php?var1=value1var2=value2va // r3=value3 // // will do the trick. // And in the page that receives this link (yourpage.php that // is), use $_GET[] // to get the value: // // $var1 = $_GET[var1]; // $var2 = $_GET[var2]; // $var3 = $_GET[var3]; // // Tony S. Wu // // // Manuel at [EMAIL PROTECTED] wrote: // // // I recently discovered that you can pass variables through // hyperlinks. (I // didn't know this could be done) This will be very helpful // for the project I'm // working on but I cannot find any information on this subject. // // Does anybody know where I can find information on the // syntax and limitations // of this feature? // // // // - // Do You Yahoo!? // New! SBC Yahoo! Dial - 1st Month Free unlimited access // // // // // -- // 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] A Simple Question
4. Be careful with the $_GET[] array that Tony mentions, it is only available on more recent versions of PHP, before that it was $HTTP_GET_VARS and a lot of people had been using just plain $var1 or whatever, assuming that register_globals would always be ON in the php.ini file (which also changed in recent versions). 4. Be careful with the $_GET[] array that Tony mentions, it is only available on more recent versions of PHP, before that it was $HTTP_GET_VARS and a lot of people had been using just plain $var1 or whatever, assuming that register_globals would always be ON in the php.ini file (which also changed in recent versions). register_globals was turned off by default in the INI file in 4.2.0+ so I would recommend against using them. Besides compatability issues, there are security issues with it. Of course, to maintain backward compatability (Superglobals are only supported in 4.1.0+) you might want to use the $HTTP_POST_VARS, $HTTP_GET_VARS e.t.c. which are being phased out however. Remember though, 4.1.0 was released on the 10th of Decemeber, so there's a good chance many hosts have upgraded to that version or greater, but there are always the late ones. Good reading: http://www.php.net/manual/en/language.variables.predefined.php -- Adam Alkins http://www.rasadam.com -- -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] a simple question
can somebody help me with the following code: function multi_word($title) { $array = explode ( , $input); $number = count ($array); if ($number 1) { return true; } else{ return false; } } if ($category) { $Query = SELECT * from $TableName WHERE ((category)=$category); } else { if ($title) { if (multi_word($title)) { print one word at a time for now; die(); } else { $Query = SELECT * from $TableName WHERE title LIKE '%$title%'; } } } when i try to pass in a multi-word string it doesnt print anything. I have tested the function and I know it works allright... if anyone could help that would be great. Brad -- 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] a simple question
Hi Brad, Your parameter is named $title and you are converting a variable called $input to an array. You could catch this type of errors if you change the setting for error_reportiong in php.ini. - Frank can somebody help me with the following code: function multi_word($title) { $array = explode ( , $input); $number = count ($array); if ($number 1) { return true; } else{ return false; } } if ($category) { $Query = SELECT * from $TableName WHERE ((category)=$category); } else { if ($title) { if (multi_word($title)) { print one word at a time for now; die(); } else { $Query = SELECT * from $TableName WHERE title LIKE '%$title%'; } } } when i try to pass in a multi-word string it doesnt print anything. I have tested the function and I know it works allright... if anyone could help that would be great. Brad -- 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] -- 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]