Jump to content

sasa

Staff Alumni
  • Posts

    2,804
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by sasa

  1. try <?php $qa = array( "q" => array('sean is', 'kelsey is', 'I love'), "a" => array('kelseys bf', 'seans gf', 'sean') ); $keys = array_keys($qa['q']); shuffle($keys); $question = $qa['q'][$keys[0]]; $answer= $qa['a'][$keys[0]]; echo $question; echo $answer; ?>
  2. what you want to script do? but you say:
  3. try <?php function new_order($a){ $out = array(); $n = count($a) / 2; foreach ($a as $k => $v){ $m = $n; $newk = 0; while ($k > 0){ $newk += ($k % 2) * $m; $k = (int) $k / 2; $m = $m / 2; } $out[$newk] = $v; } ksort($out); return $out; } $a = array(1,2,3,4,5,6,7,; $b = new_order($a); print_r($b); ?>
  4. try SELECT sum( hours ) hr, sum( mileage ) ml, IF ( billable = '', 'no', billable )bill, IF ( remote_bench = '', 'no', remote_bench )rb FROM `tblhours` WHERE 1 GROUP BY bill, rb
  5. try <?php $a = '12-what-is-clonable-interface-in-java/'; preg_match('/^([0-9]+)-(.+)$/',$a,$b); echo $b[1], "\n<br />\n", $b[2]; ?>
  6. you must add sigle qoute around string type data Try $insertSQL = sprintf("INSERT INTO projects (proj_name, proj_desc, sponsor, priority, division, writer, sme, progress, status, due) VALUES ('".$_POST['proj_name']."', '".$_POST['desc']."', '".$_POST['sponsor']."', '".$_POST['priority']."', '".$_POST['div']."', '" .$_POST['writer']."', '".$_POST['sme']."', '".$progress."', 'Open', '".$mysqlFormat."'");
  7. sasa

    Code Help

    change $captain = escape_data($_POST['captain']); $vice_captain = escape_data($_POST['vicecaptain']); $wicketkeeper = escape_data($_POST['wicketkeeper']); to $captain = isset($_POST['captain']) ? escape_data($_POST['captain']) : ''; $vice_captain = isset($_POST['vicecaptain']) ? escape_data($_POST['vicecaptain']) : ''; $wicketkeeper = isset($_POST['wicketkeeper']) ? escape_data($_POST['wicketkeeper']) : '';
  8. in the end of else part add line break; } else { //from bottom up, I'm assuming j+1 is clear since I NULL it if anything was once there and if it was the last spot that was compared then that spot+1 should be empty to add to $searchhits[$j+1]=$hits; $searchresults[$j+1]=$searchresultdata; break; }
  9. try $category='cat1'; $query = "SELECT product_name,id,categories from products WHERE FIND_IN_SET('$category', categories)"; $result = mysql_query($query) or die(mysql_error()); while($row = MySQL_fetch_assoc($result)){ echo imlope(' - ', $row), '<br />'; }
  10. try <?php $names_in_form = 50; //change this number if (isset($_POST['submit'])) { $out = array(); for ($i = 1; $i <= $names_in_form; $i++){ $var_name = 'name_'.$i; if ($_POST[$var_name]) $out[] = $var_name.'='.$_POST[$var_name]; } $out = implode('&', $out); $h = fopen("names.txt",'w'); fwrite($h, $out); fclose($h); } if(file_exists("names.txt")){ $names = file_get_contents("names.txt"); $names1 = explode('&',$names); $names = array(); foreach ($names1 as $name){ $name = explode('=',$name); $names[$name[0]] = $name[1]; } } else $names = array(); echo '<form method="POST" action="">',"\n"; for ($i = 1; $i <= $names_in_form; $i++){ $var_name = 'name_'.$i; echo 'Name ', $i, ' <input type="text" name="',$var_name, '" value="',$x = array_key_exists($var_name,$names) ? $names[$var_name] : '' ,'"><br />',"\n"; } echo ' <input type="submit" name="submit" value="Submit"> </form>'; if (isset($_POST['submit'])) echo '<h2>In file write: ', $out,'</h2>'; ?>
  11. In your $array_test you don't have multiple value for some key, just last one try <?php $array_test = array('111' => 'first one', '111' => 'middle one', '111' => 'last one', '222' => 'first one', '222' => 'last one', '333' => 'first one', '444' => 'first one'); echo '<pre>'; print_r($array_test); echo '</pre>'; ?>
  12. //$to = (($page * $limit) - $limit + 40); $to = $page * $limit > $totalrows ? $totalrows : $page * $limit; $from = (($page * $limit) - $limit + 1); echo 'Currently viewing ' . $from. ' to ' . $to. ' of ' . $totalrows . ' available mobile phone deals';
  13. try <?php $a = '$string = "blab blab some useless html tags here <strong>Downloads:</strong> 1,826 </p> and some other ";'; preg_match('/Downloads:<\/strong>(.*)<\/p>/s', $a, $b); echo $b = preg_replace('/[^0-9]/', '', $b[1]); ?>
  14. change: $totalrows = mysql_num_rows($result_count); to $totalrows = mysql_result($result_count,0,0); $pageprev = $page--; to $pageprev = $page-1; $pagenext = $page+1; to $pagenext = $page+1;
  15. try SELECT * FROM contact WHERE co_id>(SELECT MIN(co_id) FROM contact)
  16. function display($file,$count) { global $columns,$rows; $per_page = $columns * $rows; $no_of_pages = ceil($count / $per_page); if (isset($_GET['page'])) $page = (int) $_GET['page']; else $page = 1; $end = $page * $per_page; $start = $end - $per_page; $max_site = ceil(($columns * $rows) / $count); krsort($file); $act = 0; $i = 0; $xxx = 1; foreach ($file as $time => $fil) { if(++$i > $start and $i <= $end){ ++$act; if ($act > $columns) { echo '</tr><tr><td class="photo"><a href="'.getNormalImage($fil).'"><img src="'.$fil.'" alt="'.$fil.'"/></a></td>'; $act = 1; $xxx++; } else { echo '<td class="photo"><a href="'.getNormalImage($fil).'"><img src="'.$fil.'" alt="'.$fil.'"/></a></td>'; } } } echo '</tr></table>'; $margin = ($rows - $xxx) * 124; echo '<div align="center" class="page_number" style="margin-top:',$margin,'px;">'; if ($page > 1) echo ' <a href="?page=1">First Page</a> '; else echo ' First Page '; if ($page > 1) echo ' <a href="?page=',$page-1,'"><<</a> '; else echo ' << '; $midle_page = $page; if ($page < 3) $midle_page = 3; else if ($no_of_pages - $page < 2) $midle_page = $no_of_pages - 2; for ($i = 1; $i <= $no_of_pages; $i++) if(abs($midle_page - $i) <= 2) if($i != $page) echo ' <a href="?page=',$i,'">',$i, '</a> '; else echo ' ',$i, ' '; if ($page < $no_of_pages) echo ' <a href="?page=',$page+1,'">>></a> '; else echo ' >> '; if ($page < $no_of_pages) echo ' <a href="?page=',$no_of_pages,'">Last Page</a> '; else echo ' Last Page '; echo '</div>'; }
  17. function display($file,$count) { global $columns,$rows; $per_page = $columns * $rows; $no_of_pages = ceil($count / $per_page); if (isset($_GET['page'])) $page = (int) $_GET['page']; else $page = 1; $end = $page * $per_page; $start = $end - $per_page; $max_site = ceil(($columns * $rows) / $count); krsort($file); $act = 0; $i = 0; foreach ($file as $time => $fil) { if(++$i > $start and $i <= $end){ ++$act; if ($act > $columns) { echo '</tr><tr><td class="photo"><a href="'.getNormalImage($fil).'"><img src="'.$fil.'" alt="'.$fil.'"/></a></td>'; $act = 1; } else { echo '<td class="photo"><a href="'.getNormalImage($fil).'"><img src="'.$fil.'" alt="'.$fil.'"/></a></td>'; } } } echo '</tr></table>'; echo '<div align="center" class="page_number">'; if ($page > 1) echo ' <a href="?page=1">First Page</a> '; else echo ' First Page '; if ($page > 1) echo ' <a href="?page=',$page-1,'"><<</a> '; else echo ' << '; $midle_page = $page; if ($page < 3) $midle_page = 3; else if ($no_of_pages - $page < 2) $midle_page = $no_of_pages - 2; for ($i = 1; $i <= $no_of_pages; $i++) if(abs($midle_page - $i) <= 2) if($i != $page) echo ' <a href="?page=',$i,'">',$i, '</a> '; else echo ' ',$i, ' '; if ($page < $no_of_pages) echo ' <a href="?page=',$page+1,'">>></a> '; else echo ' >> '; if ($page < $no_of_pages) echo ' <a href="?page=',$no_of_pages,'">Last Page</a> '; else echo ' Last Page '; echo '</div>'; }
  18. change function display function display($file,$count) { global $columns,$rows; $per_page = $columns * $rows; $no_of_pages = ceil($count / $per_page); if (isset($_GET['page'])) $page = (int) $_GET['page']; else $page = 1; $end = $page * $per_page; $start = $end - $per_page; $max_site = ceil(($columns * $rows) / $count); krsort($file); $act = 0; $i = 0; foreach ($file as $time => $fil) { if(++$i > $start and $i <= $end){ ++$act; if ($act > $columns) { echo '</tr><tr><td class="photo"><a href="'.getNormalImage($fil).'"><img src="'.$fil.'" alt="'.$fil.'"/></a></td>'; $act = 1; } else { echo '<td class="photo"><a href="'.getNormalImage($fil).'"><img src="'.$fil.'" alt="'.$fil.'"/></a></td>'; } } } echo '</tr></table>'; if ($page > 1) echo ' <a href="?page=1">First Page</a> '; else echo ' First Page '; if ($page > 1) echo ' <a href="?page=',$page-1,'"><<</a> '; else echo ' << '; $midle_page = $page; if ($page < 3) $midle_page = 3; else if ($no_of_pages - $page < 2) $midle_page = $no_of_pages - 2; for ($i = 1; $i <= $no_of_pages; $i++) if(abs($midle_page - $i) <= 2) if($i != $page) echo ' <a href="?page=',$i,'">',$i, '</a> '; else echo ' ',$i, ' '; if ($page < $no_of_pages) echo ' <a href="?page=',$page+1,'">>></a> '; else echo ' >> '; if ($page < $no_of_pages) echo ' <a href="?page=',$no_of_pages,'">Last Page</a> '; else echo ' Last Page '; }
  19. try <?php $thumb_size = 100; $columns = 5; $rows = 2; $dir = '.'; function resizeImage($source) { global $thumb_size; $size = getimagesize($source); $width = $size[0]; $height = $size[1]; if($width > $height) { $x = ceil(($width - $height) / 2 ); $width = $height; } elseif($height > $width) { $y = ceil(($height - $width) / 2); $height = $width; } $new_im = imagecreatetruecolor($thumb_size,$thumb_size); $im = imagecreatefromjpeg($source); imagecopyresampled($new_im,$im,0,0,$x,$y,$thumb_size,$thumb_size,$width,$height); return $new_im; } function generateThumbnails($dir='.'){ // Open the actual directory if ($handle = opendir($dir)) { // Read all file from the actual directory while ($file = readdir($handle)) { // Check whether tha actual item is a valid file if (is_file($file)){ // Check whether the actual image is a thumbnail if (strpos($file,'_th.jpg')){ $isThumb = true; } else { $isThumb = false; } if (!$isThumb) { // Process the file string $dirName = substr($file,0,strpos($file,basename($file))); if (strlen($dirName) < 1) $dirName = '.'; $fileName = basename($file); $fileMain = substr($fileName,0,strrpos($fileName,'.')); $extName = substr($fileName,strrpos($fileName,'.'),strlen($fileName)-strrpos($fileName,'.')); // Check if the actual file is a jpeg image if (($extName == '.jpg') || ($extName == '.jpeg')){ $thmbFile = $dirName.'/'.$fileMain.'_th.jpg'; // If a thumbnail dosn't exists tahn create a new one if (!file_exists($thmbFile)){ imagejpeg(resizeImage($file),$thmbFile,80); } } } } } } } function getNormalImage($file){ $base = substr($file,0,strrpos($file,'_th.jpg')); if (file_exists($base.'.jpg')) return $base.'.jpg'; elseif (file_exists($base.'.jpeg')) return $base.'.jpeg'; else return ""; } function displayPhotos($dir = '.'){ global $columns,$bilde; generateThumbnails($dir); // Open the actual directory if ($handle = opendir($dir)) { // Read all file from the actual directory while ($file = readdir($handle)) { // Check whether tha actual item is a valid file if (is_file($file)){ // Check whether the actual image is a thumbnail if (strpos($file,'_th.jpg')){ $fil = ereg_replace("_th.jpg",".jpg",$file); $time = filemtime($fil); $normal = getNormalImage($file); $bilde[$time] = $file; } } } if (isset($bilde)) { $count = count($bilde,1); display($bilde,$count); } else { echo "Det er desverre ikke noen bilder her!"; } } } function display($file,$count) { global $columns,$rows; $per_page = $columns * $rows; $no_of_pages = ceil($count / $per_page); if (isset($_GET['page'])) $page = (int) $_GET['page']; else $page = 1; $end = $page * $per_page; $start = $end - $per_page; $max_site = ceil(($columns * $rows) / $count); krsort($file); $act = 0; $i = 0; foreach ($file as $time => $fil) { if(++$i > $start and $i <= $end){ ++$act; if ($act > $columns) { echo '</tr><tr><td class="photo"><a href="'.getNormalImage($fil).'"><img src="'.$fil.'" alt="'.$fil.'"/></a></td>'; $act = 1; } else { echo '<td class="photo"><a href="'.getNormalImage($fil).'"><img src="'.$fil.'" alt="'.$fil.'"/></a></td>'; } } } echo '</tr></table>'; if ($page > 1) echo ' <a href="?page=',$page-1,'">prev</a> '; else echo ' prev '; for ($i = 1; $i <= $no_of_pages; $i++) if($i != $page) echo ' <a href="?page=',$i,'">',$i, '</a> '; else echo ' ',$i, ' '; if ($page < $no_of_pages) echo '<a href="?page=',$page+1,'"> next </a>'; else echo ' next '; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd"> <html> <head> <title>Cecilie Løvvold Photography</title> <link href="../style/style.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="main"> <div class="caption">Landskap</div> <table align="center"><tr> <?php displayPhotos(); ?> </div> </body>
  20. You mast change test.html from <html><head></head> <body> <img border="0" src="Image.jpg" width="450" height="350"> </body> </html> to <html><head></head> <body> <img border="0" src="/content/Image.jpg" width="450" height="350"> </body> </html> use full path for jour pictures
  21. or echo $new_date = $explode_date[1].$explode_date[2].$explode_date[0] % 100;echo $new_date = $explode_date[1].$explode_date[2].substr($explode_date[0],-2);
  22. insert line mysql_data_seek($result,0); befor table 8, 3 and 4
  23. in main page your inlude must be include ($_SERVER['DOCUMENT_ROOT'] .'/'.$_GET['go']); in test.html you use <img src="/content/image.jpg">
×
×
  • 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.