Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
First PHP Script ... not working!
Old 09-30-2007, 08:28 PM First PHP Script ... not working!
Junior Talker

Posts: 1
Name: none
Trades: 0
Hello all,
First off, i'm starting to learn PHP so excuse me if my quetion wasn't up to the level.

Anyway, I have setup spam filtering server that runs mysql in the backend. I want to send my clients the total amount of spam messages and virus messages they are getting a month.

here is the script:
Code:
<?php
// Building mysql connection
$con = mysql_connect("localhost","root","mypass");
if (!$con)
  {
  die ('Could not connect:' . mysql_error());
  }
// Selecting Database
mysql_select_db("mailscanner", $con);

$allmail = mysql_query("SELECT COUNT(*) FROM maillog WHERE to_domain="mydomain.com" AND MONTH(date) = MONTH(CURRENT_DATE)");

//Printing output
echo $allmail;

mysql_close($con);
?>
For some reason, the script is not giving any output. under MySQL shell, i have tested the query inclused into $allmail variable. i have also tested the above PHP script with simpler mysql and it works fine.

I need to learn from you guys ... any help will be highly appreciated.

Regards;
real_shock is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 09-30-2007, 09:06 PM Re: First PHP Script ... not working!
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
it's because $allmail is a reference to a mysql result.
You need to process this reference to get the datas you want:
PHP Code:
<?php
// Building mysql connection
$con mysql_connect("localhost","root","mypass");
if (!
$con)
  {
  die (
'Could not connect:' mysql_error());
  }
// Selecting Database
mysql_select_db("mailscanner"$con);

//Not the column alias here, just after the count()
$allmail mysql_query("SELECT COUNT(*) AS cnt FROM maillog WHERE to_domain="mydomain.com" AND MONTH(date) = MONTH(CURRENT_DATE)");

//Here, we fetch into the array $res all the rows returned by your query.
//The array indexes can be numeric, but I recommande you to use the
//literral value, it's more straightforward. For that, I've aliased the count(*)
//in your query, otherwise , you would need $res['count(*)'] to get the result
while($res=mysql_fetch_array($allmail)){
  echo 
$res['cnt'];
}


mysql_close($con);
?>
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Reply     « Reply to First PHP Script ... not working!
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.88980 seconds with 12 queries