-
Posts
23 -
Joined
-
Last visited
Never
Everything posted by maca134
-
Forcing title of output files in uppercase...
maca134 replied to tonyjms2005's topic in PHP Coding Help
Hey If i understand you correctly, this one it easy. I would save the filename in a var first: $filename = $value . '_' . str_replace('/', '', $data[$ccyValue][0]) . '.csv'; $filename = strtoupper($filename); $fp = fopen(DIR . $filename, 'w'); Thats should work -
Hey all Im trying to find a way to combine images but set the blend mode, like in Photoshop, selecting how layers are blended together. I have looked at all the docs for GD with no luck... Cheers in advanced Maca134
-
you will have to draw the table if you use the PHP image functions. Finding a "HTML -> PDF" PHP is going to be much easier. try looking on www.phpclasses.org, its a great website for PHP classes
-
Oh i use codeigniter all the time... Its easy to integrate it into a controller class Home extends Controller { public $item_count = 0; ...your other vars/controllers/etc... function _scan( $parent_cat_id = 0 ) { $result = mysql_query('SELECT * FROM `cats` WHERE `parent_id` = "' . $parent_cat_id . '"'); if ( mysql_num_rows($result) > 0 ) { $item_count = $item_count + mysql_num_rows($result); while ( $row = mysql_fetch_assoc($result) ) { $this->_scan( $row['id'] ); } } } function _get_item_count() { return $this->item_count; } } Or you could put the function into a Model, which would make sense, as they are for DB stuff
-
How do I display images stored in my databse???
maca134 replied to maxves1's topic in PHP Coding Help
You could embed the image data directly into the HTML page, take a look at this: http://danielcamargo.com/blog/embedding-image-in-html/ <div class="some_image" style="width:100px; height: 100px; background: url(data:image/gif;base64,<?php echo base64_encode($image_data_gif); ?>);"></div> -
Hey assuming you have an open database connection, the code below might be suitable: class recursive_scan { public $item_count = 0; function scan( $parent_cat_id = 0 ) { $result = mysql_query('SELECT * FROM `cats` WHERE `parent_id` = "' . $parent_cat_id . '"'); if ( mysql_num_rows($result) > 0 ) { $item_count = $item_count + mysql_num_rows($result); while ( $row = mysql_fetch_assoc($result) ) { $this->scan( $row['id'] ); } } } function get_item_count() { return $this->item_count; } } $rs = new recursive_scan; $rs->scan(); var_dump( $rs->get_item_count() ); I have tested it but it should work
-
Cheers I was having a dumb moment lol
-
Hey Im trying to set some vars in a class, here is code: class someClass { public $var1 = ''; public $var2 = ''; public function __construct($options) { if (isset($options) && is_array($options)) { foreach ($options as $key => $val) { $this->$$key = $val; } } } } $options = array('var1' => 1, 'var2' => 2); $class = new someClass($options); I know the above is wrong but can someone tell me how to access class vars, like you can access vars with a double dollar sign ($$vars) Thanks in advanced
-
Help! What does this mean? expecting `T_STRING'
maca134 replied to morocco-iceberg's topic in PHP Coding Help
The best thing for you to do is re-write, putting the code on 'more than one line' It would of made the error easier to spot( line numbers are given on errors) The code would be a nightmare for you to maintain later on... But a quick look suggests theres missing quotes all over the show and some that havent be slashed out... So i suggest re-write (im sure you really dont want to tho) -
Help! What does this mean? expecting `T_STRING'
maca134 replied to morocco-iceberg's topic in PHP Coding Help
lol -
mysql_fetch_assoc is the function you require http://php.net/manual/en/function.mysql-fetch-assoc.php
-
thats is because the function mysql_fetch_array() outputs an array. Try var_dump($output) and see what happens
-
you need to make sure the fetch_array function is in the class. also i good idea to output the SQL instead on executing it to check it right. Might be an idea to remove the 'at' at the end of mysql_query(), if the SQL is correct then it wont produce an error.
-
After the line 'public $ini;' Put 'private $query;' and the last line of the dbselect function change from $query = @mysql_query($q); to $this->query = @mysql_query($q); Now you can create another function like so: public function fetch_array() { return mysql_fetch_array($this->query); } This will return the results you after
-
The last line of the function needs to be something like $this->query = @mysql_query($q); Then $row = mysql_fetch_array($this->query) will work if the line is inside a function in the same class as the function 'dbselect'
-
Take a look at this: http://www.phpclasses.org/browse/package/1267.html
-
Populating a multidimensional array in JS with PHP
maca134 replied to spenceddd's topic in PHP Coding Help
Heres a little example of how it works: <?php // Setting simple multi-array up $someArray['a']['1'] = 'cell: a1'; $someArray['a']['2'] = 'cell: a2'; $someArray['a']['3'] = 'cell: a3'; $someArray['b']['1'] = 'cell: b1'; $someArray['b']['2'] = 'cell: b2'; $someArray['b']['3'] = 'cell: b3'; $someArray['c']['1'] = 'cell: c1'; $someArray['c']['2'] = 'cell: c2'; $someArray['c']['3'] = 'cell: c3'; // Converts the array into a JSON string $json_string = json_encode($someArray); ?> <html> <head> <title>JSON Example</title> </head> <body> <script type="text/javascript"> var someArray = <?php echo $json_string; ?>; /* Sets someArray */ /* Examples: Access the array in JS */ document.write('someArray[\'a\'][\'1\'] = ' + someArray['a']['1'] + '<br />'); document.write('someArray[\'b\'][\'2\'] = ' + someArray['b']['2'] + '<br />'); document.write('someArray[\'c\'][\'3\'] = ' + someArray['c']['3'] + '<br />'); </script> </body> </html> -
do you want to embed the image into the email or link it?? to link it, all you need to do is file_put_contents() to a lcation that is accessible to the web then link the image in the email "<img src='http://www.yourdomain.com/path/to/img' />" Embedding the image increase bandwidth on the server especially if your sending loads of emails. The best thing to do for embedding is take a look on www.phpclasses.org and find a mime email class, will make your life much easier
-
Populating a multidimensional array in JS with PHP
maca134 replied to spenceddd's topic in PHP Coding Help
have you tried using json_encode?? You could probably echo the resulting string into the page <script type="text/javascript"> var myJSONObject = <?php echo json_encode($this_array); ?>; </script> -
If its already image binary data then you shouldn't need to use imagecreatetruecolor. Eg. If the binary data is a GIF header('Content-type: image/gif'); echo $binary_data; exit; That should do it
-
found this: http://www.zend.com//code/codex.php?ozid=175&single=1 Slightly edited it: class dec2fraction { function convert($number, $top_heavy = false) { if (strpos($number, '.') === false) $number .= '.0'; list ($whole, $numerator) = explode ('.', $number); $denominator = 1 . str_repeat (0, strlen ($numerator)); $GCD = self::GCD($numerator, $denominator); $numerator /= $GCD; $denominator /= $GCD; if ($top_heavy) { $numerator = $numerator + ($whole * $denominator); $whole = 0; } return array('whole' => (int) $whole, 'numerator' => $numerator, 'denominator' => $denominator); } function GCD ($a, $b) { while ( $b != 0) { $remainder = $a % $b; $a = $b; $b = $remainder; } return abs ($a); } } var_dump(dec2fraction::convert(3.14, true)); var_dump(dec2fraction::convert(3.14, false)); var_dump(dec2fraction::convert(3, true)); var_dump(dec2fraction::convert(3, false)); var_dump(dec2fraction::convert(5.25, true)); var_dump(dec2fraction::convert(5.25, false)); /* OUTPUT array 'whole' => int 0 'numerator' => int 157 'denominator' => int 50 array 'whole' => int 3 'numerator' => int 7 'denominator' => int 50 array 'whole' => int 0 'numerator' => int 3 'denominator' => int 1 array 'whole' => int 3 'numerator' => int 0 'denominator' => int 1 array 'whole' => int 0 'numerator' => int 21 'denominator' => int 4 array 'whole' => int 5 'numerator' => int 1 'denominator' => int 4 */ Hope this helps
-
so do you want the follow: 1.5 -> 3/2 or 1 1/2 2.2 -> 11/5 or 2 1/5 ??
-
If your going to run some PHP script using Lynx/wget, I dont think you need the '#!/usr/local/bin/php' at the top You only need this if you want to run the script directly from the command line. I use NANO to edit '/etc/crontab' and use WGET to run the script. The script be a normal php file that 'can' be run from your browser. 00 00 * * * root wget -O /dev/null http://www.somedomain.co.uk/cronjobs/daily_jobs.php /dev/null 2>&1 Runs daily @ 12:00am This work a treat for me. Hope it helps!