RON_ron Posted August 10, 2010 Share Posted August 10, 2010 I need to pull all the mysql data by the order of it's date/time . How can I write the code? I'm using this as a serverside script and I'm not a php person. But i believe the below code will not pull the data. Will it work if I remove the text marked in red? $query = "SELECT * FROM sub_db WHERE the_code = '".$abc."'" ORDER BY timestampz ASC"; Quote Link to comment https://forums.phpfreaks.com/topic/210301-pull-all-the-data/ Share on other sites More sharing options...
trq Posted August 10, 2010 Share Posted August 10, 2010 Will it work if I remove the text marked in red? Yes, why not try it? Quote Link to comment https://forums.phpfreaks.com/topic/210301-pull-all-the-data/#findComment-1097411 Share on other sites More sharing options...
RON_ron Posted August 10, 2010 Author Share Posted August 10, 2010 how can I pull in only the latest record? Quote Link to comment https://forums.phpfreaks.com/topic/210301-pull-all-the-data/#findComment-1097416 Share on other sites More sharing options...
Adam Posted August 10, 2010 Share Posted August 10, 2010 SELECT * FROM sub_db ORDER BY timestampz DESC LIMIT 0,1 Quote Link to comment https://forums.phpfreaks.com/topic/210301-pull-all-the-data/#findComment-1097419 Share on other sites More sharing options...
RON_ron Posted August 10, 2010 Author Share Posted August 10, 2010 Great! Thank you MrAdam. Quote Link to comment https://forums.phpfreaks.com/topic/210301-pull-all-the-data/#findComment-1097435 Share on other sites More sharing options...
RON_ron Posted August 10, 2010 Author Share Posted August 10, 2010 How can I put 2 queries using the same php script? (ie. the same values to be sent to database 1 and 2) $query = "INSERT INTO db_1(abc1, abc2, abc3, abc4) VALUES('$a','$b','$c,'$d')"; $query = "INSERT INTO db_2(abc1, abc2, abc3, abc4) VALUES('$a','$b','$c,'$d')"; $result = mysql_query($query); $sentOk = "The data has been added to the database."; Quote Link to comment https://forums.phpfreaks.com/topic/210301-pull-all-the-data/#findComment-1097454 Share on other sites More sharing options...
Adam Posted August 10, 2010 Share Posted August 10, 2010 With your code all you're doing is storing the first query within $query, then overwriting the same variable with the next query and then running that. You can't be trying to debug this much yourself as a quick var_dump() test on $query before you try to execute it, would have shown you that you only have the second query stored. How can I put 2 queries using the same php script? (ie. the same values to be sent to database 1 and 2) Do you mean insert the same values into both tables? Different databases would require a very different approach. A good question is why do you want to store identical data within two identical tables? Seems a little redundant to me. Quote Link to comment https://forums.phpfreaks.com/topic/210301-pull-all-the-data/#findComment-1097482 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.