aquapan Posted March 8, 2010 Share Posted March 8, 2010 Hi, I got stuck recently attempting to read an sql database using php as I kept on getting the error: Warning: implode() [function.implode]: Invalid arguments passed in /home/***/public_html/***/includes/query_posts.php on line 28 The idea was that I would create this php page that would read an vbulletin sql database and then pop off an email when a user is over certain post amounts of 500 and 1000. The idea being that the poster is rewarded for their efforts etc. Here below is the code I am using with identifying site information trimmed of course using *** symbols - this version is for the 500 post limit being met or exceeded. <?php //Get variables from config.php to connect to mysql server require 'config.php'; // connect to the mysql database server. mysql_connect ('localhost', '***', '***'); //select the database mysql_select_db('***_forums1') or die('Cannot select database'); //select statement for users $sql = "SELECT username FROM user WHERE posts >='500'"; $result = mysql_query($sql); $row = mysql_fetch_assoc($result); $username = $row["username"]; //take the emails and add a comma to email and create an string $list = implode(',' , $username); echo $list; $to = "***@***.com"; $subject = "These users have reached 500 posts "&$list; //send the emails //mail($to, $from, $subject); ?></p> Now I can't see why this error would happen as I don't fully understand implode and its requirements. Any help appreciated. Thanks Aqua Quote Link to comment Share on other sites More sharing options...
aeroswat Posted March 8, 2010 Share Posted March 8, 2010 implode function requires an array where the $username variable is. Your $username is not an array. I'll fix what needs to be fixed real fast Quote Link to comment Share on other sites More sharing options...
aeroswat Posted March 8, 2010 Share Posted March 8, 2010 <?php //Get variables from config.php to connect to mysql server require 'config.php'; // connect to the mysql database server. mysql_connect ('localhost', '***', '***'); //select the database mysql_select_db('***_forums1') or die('Cannot select database'); //select statement for users $sql = "SELECT username FROM user WHERE posts >='500'"; $result = mysql_query($sql); $username = array(); if(mysql_num_rows($result)>0) { while($row = mysql_fetch_assoc($result)) { $username[] = $row["username"]; } } //take the emails and add a comma to email and create an string $list = implode(',' , $username); echo $list; $to = "***@***.com"; $subject = "These users have reached 500 posts: " . $list; //send the emails //mail($to, $from, $subject); ?> That should do what u want it to Quote Link to comment Share on other sites More sharing options...
aquapan Posted March 8, 2010 Author Share Posted March 8, 2010 Wow Aeroswat you are fast... thanks! I will give this a try Cheers Aqua Quote Link to comment Share on other sites More sharing options...
aeroswat Posted March 8, 2010 Share Posted March 8, 2010 Wow Aeroswat you are fast... thanks! I will give this a try Cheers Aqua Np. You are going to have to do a little to that mail function to get it to work but the code I have given you will create your list sufficiently. If you need help with the mail part let me know and I'll help ya with that too. Quote Link to comment Share on other sites More sharing options...
aquapan Posted March 8, 2010 Author Share Posted March 8, 2010 You were right on that too... a little help is needed on the mail. I thought $subject would throw detail into the subject but for whatever reason it throws it into the body of the email. The from I had originally seemed to be ignored by the mail function and it just sent it direct from the server. Is there a way to define from as well? I will also do some code adjustments as well as I am looking at this alerting when someone reaches 500 posts and then again when they reach 1000 posts. The idea being that this is triggered daily as a report via a cron job. Cheers Aqua Quote Link to comment Share on other sites More sharing options...
aeroswat Posted March 8, 2010 Share Posted March 8, 2010 You were right on that too... a little help is needed on the mail. I thought $subject would throw detail into the subject but for whatever reason it throws it into the body of the email. The from I had originally seemed to be ignored by the mail function and it just sent it direct from the server. Is there a way to define from as well? I will also do some code adjustments as well as I am looking at this alerting when someone reaches 500 posts and then again when they reach 1000 posts. The idea being that this is triggered daily as a report via a cron job. Cheers Aqua from should be included in your header (the fourth section of the mail function) something like this $header = 'From: SystemAdmin@yoursite.com' . "\r\n" . 'Reply-To: no-reply@yoursite.com' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); Quote Link to comment Share on other sites More sharing options...
aquapan Posted March 8, 2010 Author Share Posted March 8, 2010 thanks aeroswat again.... you are a legend. is there a hero button here somewhere? Cheers Aqua Quote Link to comment Share on other sites More sharing options...
aeroswat Posted March 8, 2010 Share Posted March 8, 2010 thanks aeroswat again.... you are a legend. is there a hero button here somewhere? Cheers Aqua Thank you. Glad to help man. Good luck with your project! Quote Link to comment 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.