tcorbeil Posted March 31, 2007 Share Posted March 31, 2007 Hello again. I have this: $query="SELECT 'submitid' FROM `subcategories` ORDER BY 'submitid' DESC LIMIT 1; $result=mysql_query($query); basically, I want to get the last value of the submitid to use elswere.. the above keeps give me a T_Parse error.. Any help would be appreciated.. T. Link to comment https://forums.phpfreaks.com/topic/45007-help-please/ Share on other sites More sharing options...
fert Posted March 31, 2007 Share Posted March 31, 2007 you forgot a " Link to comment https://forums.phpfreaks.com/topic/45007-help-please/#findComment-218478 Share on other sites More sharing options...
AndyB Posted March 31, 2007 Share Posted March 31, 2007 ... at the end Link to comment https://forums.phpfreaks.com/topic/45007-help-please/#findComment-218479 Share on other sites More sharing options...
tcorbeil Posted March 31, 2007 Author Share Posted March 31, 2007 thanks fellas. it would seem the variable $result returns something like "id #" ... i would like to get rid of the '#' symbol.. I used: $query="SELECT 'submitid' FROM `subcategories` ORDER BY 'submitid' DESC LIMIT 1"; $result=mysql_query($query); $result=str_replace("_", "#", $result); but it's not working.. what I'm after is something $result = value of id_1_oilers... any ideas? Link to comment https://forums.phpfreaks.com/topic/45007-help-please/#findComment-218486 Share on other sites More sharing options...
AndyB Posted March 31, 2007 Share Posted March 31, 2007 $query="SELECT 'submitid' FROM `subcategories` ORDER BY 'submitid' DESC LIMIT 1"; $result=mysql_query($query); $row = mysql_fetch_array($result); // got the data now $some_var = $row['whatever_variable_you_want']; // NOW you can run the str_replace ...{/code] Link to comment https://forums.phpfreaks.com/topic/45007-help-please/#findComment-218488 Share on other sites More sharing options...
jitesh Posted March 31, 2007 Share Posted March 31, 2007 $query="SELECT `submitid`(No cotation sign for feild and tables) FROM `subcategories` ORDER BY submitid DESC LIMIT 1"; Link to comment https://forums.phpfreaks.com/topic/45007-help-please/#findComment-218506 Share on other sites More sharing options...
tcorbeil Posted March 31, 2007 Author Share Posted March 31, 2007 Can someone please clarify this code? i keep getting the value Resource id#4 no matter what value submit id is.. what i need is to get the last value in the submitid column in my table.. problem is, i can't seem to get the value out of the array $result... any other suggestions? T Link to comment https://forums.phpfreaks.com/topic/45007-help-please/#findComment-218509 Share on other sites More sharing options...
AndyB Posted March 31, 2007 Share Posted March 31, 2007 Please post a more complete portion of your code (and does it look like I suggested two posts ago?) Link to comment https://forums.phpfreaks.com/topic/45007-help-please/#findComment-218633 Share on other sites More sharing options...
tcorbeil Posted March 31, 2007 Author Share Posted March 31, 2007 Basically, all I want to do is look into a table, grab the last index number so i can then use it to make a unique variable: eg: look into table hockey and get the last entry on the idex.. Tabel hockey: submitid NHL team ------------------------------------ 1 Oilers 2 Flames 3 Flyers So in the end, I want to be able to do something like: /// code to get the last entry on of submitid... $index_id now holds the value "3" ...now lets add one to the value.. $index_id = $index_id ++; $some_var = "_Canucks"; $next_entry = $index_id.$some_var; echo $next_entry; ///// should be a value of "4_Canucks" ..I tried your code AndyB, but am not able to make it work.. T. Link to comment https://forums.phpfreaks.com/topic/45007-help-please/#findComment-218778 Share on other sites More sharing options...
shocker-z Posted March 31, 2007 Share Posted March 31, 2007 If this helps then you can use mysql_insert_id() which returns the last unique ID of a row inserted into your table. Regards Liam Link to comment https://forums.phpfreaks.com/topic/45007-help-please/#findComment-218781 Share on other sites More sharing options...
tcorbeil Posted March 31, 2007 Author Share Posted March 31, 2007 ... tried it.. got this message: Warning: mysql_insert_id(): supplied argument is not a valid MySQL-Link resource in /home/tcorbeil/public_html/Global/subpost.php on line 41 code is: $query="SELECT submitid FROM subcategories ORDER BY submitid DESC LIMIT 1"; $result=mysql_insert_id($query); $result=ereg_replace("[^[:alnum:]]", "", $result); $result= str_replace("Resourceid", "ID", $result); $mktbl = $result."_".$Subpage; Link to comment https://forums.phpfreaks.com/topic/45007-help-please/#findComment-218788 Share on other sites More sharing options...
AndyB Posted March 31, 2007 Share Posted March 31, 2007 You do understand that $result is a resource and NOT the actual array of values retrieved, don't you? Take a look at what I posted below to see how to get the array of values from the resource. Link to comment https://forums.phpfreaks.com/topic/45007-help-please/#findComment-218815 Share on other sites More sharing options...
tcorbeil Posted March 31, 2007 Author Share Posted March 31, 2007 thanks shocker.. i can't use the id idea as it requires me to submit into a table prior.. I need to be able to get the auto_increment id prior to any action.. AndyB, you'll have to forgive me.. I think where I get lost is here: $some_var = $row['whatever_variable_you_want']; // NOW you can run the str_replace ...{/code] you lost me.. is it some_var that gets the value out of the array?? and I also don't understand what to put in for 'whatever_variable_you_want.. would it be like this? $some_var = $row['test']; ...and then i would format the variable $test?? i just don't get it.. can you enlighten me? T. Link to comment https://forums.phpfreaks.com/topic/45007-help-please/#findComment-218822 Share on other sites More sharing options...
tcorbeil Posted March 31, 2007 Author Share Posted March 31, 2007 to add, i do understand your post AndyB.. what I don't know how to do is get the value out of the array... Link to comment https://forums.phpfreaks.com/topic/45007-help-please/#findComment-218823 Share on other sites More sharing options...
AndyB Posted March 31, 2007 Share Posted March 31, 2007 What is the name of the specific field that you want to retrieve from the database record? Suppose it was team_name. Then: $query = " ... your query ..."; // use your real query here $result = mysql_query($query) or die("error: ". mysql_error(). " with query ". $query); $row = mysql_fetch_array($result); // get the array of values from the resource result $team_name = $row['team_name']; // abstract a specific array element. do same for other vars Link to comment https://forums.phpfreaks.com/topic/45007-help-please/#findComment-218824 Share on other sites More sharing options...
tcorbeil Posted March 31, 2007 Author Share Posted March 31, 2007 I tried this.. $submitid = $row['submitid']; echo $submitid; in the effort to get the last entry value issued in my table (If I had 5 entries in the table listed under submitid, i would expect this to be a 5) but all i have echoed to the screen is submitid.. why would this not echo a value of 5? T. Link to comment https://forums.phpfreaks.com/topic/45007-help-please/#findComment-218825 Share on other sites More sharing options...
tcorbeil Posted April 1, 2007 Author Share Posted April 1, 2007 sorry... I just want to know if someone could kindly have another review of this... T Link to comment https://forums.phpfreaks.com/topic/45007-help-please/#findComment-218895 Share on other sites More sharing options...
AndyB Posted April 1, 2007 Share Posted April 1, 2007 sorry... I just want to know if someone could kindly have another review of this... Sure - but we need more than two lines of code. Why not post your table structure along with the complete code you're using to retrieve data from the database. And are you sure the table contains the information you think it contains? phpAdmin would verify what's really in the database. Link to comment https://forums.phpfreaks.com/topic/45007-help-please/#findComment-218931 Share on other sites More sharing options...
tcorbeil Posted April 1, 2007 Author Share Posted April 1, 2007 I would AndyB but i think i would confuse myself in trying to explain.. sheesh.. i didn't think this would be so difficult.. I just want to have a variable be equal to the last entry of the submit Id (auto_increment) in my table.. i don't know what else to say but if post code, it will only raise more questions I'm sure.. the only thing I can think is to ask you this: let say you have table with 5 entries in it where the primary colum is an incremtal counter which increases with every entry.. (who care what other colums are in it really...) how would you go about writing code to look at the table get the last counter value and throw that value into a variable?? T. I just want a piece of code to look at the Link to comment https://forums.phpfreaks.com/topic/45007-help-please/#findComment-218938 Share on other sites More sharing options...
AndyB Posted April 1, 2007 Share Posted April 1, 2007 $query="SELECT submitid FROM subcategories ORDER BY submitid DESC LIMIT 1"; $result=mysql_query($query) ; $row = mysql_fetch_array($result); // got the data now $some_var = $row['submitid']; echo $some_var; Link to comment https://forums.phpfreaks.com/topic/45007-help-please/#findComment-218956 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.