helloise Posted April 20, 2011 Share Posted April 20, 2011 i have the following code in php: <?php error_reporting (E_ALL); $host="localhost"; // Host name $username="elemental"; // username $password="rclogin"; // password $db_name="traffic2"; // Database name //$rc_profile_table="rc_profile_table"; // Table name //$rc_profile_relation_table="rc_profile_relation_table"; // Table name mysql_connect("$host", "$username", "$password"); mysql_select_db("$db_name"); $sql="SELECT created_at FROM rc_profile_table where created_at > 2011-04-19 08:00:00"; $result=mysql_query($sql); $count=mysql_num_rows($result); $sql="SELECT created_at FROM rc_profile_relation_table where created_at > 2011-04-19 08:00:00"; $result2=mysql_query($sql); $count2=mysql_num_rows($result); mysql_close(); ?> am i on the right path please? thank you Quote Link to comment https://forums.phpfreaks.com/topic/234239-script-for-query-a-db-help-needed/ Share on other sites More sharing options...
Nodral Posted April 20, 2011 Share Posted April 20, 2011 Hi What exactly are you trying to acheive? This script looks fine but obviously we need to know the purpose. Are you getting an error? Stu Quote Link to comment https://forums.phpfreaks.com/topic/234239-script-for-query-a-db-help-needed/#findComment-1203916 Share on other sites More sharing options...
Muddy_Funster Posted April 20, 2011 Share Posted April 20, 2011 Your going the right way, except for a couple of things: your timestamp value in the query string should be enclosed in single quotes; you should have error capture on your connection and query stings and you are using 2 queries where 1 would do. other than that looks spot on, It would be better if you would continue the verbose commenting aswell. Quote Link to comment https://forums.phpfreaks.com/topic/234239-script-for-query-a-db-help-needed/#findComment-1203920 Share on other sites More sharing options...
helloise Posted April 20, 2011 Author Share Posted April 20, 2011 i need to get some stats off the database tables and output it to a text file to send to a client Quote Link to comment https://forums.phpfreaks.com/topic/234239-script-for-query-a-db-help-needed/#findComment-1203921 Share on other sites More sharing options...
helloise Posted April 20, 2011 Author Share Posted April 20, 2011 thank you all, i make those changes and my next step would be to output it to a text file....how would i go about doing that please? thank you Quote Link to comment https://forums.phpfreaks.com/topic/234239-script-for-query-a-db-help-needed/#findComment-1203923 Share on other sites More sharing options...
helloise Posted April 20, 2011 Author Share Posted April 20, 2011 i made some changes and it looks like this now: <?php error_reporting (E_ALL); $host="localhost"; // Host name $username="elemental"; // username $password="rclogin"; // password $db_name="traffic2"; // Database name //$rc_profile_table="rc_profile_table"; // Table name //$rc_profile_relation_table="rc_profile_relation_table"; // Table name mysql_connect("$host", "$username", "$password")or die("Could not connect to the database: " . mysql_error()) ; mysql_select_db("$db_name") or die("Could not select database: " . mysql_error()) ; $sql="SELECT created_at FROM rc_profile_table where created_at > '2011-04-19 08:00:00'"; $result=mysql_query($sql); $count=mysql_num_rows($result); $sql="SELECT created_at FROM rc_profile_relation_table where created_at > '2011-04-19 08:00:00'" ; $result2=mysql_query($sql)or die("Could not execute query: " . $sql . "ERROR: " . mysql_error()) ; $count2=mysql_num_rows($result)or die(mysql_error()) ; mysql_close(); ?> how can i write some output to a text file to make it look nice? thanks Quote Link to comment https://forums.phpfreaks.com/topic/234239-script-for-query-a-db-help-needed/#findComment-1203940 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.