Jump to content

cjackson111

Members
  • Posts

    19
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

cjackson111's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. It should return the average value from the database fields
  2. Hello. I am pulling data, joining two MySQL tables (using php). When I use the following part in my select statement all rows are returned (which I want) even if it does not have a value for 'r_star' SELECT..... challnge.r_star ..... FROM.... But when I use the following, only rows are returned that have values for 'r_star' SELECT..... AVG(challnge.r_star) ..... FROM.... I want to find the average for the field r_star. Any ideas what I may be doing worng? Thanks!
  3. That's what I thought, but when I started specifying it as UTF-8, that is when I started getting the error.
  4. That's what I want to do, fix it from the root, but I am not sure what to do to fix it. Any ideas?
  5. Hello all. I have a php script that creates an xml file pulled from a mysql database. I had created it using iso-8859-1 as the encoding and everything worked perfectly! However, the client wants it encoded at UTF-8. $_xml ="<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\r\n"; When I do that I get the following error -- An invalid character was found in text content. Error processing resource 'http://www..... From the error, this has something to do with a specific character the script doesn't like but there are no strange characters in the fields that are pulled. Any ideas what may be the problem? I would greatly appreciate any help!
  6. Cool, thanks alot. I'll try it in the morning...too sleepy now
  7. Hello. I am pulling data from a mysql table and want to replace some strings that may appear in the data. Is it possible to use str_replace to replace more than one value at a time? For instance, replace '+' with 'plus' AND '-' with 'minus'. This doesn't work but something like this -- str_replace($search1, $replace1, $subject1, $search2, $replace2, $subject2); Thanks for all help!
  8. I am now trying to ftp the saved file to a remote server but can't seem to get it to work. The following is the code I have for that -- //FTP file to remote server $ftpStream = ftp_connect("ftp.domain.com"); $loginResult = ftp_login($ftpStream, "username@domain.com", "password"); if ($loginResult) { ftp_put($ftpStream, "target.txt", "target.txt", FTP_ASCII); } ftp_quit($ftpStream);
  9. Got it. Thanks so much for your help!
  10. Thanks. I now see that the file is saved on the server, however it does not have the .csv extension to it. Any ideas what I may be doing wrong? I have added the following code -- file_put_contents($filename, $csv_output);
  11. Hello all. I have a script that exports data from mysql to a csv file. Everything works great. However, I do not know how to save the csv file to the server. Does anyone have any ideas how I would do that? The script is below. Thanks for all help! <?php $host = 'localhost'; $user = ''; $pass = ''; $db = ''; $table = ''; $file = 'export'; function escape_csv_value($value) { $value = str_replace('"', '""', $value); // First off escape all " and make them "" if(preg_match('/,/', $value) or preg_match("/n/", $value) or preg_match('/"/', $value)) { // Check if I have any commas or new lines return '"'.$value.'"'; // If I have new lines or commas escape them } else { return $value; // If no new lines or commas just return the value } } $link = mysql_connect($host, $user, $pass) or die("Can not connect." . mysql_error()); mysql_select_db($db) or die("Can not connect."); $result = mysql_query("SHOW COLUMNS FROM ".$table.""); $i = 0; if (mysql_num_rows($result) > 0) { while ($row = mysql_fetch_assoc($result)) { $csv_output .= $row['Field'].", "; $i++; } } $csv_output .= "\n"; $values = mysql_query("SELECT * FROM ".$table.""); while ($rowr = mysql_fetch_row($values)) { for ($j=0;$j<$i;$j++) { $csv_output .= escape_csv_value($rowr[$j]).','; //$csv_output .= $rowr[$j].", "; } $csv_output .= "\n"; } $filename = $file."_".date("Y-m-d_H-i",time()); //header( "Content-Type: application/save-as" ); header("Content-type: application/vnd.ms-excel"); header("Content-disposition: csv" . date("Y-m-d") . ".csv"); header( "Content-disposition: attachment; filename=".$filename.".csv"); //header( "Content-disposition: filename=".$filename.".csv"); print $csv_output; exit; ?>
  12. Ok, I have a little snag. Everything works great except for the last bit (order by date ASC). It still shows whatever record is first in the database. Any ideas what I may be doing wrong? $sql = "select memberid, event, category, date, enddate, locality, location, address, city, state, zip, contact, phone, notes, doc1, doc2, doc3, doc4, doc5 from event where date >= '$datenow' GROUP BY memberid ORDER BY date ASC"; Thanks!
  13. Thanks, that worked! I was thinking I needed to use DISTINCT. I specified to display the first record of each group by adding an order by clause. Thanks for your help!!!
  14. No, I only want to show one record that has the same memberid. For instance, I have 5 similar records that all have the same memberid. I only want to show one of them
  15. Hello. I am trying to display only one instance of records that have the same memberid in my db. I am using the following statement but it continues to show all of the records that have the same memberid. Any ideas what I may be doing wrong? $sql = "select DISTINCT memberid, event, category, date, enddate, locality, location, address, city, state, zip, contact, phone, notes, doc1, doc2, doc3, doc4, doc5 from event where date >= '$datenow' ORDER by date ASC"; Thanks for any help!
×
×
  • 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.