Jump to content

punky79

Members
  • Posts

    17
  • Joined

  • Last visited

    Never

Everything posted by punky79

  1. After a bit of research and advise from others I think I will go for option 1 and use customer_id for identification.
  2. Looking for any suggestions or advise or even best practices. I have developed an online database using php and mysql. It allows companies to log complaints and resolutions etc. There is a user database with user details for login and a cip database for logging the main data. 2 companies are trialing and testing the database. At the moment each company is using separate databases and separate html pages. Everything is seperate for each company. I am wondering what the best way forward would be when adding more companies. Ideas that I have are: 1. To have one large database for users and one large database for cip and use a company id or similar to identify individual companies records in the datasebase. 2. To use the same html pages for every company but select which database to use from the login details. So that each company will have a separate cip database but all companies use the same users database. 3. Or just keep everything separate for every company. (this might be really bad for doing updates) I hope I have made myself clear and look forward to any suggestions. Thanks
  3. Yes that is perfect. I was over complicating it. Thank you for all your help
  4. Sorry I realised that I needed to just pass the name of the field to the array...not the whole object. I have modified the code. Now I am stuck in the foreach loop........ <?php //if(isset($_POST['submitted'])) //{ //echo "submitted"; //if(isset($_POST['csvexport'])){ require_once ('includes/database_connect.php'); $query = "SELECT * FROM cip ORDER BY cip_ID"; $result = mysqli_query ($dbc,$query); $num_fields = mysqli_num_fields($result); $headers = array(); ///for ($i = 0; $i < $num_fields; $i++) { //$headers[] = mysql_field_name($result , $i); //} $fields = mysqli_fetch_fields($result); for ($i = 0; $i < $num_fields; $i++) { foreach ($fields as $val) { $headers[$i]= $val->name; } } $fp = fopen('php://output', 'w'); if ($fp && $result) { header('Content-Type: text/csv'); header('Content-Disposition: attachment; filename="All CIPs report.csv"'); header('Pragma: no-cache'); header('Expires: 0'); fputcsv($fp, $headers); while ($row = $result->fetch_array(MYSQLI_NUM)) { fputcsv($fp, array_values($row)); } die; } //} //} ?>
  5. Thanks for the reply. I am not sure how to use the "mysqli_fetch_fields" function. I have posted code below....but I think I have gone at it in the wrong way all together.... error "Object of class stdClass could not be converted to string" <?php //if(isset($_POST['submitted'])) //{ //echo "submitted"; //if(isset($_POST['csvexport'])){ require_once ('includes/database_connect.php'); $query = "SELECT * FROM cip ORDER BY cip_ID"; $result = mysqli_query ($dbc,$query); $num_fields = mysqli_num_fields($result); $headers = null; ///for ($i = 0; $i < $num_fields; $i++) { //$headers[] = mysql_field_name($result , $i); //} $fields = mysqli_fetch_fields($result); for ($i = 0; $i < $num_fields; $i++) { foreach ($fields as $val) { $headers .= $val; } } $fp = fopen('php://output', 'w'); if ($fp && $result) { header('Content-Type: text/csv'); header('Content-Disposition: attachment; filename="All CIPs report.csv"'); header('Pragma: no-cache'); header('Expires: 0'); fputcsv($fp, $headers); while ($row = $result->fetch_array(MYSQLI_NUM)) { fputcsv($fp, array_values($row)); } die; } //} //} ?>
  6. Thank you for the very fast reply. That has worked for me but now an error on "mysql_field_name()" error "mysql_field_name() expects parameter 1 to be resource" I have tried mysqli_field_name() but it does not work. Should I be coming at it a different way to print out each header?
  7. Hi, I am trying to download a mysql query to a csv file and have written code to perform this. I can get the database information out to the file but the field names (headers) will not come out. I am using "mysql_num_fields" to get the number of field names but I get the error "mysql_num_fields() expects parameter 1 to be resource". I have checked the PHP manual and it seems that the mysqli query I am running returns an object and "mysql_num_fields()" needs a resource? I am not sure how to get around this? Here is my code...any help would be appreciated. Thanks require_once ('includes/database_connect.php'); $query = "SELECT * FROM cip ORDER BY cip_ID"; $result = mysqli_query ($dbc,$query); $num_fields = mysql_num_fields($result); $headers = array(); for ($i = 0; $i < $num_fields; $i++) { $headers[] = mysql_field_name($result , $i); } $fp = fopen('php://output', 'w'); if ($fp && $result) { header('Content-Type: text/csv'); header('Content-Disposition: attachment; filename="All CIPs report.csv"'); header('Pragma: no-cache'); header('Expires: 0'); fputcsv($fp, $headers); while ($row = $result->fetch_array(MYSQLI_NUM)) { fputcsv($fp, array_values($row)); } die; }
  8. Than ks for your reply I have managed to get it working now. Here is the code I used: $filenamepath .= "images.xml"; $fp = fopen($filenamepath,'w'); $write = fwrite($fp,$xml_output); echo $xml_output; Thanks for your help
  9. thanks for reply I have been trying to use this function but I keep getting this error: Warning: file_put_contents(C:\htdocs\PhotoABC\upload_test\J ordan) [function.file-put-contents]: failed to open stream: Permission denied in C:\htdocs\PhotoABC\xml.php on line 43 I dont know if I need to open inout and output streams or just if my permissions are not set properly? Do u have any suggestions? $filename= 'C://htdocs//PhotoABC//upload_test//'.$_SESSION['MM_Username']; file_put_contents($filename ,$xml_output);
  10. I have code written to generate xml data in PHP from my MySQL database. I can display this in my browser using "echo" but wbat I really want is to write this xml data to a seperate xml file so that I can have flash use it. Here is my code: <?php require_once('Connections/PhotoABC.php'); ?> <?php if (!isset($_SESSION)) { session_start(); } $sqluserid = "SELECT `user_id` FROM `user` WHERE `username` = '".$_SESSION['MM_Username']."'"; $useridqueryresult = mysql_query($sqluserid) or die (mysql_error()); if (mysql_num_rows($useridqueryresult) > 0) { $row=mysql_fetch_assoc($useridqueryresult); $userid=$row['user_id']; } $sqlimagename = "SELECT `image_name` FROM `gallery` WHERE `user_id` = '$userid'"; $imagenamequeryresult = mysql_query($sqlimagename) or die (mysql_error()); $xml_output = "<?xml version=\"1.0\"?>\n"; $xml_output .= "<images>\n"; for($x = 0 ; $x < mysql_num_rows($imagenamequeryresult) ; $x++){ $row = mysql_fetch_assoc($imagenamequeryresult); $xml_output .= "\t<image>\n"; xml_output .= "\t\t<image>" . $row['image_name'] . "</image>\n"; $xml_output .= "\t</image>\n"; } $xml_output .= "</images>"; echo $xml_output; ?> I would like to write this xml data to a new xml file called "images" and to save it to this directory "C:\htdocs\PhotoABC\upload_test\Jordan" Any help would be great
  11. Thank u so muc Little guy That worked a treat I thought I was gonna go mad with all the ' and " Thanks
  12. Thanks The Little Guy I tried your 2 suggestions and got this error "Error in INSERT: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''user_id', 'image_name') VALUES ('5','C:\htdocs\PhotoABC\upload_test\Jordan/2008' at line 1" I seem to be going around in circles?? Any more help is appreciated It does seem to be nearly there tho cause the VALUES seem to be correct!!!
  13. Thanks N350CA When I try yours I get this error "Error in INSERT: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''user_id', 'image_name') VALUES ('5','C:\htdocs\PhotoABC\upload_test\Jordan/2008' at line 1"
  14. Thanks little guy.... When i try yours I get this error "Error in INSERT: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1"
  15. Error: Unknown column 'Jordan' in 'where clause' My code: $v=UPLOAD_DIR.$_SESSION['MM_Username'].'/'.$now.$_SESSION['MM_Username'].'-'.$file; //copy image to database $sql = "SELECT user_id FROM user WHERE username = ".$_SESSION['MM_Username'].""; $queryresult = mysql_query($sql) or die (mysql_error()); if (mysql_num_rows($queryresult) > 0) { $row=mysql_fetch_assoc($queryresult); $userid=$row['user_id']; } $resins=mysql_query("INSERT INTO gallery (user_id, image_name) VALUES ($userid,'$v'") or die("Error in INSERT: ".mysql_error()); The only place I can see it is getting the name 'Jordan' is from the session name .$_SESSION['MM_Username']. Can anyone help with this... If more of my code is need I can post the whole script.
  16. Error in INSERT: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 Any ideas of what this error might be. Here is my SQL code in a PHP script. $v=UPLOAD_DIR.$_SESSION['MM_Username'].'/'.$now.$_SESSION['MM_Username'].'-'.$file; //copy image to database $sql ="SELECT user_id FROM user WHERE username = '".$_SESSION['MM_Username']."'"; $queryresult = mysql_query($sql) or die (mysql_error()); if (mysql_num_rows($queryresult) > 0) { $row=mysql_fetch_assoc($queryresult); $userid=$row['user_id']; } $resins=mysql_query("INSERT INTO gallery (user_id, image_name) VALUES ($userid,'$v'") or die("Error in INSERT: ".mysql_error());
×
×
  • 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.