Jump to content
Stef's Coding Community


  • Content Count

  • Joined

  • Last visited

Community Reputation

0 Neutral

About Hank

  • Rank
    New member
  • Birthday 08/09/1970

Profile Information

  • Gender
  • Location
    Adelaide, Australia

Contact Methods

  • Website
  1. Hank

    csv files

    I need to write a script to do the following. 1. read data from csv files in a bunch of directories (the list of directories will grow in time) 2. the idea is that these csv files will be updated by car dealers and then uploaded to their respective directories thru ftp (I'm good with this bit as I will set the dir's and access) 3. problem comes in that at the dealer side the content of the files will keep changing. (some car info will remain / some will be deleted / and new ones will be added), this goes for all the dealers. 4. With every csv file they will upload images relating to the data in the csv files, so I will need to link this as well somehow. 5. the idea is to run this file with cron.php at set intervals to update the database (will ask how to do this when I get there) What I've managed so far is to loop through the lot with the glob function, and adding the files, but my problem is updating the database. (cars removed from the csv files must not be deleted just set to sold, so we can keep that data for statistics) Hope someone can point me in the right direction. This is the code i've written so far: (Also added the temp database and some csv files) PS: there are no headings in the csv files. <?php $username ="root"; $password = "myPasword"; $host = "localhost"; $table = "csv_table"; $conn = new mysqli("$host", "$username", "$password"); // echo "Connected to localhost" . "<br />"; mysql_select_db("csvdb") or die(mysql_error()); // echo "Connected to Database"; ?> <?php // Set variable for csv file path $dir = "dealer_upload/*/*.csv"; // Open a known directory, and proceed to read its contents foreach(glob($dir) as $file) { //echo "PATH AND FILENAME: " . $file . "<br /><br />"; // Create the array $fileTemp = $file; $fp = fopen($fileTemp,'r'); $datas = array(); while (($data = fgetcsv($fp)) !== FALSE) { $stockNumber = trim($data[0]); $make = trim($data[1]); $model = trim($data[2]); $derivative = trim($data[3]); $series = trim($data[4]); $reg = trim($data[5]); $vin = trim($data[6]); $driveAwayPrice = trim($data[7]); $priceExcluding = trim($data[8]); $specialPrice = trim($data[9]); $year = trim($data[10]); $kilometres = trim($data[11]); $body = trim($data[12]); $colour = trim($data[13]); $engine = trim($data[14]); $transmission = trim($data[15]); $fuel = trim($data[16]); $options = trim($data[17]); $sellingPoints = trim($data[18]); $nvic = trim($data[19]); $redBook = trim($data[20]); // Insert Data mysql_query ("INSERT INTO $table (id_dealer, stockNumber, make, model, derivative, series, reg, vin, driveAwayPrice, priceExcluding, specialPrice, year, kilometres, body, colour, engine, transmission, fuel, options, sellingPoints, nvic, redBook) VALUES ('$file', '$stockNumber', '$make', '$model', '$derivative', '$series', '$reg', '$vin', '$driveAwayPrice', '$priceExcluding' ,'$specialPrice' , '$year' , '$kilometres' , '$body', '$colour', '$engine', '$transmission', '$fuel', '$options', '$sellingPoints', '$nvic', '$redBook') ") or die (mysql_error()); } } ?> csv.zip
  2. The latest wordpress should be a breeze to install, don't even need to change the wp-config file. step 1 would be to create your database through your cpanel from your provider step 2 create user and password step 3 link user to database then copy all wordpress files to your hosting and run index.php, from there you just fill in the details to match your database connection if you need to change the wordpress theme go to /wp-content/themes and hack the one you want to change (make a backup!) hope this helped if all else fails, get the video tutorial from killerphp, helped me heaps in the beginning.
  3. Hank


    mmm right, I recently purchased this from some dodgy guys somewhere. Got the script installed and all seems to be working well. What I want to do is to have a link to a wordpress blog (Already installed and working) This is the code below: My directory structure looks something like this: root --blog -header.php (but the actual header of my website is in my root directory - linked to a header.php.html file(Struggling to figure this out in root/themes/mythemes)) I've made some comment below, be great if someone can point me in the right direction. ----------------------------------- <?php /** * The Header for our theme. * * Displays all of the <head> section and everything up till <div id="main"> * * @package WordPress * @subpackage Twenty_Ten * @since Twenty Ten 1.0 */ ?><!DOCTYPE html> <html <?php language_attributes(); ?>> <head> <meta charset="<?php bloginfo( 'charset' ); ?>" /> <title><?php /* * Print the <title> tag based on what is being viewed. */ global $page, $paged; wp_title( '|', true, 'right' ); // Add the blog name. bloginfo( 'name' ); // Add the blog description for the home/front page. $site_description = get_bloginfo( 'description', 'display' ); if ( $site_description && ( is_home() || is_front_page() ) ) echo " | $site_description"; // Add a page number if necessary: if ( $paged >= 2 || $page >= 2 ) echo ' | ' . sprintf( __( 'Page %s', 'twentyten' ), max( $paged, $page ) ); ?></title> <?php /* We add some JavaScript to pages with the comment form * to support sites with threaded comments (when in use). */ if ( is_singular() && get_option( 'thread_comments' ) ) wp_enqueue_script( 'comment-reply' ); /* Always have wp_head() just before the closing </head> * tag of your theme, or you will break many plugins, which * generally use this hook to add elements to <head> such * as styles, scripts, and meta tags. */ wp_head(); ?> <link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>" /> <?php ----- ALL WORKS WELL TO THIS POINT ---------------------------- #//v.3.2.2 #/////////////////////////////////////////////////////// #// COPYRIGHT 2004 Phpauction.org ALL RIGHTS RESERVED// #/////////////////////////////////////////////////////// ----------------- WHEN IT GETS HERE IT GIVES ME ACCESS DENIED ----------------- if(!defined("INCLUDED")) exit("Access denied"); $prefix = str_replace("http://", "", $prefix); if ( file_exists($prefix.'./includes/config.inc.php')) require($prefix.'./includes/config.inc.php'); else exit ("Access forbbiden"); ------------IF I SET $prefix TO A NEW VALUE I CAN GET PAST THIS TOP BIT , I PRESUME NOT A GOOD IDEA----------------- mysql_query("SET CHARACTER_SET_CLIENT=utf8"); mysql_query("SET character_set_server=utf8"); mysql_query("SET character_set_results=utf8"); mysql_query("SET character_set_database=utf8"); mysql_query("SET character_set_connection=utf8"); mysql_query("SET collation_server=utf8"); mysql_query("SET collation_database=utf8"); mysql_query("SET collation_connection=utf8"); #// Atuomatically login user is necessary ("Remember me" option if(!isset($_SESSION["PHPAUCTION_LOGGED_IN"]) && isset($_COOKIE['PHPAUCTION_RM_ID'])) { $query = "SELECT userid FROM PHPAUCTIONXL_rememberme WHERE hashkey='".addslashes($_COOKIE['PHPAUCTION_RM_ID'])."'"; $res = mysql_query($query); if(!$res){ MySQLError($query); exit; }elseif(mysql_num_rows($res) > 0){ $REMEMBER = mysql_fetch_array(mysql_query("SELECT id,email,nick,name FROM PHPAUCTIONXL_users WHERE id=".intval(mysql_result($res,0,"userid")))); mysql_error(); $_SESSION["PHPAUCTION_LOGGED_IN"] = $REMEMBER['id']; $_SESSION["PHPAUCTION_LOGGED_EMAIL"] = $REMEMBER['email']; $_SESSION["PHPAUCTION_LOGGED_NAME"] = $REMEMBER['name']; $_SESSION["PHPAUCTION_LOGGED_IN_USERNAME"] = $REMEMBER['nick']; } } /** ************************************************************************* * NOTE: Modules enbled version * This version of header.php can be called from any Phpauction XL module * It uses the $prefix variable to set the correct include path. * * *****************************************************************************/ -------------BUT THEN I GET TO THE INCLUDES BELOW I GET THE MESSAGE ACCESS DENIED, I KNOW OR THINK IT IS BECAUSE I CANNOT ACCESS THOSE FILES DIRECTLY --------------- // include "../includes/ips.inc.php"; // include $prefix."includes/ips.inc.php"; //-- Function definition section include $prefix."includes/dates.inc.php"; include $prefix."maintenance.php"; include $prefix."includes/banners.inc.php"; #// if(basename($PHP_SELF) != "error.php") { include $prefix."includes/stats.inc.php"; } // flag to enable style editor $editstyle=isset($_SESSION["PHPAUCTION_ADMIN_USER"]) && !isset($_GET['thepage']); $editstyle=$editstyle && $prefix==""; // Added by Edgar 12/09/2005 // to handle relative paths to themes when browsing webstores // Seeks path to header.php.html in address of being at home directory or webstores module if (!isset($SETTINGS['theme']) || empty($SETTINGS['theme'])) $SETTINGS['theme']='default'; $htmlheader="themes/".$SETTINGS['theme']."/header.php.html"; if (!file_exists($htmlheader)) { $htmlheader="../../themes/".$SETTINGS['theme']."/header.php.html"; } include($htmlheader); ?> </head>
  4. : ) and just to show how little I know, how do I figure out what the server path is? I created a dummy file and put phpinfo() in to see if I can find it in there, but my knowledge is ...
  5. Thanks guys, WAMP runs perfect and if I create a DB locally it works great in localhost. in my config file I have this - require_once('passwd.inc.php'); $main_path = $server_path; $include_path = $server_path."includes/"; and then in the passwd.inc.php file I have this bit - <?php $DbHost = "localhost"; // The host where the MySQL server resides $DbDatabase = "lookawin_icauction"; // The database you are going to use $DbUser = "lookawin_icaucti"; // Username $DbPassword = "mypassword"; // Password $server_path= "/home/lookawin/public_html/"; ?> All my files are in this folder - C:\wamp\www\lookawine Could it be the server path?
  6. Hi, I am sure this has been answered somewhere but I cannot find it. Anyway I bought a PHP website of someone and they installed it for me with my ISP. It works a charm but I want to make some small changes to the layouts and CS. So i've downloaded the files from the public folder onto my PC using Wamp and exported the database to my hard drive and imported the DB with PHPmyAdmin. But I cannot get it to work, is there somewhere a tutorial on how to do this? Tx Hank
  • Create New...