i have the following code in php:
$host="localhost"; // Host name
$username="***"; // username
$password="***"; // password
$db_name="***"; // 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();
hakre
200k55 gold badges454 silver badges868 bronze badges
asked Apr 20, 2011 at 10:03
charlie_cat
1,8507 gold badges46 silver badges75 bronze badges
-
Accept your recent questions.hsz– hsz2011年04月20日 10:05:26 +00:00Commented Apr 20, 2011 at 10:05
-
Don't post your username and password...user657496– user6574962011年04月20日 10:06:20 +00:00Commented Apr 20, 2011 at 10:06
-
pleas select your code and click the {} icon when you ask a question. This will format the code.tim_a– tim_a2011年04月20日 10:06:51 +00:00Commented Apr 20, 2011 at 10:06
-
yep, that's code alright. what do you want it to do?trickwallett– trickwallett2011年04月20日 10:07:58 +00:00Commented Apr 20, 2011 at 10:07
3 Answers 3
What do you actually want to do? You have to describe the problem else no one can help you...
answered Apr 20, 2011 at 10:05
KillerX
1,4661 gold badge15 silver badges26 bronze badges
Sign up to request clarification or add additional context in comments.
2 Comments
CloudyMarble
and this is a comment and not an naswer!
tim_a
Then you should not comment :-)
You have no proper error handling. The mysql functionality provided with php have a build in function that outputs the error on the screen. This would be a lot better:
<?php
$host="localhost"; // Host name
$username="***"; // username
$password="***"; // password
$db_name="***"; //db name
$connection = mysql_connect($host, $username, $password) or die("Could not connect to the database: " . mysql_error());
mysql_select_db($db_name, $connection) 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) or die("Could not execute query: " . $sql . "ERROR: " . mysql_error());
$count = mysql_num_rows($result);
mysql_close($connection) or die(mysql_error());
?>
answered Apr 20, 2011 at 10:15
tim_a
9701 gold badge7 silver badges21 bronze badges
4 Comments
tim_a
if you find a answer of someone really useful you need to accept this. You can do this by pressing on the V icon (so it becomes green) in the left upper corner of an answer. (Under the number with votes).
charlie_cat
how can i now write the output to a text file to make it look nice? thank you
tim_a
to a .txt file or to a a webpage?
charlie_cat
thank you i sorted it, i wanted to run a few queries on the db to get some stats to send to a client in a text file thanks all!
In addition to the error handling already mentioned, for your second resultset, you might want to ensure that $count2 is the number of rows returned in $result2 rather than in the first resultset ($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($result2);
answered Apr 20, 2011 at 11:05
Mark Baker
213k34 gold badges354 silver badges391 bronze badges
Comments
lang-php