Jump to content

ziv

Members
  • Posts

    32
  • Joined

  • Last visited

    Never

Posts posted by ziv

  1. link=topic=179218.msg798214#msg798214 date=1201446095]

    well this file is on a remote server, and it contains everything from 100 to over 100,000 lines =) so fopen() is the one i should use?

     

    i'm not sure...because in this case if you use http protocol, there is no benefits for the fopen().....

  2. $fp = fopen($file,"r");

    $conetents = fread($fp,sile_size($file));

     

    On my server that will read a 5mb file in seconds.

     

    this is the same as using file_get_contents()

    <?php
    $conetents = file_get_contents($file);
    ?>

     

    but if you have a memory problem (or performance) you should not load all this data into the memory.

     

     

  3. something like this?

    <?php
    
    /**
    * @param int $length - max 40 chars (sha1 length)
    * @return string
    */
    function getRandomPassword($length) {
    return substr(
    	base64_encode( sha1( mt_rand() ) ),
    	0,
    	$length);
    }
    
    // i used base64 encoding becouse it's convert any
    // data to letters (lowers and uppers) and numbers 
    echo getRandomPassword(35); 
    ?>

  4. simple oo php example:

    <?php
    <?php
    
    class ImageDetails {
    /**
     * all image details you need from your db.
     * use "mysql_fetch_object" to build your results as objects
     */
    public function getName() {
    	return 'x';
    	// image name for example...
    }
    }
    
    
    class ImageGallery {
    
    private $list;
    
    private $size;
    
    /**
     * @param array $list, list of images details
     * @param int $size, number of gallery collumns 
     */
    public function __construct($list, $size = 3) {
    	$this->list = $list;
    	$this->size = $size;
    }
    
    public function show() {
    	$counter = 0;
    
    	echo '<table border="1">';
    	foreach ($this->list as $image) {
    		if ($counter == 0) { // open row
    			echo '<tr>';
    		}
    
    		$this->_printRow($image);
    		++$counter;
    
    		if ($counter == $this->size) { // close row
    			echo '</tr>';
    			$counter = 0;
    		}
    	}
    	if ($counter != 0) { // padding the table
    		$this->_paddTable($counter);
    	}
    
    	echo '</table>';
    }
    
    private function _printRow($image) {
    	// here you print the image in any form you want
    	echo '<td>' . $image->getName() . '</td>';
    }
    
    private function _paddTable($counter) {
    	for ($i=$counter ; $i<$this->size ; ++$i) {
    		echo '<td> </td>';
    	}
    }
    }
    
    // 'list of your images (ImageDetails objects)
    $list = array(new ImageDetails(), new ImageDetails(), new ImageDetails(), new ImageDetails(), new ImageDetails(), new ImageDetails(), new ImageDetails(), new ImageDetails(), new ImageDetails(), new ImageDetails());
    
    $gallery = new ImageGallery($list);
    $gallery->show();
    
    

  5. lets take a look at your code:

     

    <?php
    function MYSQL_DATABASE_QUERY($SQL, $DB_Server) {
    
    $QUERY = mysql_query($SQL, $DB_Server) or die(mysql_error());# or die ("Failed Query");
    return $QUERY;
    }
    

     

    are you sure you send to this function mysql-resource as the first parameter?

     

    if you use the return value of this function:

    <?php
    function CONNECT_MYSQL_DATABASE() {
    
    $host = "localhost";  #usually localhost
    $account = "<>"; # username for access.  eg. root
    $password = "<>"; 
    $db_name = "<>"; #name of database on the server that you want to connect.
    
    #global $db_type;
    #$db_type = 4.1; # MySQL version
    
    $DB_Server = mysql_connect($host, $account, $password) or die(mysql_error());# or die ("Cannot connect to a database.  Please try again later");
    $DB_Server = mysql_select_db($db_name, $DB_Server) or die("Cannot select the database.  Please try again later.");
    return $DB_Server;
    }
    

     

    than you use a boolean value (the return value of mysql_select_db) as mysql-resource. you should return the return value of mysql_connect as mysql-resource.

  6. I know how to do that, my session contain info for userA, i don't want userB to get userA. I want to create a unique session only for userA.

     

    Session is unique per user!

    this code:

    <?php
    session_start();
    $_SESSION['x'] = /* any data you want to store */;
    ?>

    will create a session file for each user-request (one per user).

    the user A will not see the value x of user B!

  7. pre tag is good for any pre-formated data (plain text) but if you want to convert it to simple html, you can use the nl2br() function.

    <?php
    $str = 'this is text
    with new line';
    
    echo $str; //this is text with new line 
    
    echo nl2br($str); //this is text<br />with new line
    ?>
    

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