Jump to content

script for query a db help needed


helloise

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.