Jump to content

renfley

Members
  • Posts

    89
  • Joined

  • Last visited

Posts posted by renfley

  1. Ok so guys im a little stuck on some code here and could use some help..

     

    ok so i have 3 rows in column and created 3 folder to match them

     

    /ticket/

    ->folder1

    ->folder2

    ->folder3

     

    Now at the end of day i might have more folders, 

     

    folder4,5,6,7 ect...

     

    I want to be able to check and create missing folders based on whats missing but i also want it to catch any folders that might have been deleted. 

     

    here is my code, the reason it doesnt work is that as soon as it finds a folder that doesn't exists, it creates 1 folder but wont create more then that because the confition was met. and the code stops.

     

    I have tried many different alternative any input would be awesome 

     

    //Query DB
    $sql = "SELECT DISTINCT tn from tic";
    $result = mysql_query($sql) or die(mysql_error());
    $loc = "../tickets/";
    while ($row = mysql_fetch_assoc($result)){
    $dir = $loc . $row['tn'];
    if(!is_dir($dir)){
    mkdir($dir); } 
    elseif(is_dir($dir)){ 
    }
    }
    exit();

     

     

     

     

     

  2. Hey guys im trying to download an excel sheet from the db and it keeps displaying the entire content on page and would like to just download but it aint working. 

    $DB_Server = "localhost";
    $DB_Username = "root";
    $DB_Password = "";
    $DB_DBName = "test";
    $DB_TBLName = "tickets";
    $filename = "MasterBackup";
    
    //create MySQL connection
    $sql = "Select * from $DB_TBLName";
    $Connect = @mysql_connect($DB_Server, $DB_Username, $DB_Password) or die("Couldn't connect to MySQL:<br>" . mysql_error() . "<br>" . mysql_errno());
    //select database
    $Db = @mysql_select_db($DB_DBName, $Connect) or die("Couldn't select database:<br>" . mysql_error() . "<br>" . mysql_errno());
    //execute query
    $result = @mysql_query($sql, $Connect) or die("Couldn't execute query:<br>" . mysql_error() . "<br>" . mysql_errno());
    
    //create query to select as data from your table
    $select = "SELECT * FROM $DB_TBLName";
    
    //run mysql query and then count number of fields
    $export = mysql_query ( $select ) 
           or die ( "Sql error : " . mysql_error( ) );
    $fields = mysql_num_fields ( $export );
    
    //create csv header row, to contain table headers 
    //with database field names
    for ( $i = 0; $i < $fields; $i++ ) {
    	$header .= mysql_field_name( $export , $i ) . ",";
    }
    
    //this is where most of the work is done. 
    //Loop through the query results, and create 
    //a row for each
    while( $row = mysql_fetch_row( $export ) ) {
    	$line = '';
    	//for each field in the row
    	foreach( $row as $value ) {
    		//if null, create blank field
    		if ( ( !isset( $value ) ) || ( $value == "" ) ){
    			$value = ",";
    		}
    		//else, assign field value to our data
    		else {
    			$value = str_replace( '"' , '""' , $value );
    			$value = '"' . $value . '"' . ",";
    		}
    		//add this field value to our row
    		$line .= $value;
    	}
    	//trim whitespace from each row
    	$data .= trim( $line ) . "\n";
    }
    //remove all carriage returns from the data
    $data = str_replace( "\r" , "" , $data );
    
    
    //create a file and send to browser for user to download
    header("Content-type: application/vnd.ms-excel");
    header("Content-disposition: csv" . date("Y-m-d") . ".csv");
    header( "Content-disposition: filename=".$file_name.".csv");
    print "$header\n$data";
    

    Any help would be awesome

     

  3. Hey guys i need to change the url field. 

     

    This is what i currently have, 

     

    site.com/?page=home
    and
    site.com/?admin=home
     
    Here is the .htaccess
     
    RewriteEngine On
    #Look for the word "wiki" followed by a slash, and then the article title
    RewriteRule   ^?admin=home /admin/home 
     
    dunno if im on the write track but ive never done url rewrites. 
     
     
    i would like to see site.com/page/home
     
  4. Well another issue fixed... For those wondering. I found a lib called dispatch, Does exactly what i need...

    // include the library
    include 'dispatch.php';
    
    // define your routes
    get('/greet', function () {
        // render a view
        render('greet-form');
    });
    
    // post handler
    post('/greet', function () {
        $name = from($_POST, 'name');
        // render a view while passing some locals
        render('greet-show', array('name' => $name));
    });
    
    // serve your site
    dispatch();
    

    You can find the files here...

    http://noodlehaus.github.io/dispatch/

     

    This will be perfect for my framework...

  5. LOL just notice my phrase...

     

    What i meant was

     

    I want to use a controller that sees the url as www.example.com/post/2 instead of www.example.com/?page=2 and include that post and 2. Can i take a controller or write a new one without having to incorporate MVC?

  6. Hey guys, 

     

    when every i create a new page we currently pass it via the url like...

    <a href="?page=home">home</a>
    

    So by using the following code.

    if (isset($_GET['page'])) {
         include ("includes/" . $_GET['page'] . ".php");
    }
    else{
     echo "Welcome Home";
    }
    

    This method looks like this

     

    www.example.com/?page=2

     

    Is there a way other to apply a complete MVC to use only the controler to change the view?

     

    so i would have www.example.com/article/

     

    and use a controler to just include?

     

     

     

     

     

     

     

     

     

     

     

  7. I am currently writing a framework and am experimenting with different array configurations,  which is why tried the second Dim...

     

    I've pretty much gone back to my original method which runs smoothly.

            //Here is the database information for use throughout the site. 
    	//You can use these anywhere -- echo $DB_USER
    	$mysql = array('DB_NAME' => 'dbname' , 'DB_USER' => 'dbuser', 'DB_PASS' => 'dbpass', 'DB_HOST' => 'dbhost'         );
    	
    	//this will take all the keys in the array and allow you to parse them as a variable.
    	// echo $DB_USER;
    	foreach($mysql as $key=>$value) { $$key = $value; }
    		
    

    I can then echo any of the keys are variables,

    <?php
        echo $DB_USER;
    ?>
    

    which will output dbuser.

     

    This has always been my go to method of doing it but wanted to see other methods and realized there aren't really any other ones that are as simple and as effective. 

     

    Thanks Guys for all the help!

  8. ive decided to save the static informaiton in an array which i have created but havent figured out how to print it, 

    $config = array(
    		"mysql" => array(
    			"DB_NAME" => "dbname",
    			"DB_USER" => "dbuser",
    			"DB_PASS" => "dbpass",
    			"DB_HOST" => "dbhost",
    			),
    		"paths" => array(
    			"resources" => "/public_html/",
    			"images" => array(
    				"content" => $_SERVER["DOCUMENT_ROOT"] . "/images/content",
    				"layout" => $_SERVER["DOCUMENT_ROOT"] . "/images/layout"
    				)
    			),
    		"title" => array(
    			"title" => "Sitename",
    			)
    		);
    

    So you can see ive save the title in the title array which will work for the task at hand. 

     

    My  issue is when i normally echo  out a array 

    echo $i['user'];
    

    but in this case the array is in the $config var, How would i go about echoing out the title?

  9. Hey guys i was wondering is there is any solutions for what i wanna do.

     

    Something Like this

     

        function Tag(){

        $title="Site Name";

        }

     

    I want to do this....

     

        <title>{$title}</title>

     

    Does anyone know what this method is called and if this even uses php or maybe even javascript?

     

  10. Hey guys i need some help!!

     

    when someone logs in i create a session called $_SESSION['username']

     

    i want to display only ticket that the logged in user owns

     

    $data = mysql_query("SELECT * FROM tickets where owner_id='$_SESSION['username']'") or die(mysql_error());

     

    But im not sure my syntax is correct anyone care to help me out?

     

  11. Hey guys i need help with a simple query and cant seem to figure it out...  Im pretty sure it has to do with the double quote but cant 

     

     

     
    mysql_connect("localhost", "host", "Sunadan86") or die(mysql_error());
    mysql_select_db("test") or die(mysql_error());
     
     
    mysql_query("INSERT INTO tickets (trouble_report, customer_number, customer_#, rrli, owner, active, key_symptoms, resolution)
    VALUES
    ($tr, $phone, $b1, $clli, $owner, $active, $symptoms, $description")) or die(mysql_error());  
     
     
    //echo "Data Inserted!";
     
     
    header( 'Location: renfley/www/?page=success' );
     
    mysql_close($con);

     

×
×
  • 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.