Jump to content

MadTechie

Staff Alumni
  • Posts

    9,409
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by MadTechie

  1. #1 please use code tags #2 the line $xml = file_get_contents('http://www.dpreview.com/feeds/news.xml'); doesn't seam to do anything useful! as your overwriting it with the curl!
  2. I'm off to bed.. so not going to be much help but just 1 thing.. how long does that query take ? as it make a question of just speeding that up.. (of course you could also reduce your script by 1 loop) but i don't think it will make a major impact also is it this page or test2.php thats causing the problems (as i see results are loading from their)
  3. IMHO, i would personally create a CSV file, in addion i would append the date to the filename (to allow easier management over what logs i wish to delete later or even archive, to display the file you can use function file (Reads entire file into an array) rsort it and then explode the lines (if needed) example (untested) <?php $display = 16; #$newlines = array(); // Get a file into an array $lines = file('mylog.csv'); rsort($lines); for($n=0,$n=<$display;$n++) { $line = $lines[$n]; #$newlines = explode(",",$line); //if you want an array echo "$line<br>"; //just echo the lines } ?> EDIT: oh the added bonus is you can download locally for archive and review in excel
  4. Okay i think i get what you mean.. your writing a PHP file.. well firstly.. thats mostly a bad idea.. but try this (very untested code) <?php /*Open for writing only; place the file pointer at the end of the file. If the file does not exist, attempt to create it. */ $fp = fopen("c:\\data\\info.txt", "r"); //a = append mode fseek($fp, -2, SEEK_END); //goback 2 from the end fwrite($fp, 'echo "the end"; ?>'); fclose($fp); ?> EDIT: Yep i was right. lol phpfreaks parse is confused with that code
  5. $dig = 2; $data = "select * from table where language_id = '5' and date = now()"; $data = preg_replace('/\'\d\'/i', "\'$dig\'", $data); echo $data; Edit: (fix) oops hard coded a 2 in the regex!
  6. Here a nice example for you to play with (i included the link to php.net mysql_fetch_assoc) i hope it helps <?php $conn = mysql_connect("localhost", "mysql_user", "mysql_password"); if (!$conn) { echo "Unable to connect to DB: " . mysql_error(); exit; } if (!mysql_select_db("mydbname")) { echo "Unable to select mydbname: " . mysql_error(); exit; } $sql = "SELECT id as userid, fullname, userstatus FROM sometable WHERE userstatus = 1"; $result = mysql_query($sql); if (!$result) { echo "Could not successfully run query ($sql) from DB: " . mysql_error(); exit; } //THIS GET THE RECORDS FOUND if (mysql_num_rows($result) == 0) { echo "No rows found, nothing to print so am exiting"; exit; } // While a row of data exists, put that row in $row as an associative array // Note: If you're expecting just one row, no need to use a loop // Note: If you put extract($row); inside the following loop, you'll // then create $userid, $fullname, and $userstatus while ($row = mysql_fetch_assoc($result)) { echo $row["userid"]; echo $row["fullname"]; echo $row["userstatus"]; } mysql_free_result($result); ?>
  7. use fopen in append mode (a) ie <?php /*Open for writing only; place the file pointer at the end of the file. If the file does not exist, attempt to create it. */ $fp = fopen("c:\\data\\info.txt", "a"); //a = append mode fwrite($fp, 'more stuff to add to the end'); fclose($fp);
  8. Sorry Just_Johnny, but corbin is correct - Can you give us more info.. for example.. is it due to a long complex sql query.. maybe its looking at a remote server.. is the output very large! does it only run slow when using prototype.js.. i'll stop their but the list can get quite long.. you really need to give more info.. corbin's post was very direct without much detail (just like your first post)!
  9. If you don't want a re-load then yes your need some client side code (i.e. JS) if you don't mind a page reload then you can use onclick to submit the form (or trigger a ajax routine) onclick="javascript:form.submit()"
  10. If a site does not allow JS then theirs nothing you can do.. if you convert it to html it was view as JS CODE but will have no affect it will just be readable.. the only option i can think of is if the sites allow flash objects then you could create a flash app!
  11. Are you sure your not including it twice? Also i'm not sure what your attempting here ((! $gzFile && ! $file = @fopen($filename, "rt")) || ($gzFile && ! $file = @gzopen($filename, "rt"))); its a conidtion to nothing! in anycase i cleaned up the code formatting <?php if (isset($_COOKIE['sbadmin'])) { admin_header(); # INCLUDE THE FILE CONTAINING THE MYSQL CONNECTION VARIABLES include_once ("data/required.php"); # CONNECT TO MYSQL DATABASE if (! $error) { $link = @mysql_connect($dbhost, $dbuser, $dbpass); if ($link) $db = mysql_select_db($db); if (! $link || ! $db) { echo ("<p class=\"error\">The following error occured: " . mysql_error() . "</p>\n"); $error = true; } } else { $link = false; } // REQUIRED SETTINGS $linesThisSession = 3000; define('DATA_CHUNK_LENGTH', 16384); foreach ($_REQUEST as $key => $val) { $val = preg_replace("/[^_A-Za-z0-9-\.&= ]/i", '', $val); $_REQUEST[$key] = $val; } $error = false; $file = false; # CREATES THE DATABASE SELECTION FORM if ($filename == "") { $backupFileDir = "backup/"; $handle = opendir($backupFileDir); while ($filename = readdir($handle)) { $filenames[] = $filename; } closedir($handle); sort($filenames); print"</br>\n"; print"<h2 class=style2 align=center>Restore Database</h2>\n"; print"<p class=style2>Select the database you wish to restore from the menu below</p>"; print"<form action=\"" . $_SERVER["PHP_SELF"] . "?cmd=sqlimport&import=1&filename=$filename&\" method='POST'>"; print"<table bgcolor=#0066FF align=center>"; print"<tr><td>"; print"<select name='filename'>"; print"<option>Choose Database Backup</option>"; foreach ($filenames as $filename) { if (($filename != ".") and ($filename != "..")) { printsprintf("<option value='$backupFile%s'>%s</option>", $filename, $filename); } } print"</select></td>"; print"<td><input type='submit' name='import' value='Start Import'></td></tr>"; print"</table></form>"; print"</center>"; print' </td> </tr> </table>'; } # DEFINES THE FILENAME POSTED FROM THE DATABASE SELECTION FORM $filename = 'backup/' . $_POST['filename']; # CHECK THAT SELECTED FILE IS A .GZ FILE if (eregi("\.gz$", $filename)) $gzFile = true; else $gzFile = false; ((! $gzFile && ! $file = @fopen($filename, "rt")) || ($gzFile && ! $file = @gzopen($filename, "rt"))); # START IMPORTING BACKUP TO DATABASE if (! $error && isset($_REQUEST["import"]) && eregi("(\.(gz))$", $filename)) $lineNum = $_REQUEST["import"]; $querylines = 0; # PROCESS IF MAX LINES ARE NOT REACHED while ($lineNum < $_REQUEST["import"] + $linesThisSession || $query != "") { $dumpline = ""; while (! feof($file) && substr($dumpline, - 1) != "\n") { if (! $gzFile) $dumpline .= fgets($file, DATA_CHUNK_LENGTH); else $dumpline .= gzgets($file, DATA_CHUNK_LENGTH); } if ($dumpline === "") break; # REMOVE \\ FROM DUMPLINE $noslash = str_replace("\\\\", "", $dumpline); $query .= $dumpline; # EXECUTE THE QUERY IF END OF QUERY IS REACHED if (ereg(";$", trim($dumpline))) { if (! mysql_query(trim($query), $link)) { echo ("<p class=\"error\">Error at the line $lineNum: " . trim($dumpline) . "</p>\n"); echo ("<p>Query: " . trim(nl2br(htmlentities($query))) . "</p>\n"); echo ("<p>MySQL: " . mysql_error() . "</p>\n"); $error = true; break; } $query = ""; } $lineNum ++; } # CONFIRM DATABASE HAS BEEN RESTORED AND THEN RESTART THE SCRIPT if ($lineNum < $_REQUEST["import"] + $linesThisSession) { echo ("<p class=\"success\">MySQL Database: $filename has been restored successfully.</p>\n"); } if ($link) mysql_close(); if ($file && ! $gzFile) fclose($file); else if ($file && $gzFile) gzclose($file); } else { print"<p class=style2>You are not authorised to access this page</p>"; } break; ?>
  12. The problem seams to be a cache problem Try holding the shift key down when you refeash the page.. if that doesn't work then in FF press ctrl+shift+delete untick all except cache and click 'Clear Private data' try the same in IE as the code should be the same in both (you may want yo view source as it may parse but not view correctly)
  13. Yes you can do this, via AJAX Heres a basic idea from a dropdown list Dynamic DropDown PHP/AJAX I hope it helps
  14. Cool, Can you click 'topic solved' bottom left please
  15. Extra info: but if you did need to check you could create a function using sockets or curl
  16. These are called "Breadcrumb Links" or backlinks after a quick google for "Php Breadcrumb" i found this http://mindpalette.com/tutorials/breadcrumbs/index.php i hope it helps
  17. lol i messed that up you can NOT referback to the one with ?:
  18. Using your own logic you might as well post the same question in any support section of any site! however your probably notice that all these site (including this one) have rules.
  19. Oppss about the double <?php One thing to remember is google re-directs by read the location of the client.. So where is your server based or are you using wamp/xamp etc Also if this is complete can you click solved please
  20. ?= is a positive lookahead ?: is a non-capture, (.*?) is the same as (?:.*?) except you can referback to the one with ?:
  21. Personally i would do something like this <?php $song = "Blink - 182 - Whats my age"; preg_match('/(^.*)(?= - ) - (.*)$/im', $song, $regs)) $artist = $regs[1]; $song= $regs[2]; echo "Band: $artist<br />Song: $song"; ?>
  22. The standard FPDF class builds the document entirely in memory, which can be problematic for large documents. You can solve this but writing the data to disk, howevery this will mess up the AliasNbPages() function.. but as your not using it now your need to save to file first.. change $pdf=new PDF(); to $pdf = new PDF(); $pdf->Open('MyPDF.pdf'); //the filename Change your PDF class to <?php class PDF extends FPDF { var $f; function Open($file) { if(FPDF_VERSION<'1.6') $this->Error('Version 1.6 or above is required by this extension'); $this->f=fopen($file,'wb'); if(!$this->f) $this->Error('Unable to create output file: '.$file); parent::Open(); $this->_putheader(); } function Image($file, $x=null, $y=null, $w=0, $h=0, $type='', $link='') { if(!isset($this->images[$file])) { //Retrieve only meta-information $a=getimagesize($file); if($a===false) $this->Error('Missing or incorrect image file: '.$file); $this->images[$file]=array('w'=>$a[0],'h'=>$a[1],'type'=>$a[2],'i'=>count($this->images)+1); } parent::Image($file,$x,$y,$w,$h,$type,$link); } function Output() { if($this->state<3) $this->Close(); } function _endpage() { parent::_endpage(); //Write page to file $filter=($this->compress) ? '/Filter /FlateDecode ' : ''; $p=($this->compress) ? gzcompress($this->buffer) : $this->buffer; $this->_newobj(); $this->_out('<<'.$filter.'/Length '.strlen($p).'>>'); $this->_putstream($p); $this->_out('endobj'); $this->buffer=''; } function _newobj() { $this->n++; $this->offsets[$this->n]=ftell($this->f); $this->_out($this->n.' 0 obj'); } function _out($s) { if($this->state==2) $this->buffer.=$s."\n"; else fwrite($this->f,$s."\n",strlen($s)+1); } function _putimages() { $filter=($this->compress) ? '/Filter /FlateDecode ' : ''; reset($this->images); while(list($file,$info)=each($this->images)) { //Load image if($info['type']==1) $info=$this->_parsegif($file); elseif($info['type']==2) $info=$this->_parsejpg($file); elseif($info['type']==3) $info=$this->_parsepng($file); else $this->Error('Unsupported image type: '.$file); //Put it into file $this->_newobj(); $this->images[$file]['n']=$this->n; $this->_out('<</Type /XObject'); $this->_out('/Subtype /Image'); $this->_out('/Width '.$info['w']); $this->_out('/Height '.$info['h']); if($info['cs']=='Indexed') $this->_out('/ColorSpace [/indexed /DeviceRGB '.(strlen($info['pal'])/3-1).' '.($this->n+1).' 0 R]'); else { $this->_out('/ColorSpace /'.$info['cs']); if($info['cs']=='DeviceCMYK') $this->_out('/Decode [1 0 1 0 1 0 1 0]'); } $this->_out('/BitsPerComponent '.$info['bpc']); if(isset($info['f'])) $this->_out('/Filter /'.$info['f']); if(isset($info['parms'])) $this->_out($info['parms']); if(isset($info['trns']) && is_array($info['trns'])) { $trns=''; for($i=0;$i<count($info['trns']);$i++) $trns.=$info['trns'][$i].' '.$info['trns'][$i].' '; $this->_out('/Mask ['.$trns.']'); } $this->_out('/Length '.strlen($info['data']).'>>'); $this->_putstream($info['data']); unset($info['data']); $this->_out('endobj'); //Palette if($info['cs']=='Indexed') { $this->_newobj(); $pal=($this->compress) ? gzcompress($info['pal']) : $info['pal']; $this->_out('<<'.$filter.'/Length '.strlen($pal).'>>'); $this->_putstream($pal); $this->_out('endobj'); } } } function _putpages() { $nb=$this->page; if($this->DefOrientation=='P') { $wPt=$this->DefPageFormat[0]*$this->k; $hPt=$this->DefPageFormat[1]*$this->k; } else { $wPt=$this->DefPageFormat[1]*$this->k; $hPt=$this->DefPageFormat[0]*$this->k; } //Page objects for($n=1;$n<=$nb;$n++) { $this->_newobj(); $this->_out('<</Type /Page'); $this->_out('/Parent 1 0 R'); if(isset($this->PageSizes[$n])) $this->_out(sprintf('/MediaBox [0 0 %.2F %.2F]',$this->PageSizes[$n][0],$this->PageSizes[$n][1])); $this->_out('/Resources 2 0 R'); if(isset($this->PageLinks[$n])) { //Links $annots='/Annots ['; foreach($this->PageLinks[$n] as $pl) { $rect=sprintf('%.2F %.2F %.2F %.2F',$pl[0],$pl[1],$pl[0]+$pl[2],$pl[1]-$pl[3]); $annots.='<</Type /Annot /Subtype /Link /Rect ['.$rect.'] /Border [0 0 0] '; if(is_string($pl[4])) $annots.='/A <</S /URI /URI '.$this->_textstring($pl[4]).'>>>>'; else { $l=$this->links[$pl[4]]; $h=isset($this->PageSizes[$l[0]]) ? $this->PageSizes[$l[0]][1] : $hPt; $annots.=sprintf('/Dest [%d 0 R /XYZ 0 %.2F null]>>',2+$nb+$l[0],$h-$l[1]*$this->k); } } $this->_out($annots.']'); } $this->_out('/Contents '.(2+$n).' 0 R>>'); $this->_out('endobj'); } //Pages root $this->offsets[1]=ftell($this->f); $this->_out('1 0 obj'); $this->_out('<</Type /Pages'); $kids='/Kids ['; for($n=1;$n<=$nb;$n++) $kids.=(2+$nb+$n).' 0 R '; $this->_out($kids.']'); $this->_out('/Count '.$nb); $this->_out(sprintf('/MediaBox [0 0 %.2F %.2F]',$wPt,$hPt)); $this->_out('>>'); $this->_out('endobj'); } function _putresources() { $this->_putfonts(); $this->_putimages(); //Resource dictionary $this->offsets[2]=ftell($this->f); $this->_out('2 0 obj'); $this->_out('<<'); $this->_putresourcedict(); $this->_out('>>'); $this->_out('endobj'); } function _putcatalog() { $this->_out('/Type /Catalog'); $this->_out('/Pages 1 0 R'); $n=3+$this->page; if($this->ZoomMode=='fullpage') $this->_out('/OpenAction ['.$n.' 0 R /Fit]'); elseif($this->ZoomMode=='fullwidth') $this->_out('/OpenAction ['.$n.' 0 R /FitH null]'); elseif($this->ZoomMode=='real') $this->_out('/OpenAction ['.$n.' 0 R /XYZ null null 1]'); elseif(!is_string($this->ZoomMode)) $this->_out('/OpenAction ['.$n.' 0 R /XYZ null null '.($this->ZoomMode/100).']'); if($this->LayoutMode=='single') $this->_out('/PageLayout /SinglePage'); elseif($this->LayoutMode=='continuous') $this->_out('/PageLayout /OneColumn'); elseif($this->LayoutMode=='two') $this->_out('/PageLayout /TwoColumnLeft'); } function _enddoc() { $this->_putpages(); $this->_putresources(); //Info $this->_newobj(); $this->_out('<<'); $this->_putinfo(); $this->_out('>>'); $this->_out('endobj'); //Catalog $this->_newobj(); $this->_out('<<'); $this->_putcatalog(); $this->_out('>>'); $this->_out('endobj'); //Cross-ref $o=ftell($this->f); $this->_out('xref'); $this->_out('0 '.($this->n+1)); $this->_out('0000000000 65535 f '); for($i=1;$i<=$this->n;$i++) $this->_out(sprintf('%010d 00000 n ',$this->offsets[$i])); //Trailer $this->_out('trailer'); $this->_out('<<'); $this->_puttrailer(); $this->_out('>>'); $this->_out('startxref'); $this->_out($o); $this->_out('%%EOF'); $this->state=3; fclose($this->f); } //Load data function LoadData($file) { //Read file lines $lines=file($file); $data=array(); foreach($lines as $line) $data[]=explode(';',chop($line)); return $data; } //Simple table function BasicTable($header,$data) { //Header foreach($header as $col) $this->Cell(40,7,$col,1); $this->Ln(); //Data foreach($data as $row) { foreach($row as $col) $this->Cell(40,6,$col,1); $this->Ln(); } } //Better table function ImprovedTable($header,$data) { //Column widths $w=array(40,35,40,45); //Header for($i=0;$i<count($header);$i++) $this->Cell($w[$i],7,$header[$i],1,0,'C'); $this->Ln(); //Data foreach($data as $row) { $this->Cell($w[0],6,$row[0],'LR'); $this->Cell($w[1],6,$row[1],'LR'); $this->Cell($w[2],6,number_format($row[2]),'LR',0,'R'); $this->Cell($w[3],6,number_format($row[3]),'LR',0,'R'); $this->Ln(); } //Closure line $this->Cell(array_sum($w),0,'','T'); } //Colored table function FancyTable($header,$data) { //Colors, line width and bold font $this->SetFillColor(255,0,0); $this->SetTextColor(255); $this->SetDrawColor(128,0,0); $this->SetLineWidth(.3); $this->SetFont('','B'); //Header $w=array(40,35,40,45); for($i=0;$i<count($header);$i++) $this->Cell($w[$i],7,$header[$i],1,0,'C',true); $this->Ln(); //Color and font restoration $this->SetFillColor(224,235,255); $this->SetTextColor(0); $this->SetFont(''); //Data $fill=false; foreach($data as $row) { $this->Cell($w[0],6,$row[0],'LR',0,'L',$fill); $this->Cell($w[1],6,$row[1],'LR',0,'L',$fill); $this->Cell($w[2],6,number_format($row[2]),'LR',0,'R',$fill); $this->Cell($w[3],6,number_format($row[3]),'LR',0,'R',$fill); $this->Ln(); $fill=!$fill; } $this->Cell(array_sum($w),0,'','T'); } } ?>
  23. You know its not PHP yet you posted here! doesn't sounds logical!
  24. Basically $database->loadObjectList(); isn't passing an array can you add the following to give some more info $rows = $database->loadObjectList(); var_dump($rows); //add this foreach ($rows as $row ) { and you post the message you get back (just before the "Invalid argument supplied for foreach()")
×
×
  • 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.