sasa
Staff Alumni-
Posts
2,804 -
Joined
-
Last visited
-
Days Won
1
Everything posted by sasa
-
try[code]<?php $a = array('07:43:09','11:51:51'); $total = 0; foreach ($a as $b){ $x = explode(':',$b); $tmp = 0; foreach ($x as $c) {$tmp = $tmp * 60 + $c;} $total += $tmp; } $out = array(); for ($i=0; $i<3; $i++){ $t = floor($total / 60); $out[] = sprintf( "%02d", $total - $t * 60); $total = $t; } echo $out = implode(':',array_reverse($out)); ?>[/code]
-
1st change names of your checkbox - add [] in the end of name (name="NES" => name="NES[]" etc.) [code] $total = 0; foreach ($_PRICES as $name => $price) { $total += count($_POST[$name]) * $price; } echo $total; [/code]
-
it works fine in my machine in PHP 4.4.1 and PHP 5.1.1
-
sorry i just check query not the rest of code working code [code]//$GET=1;//for testing $sql = "SELECT users.id AS id, users.avatar AS avatar, users.firstn AS firstn, users.lastn AS lastn FROM friends LEFT JOIN users on users.id=IF(friendid = '$GET',friendid2,friendid) WHERE friendid = '$GET' OR friendid2 = '$GET'"; $result = mysql_query($sql); while ($play = mysql_fetch_assoc($result)) echo "<a href='viewprofile.php?id=$play[id]'><img src='$play[avatar]' border='0' height='85' width='85'><br>$play[firstn] $play[lastn]</a><br><br>";[/code]
-
use ceil() function [code]$totalpages = ceil($numofpages);[/code]
-
try[code]$sql = "SELECT users.id AS id, users.avatar AS avatar, users.firstn AS firstn, users.lastn AS lastn FROM friends LEFT JOIN users on users.id=IF(friendid = '$GET',friendid2,friendid) WHERE friendid = '$GET' OR friendid2 = '$GET'" $result = mysql_query($sql); while ($play = mysql_fetch_assoc($result) echo "<a href='viewprofile.php?id=$play2[id]'><img src='$play2[avatar]' border='0' height='85' width='85'><br>$play2[firstn] $play2[lastn]</a><br><br>";[/code]
-
try[code]<?php $row=array('space1'=>11,'space2'=>12,'space1pic'=>21,'space2pic'=>22); for ($i=1;$i<3;$i++) { $a = 'space'.$i; echo $row[$a]; echo "<br />\n"; // or echo $row['space'.$i.'pic']; echo "<br />\n"; } ?>[/code]
-
try[code]<?php $search = array("a","b","c","g","s"); $replace = array("apple","boy","cat","girl","snake"); $a = array_combine($search,$replace); $r = mysql_query("SELECT `id`,`the_field` FROM `the_table`") or die(mysql_error()); while($rr = mysql_fetch_assoc($r)) { $r = explode('||',$rr['the_field']); $out = array(); foreach ($r as $d) if (array_key_exists($d,$a)) $out[]=$a[$d]; else $out[]=$d; $out = implode('||',$out); mysql_query("UPDATE `the_table` SET `the_field`='$out' WHERE `id`='$rr[id]'") or die(mysql_error()); } ?>[/code]
-
try[code]echo number_format($total,2);[/code]
-
try[code]<?php $t='2006-12-30 19:50:31'; echo date('h:ia',strtotime($t)); ?>[/code]
-
try[code]<?php $t=15.05; printf("%d:%02d",floor($t),round(($t-floor($t))*60)); ?>[/code]
-
look http://www.server2go-web.de/
-
or[code]array_push($personArray, array('name'=>$name,'age'=>$age));[/code]
-
[code]try to close this if block [if (!$result){ mysql_error(); return false; }[/code]
-
try [code] ... if ( "peter" == trim($names[$num]) ) ...[/code]
-
try to change lines [code]<form ... name="form_paypall">[/code]to [code]<form ... id="form_paypall">[/code] and [code]document.form_paypal.submit();[/code]to[code]document.getElementById('form_paypall').submit()[/code]
-
*SOLVED* need help with arrays / counting / logic
sasa replied to jsims281forum's topic in PHP Coding Help
try[code]<?php $w[1]="one two none one one xx prpr one none"; $w[2]="one two one none none xxxx one none none"; $word_array[1] = explode(' ',$w[1]); $word_array[2] = explode(' ',$w[2]); $shared = array_intersect($word_array[1], $word_array[2]); for ($i=1; $i<3; $i++) { foreach ($word_array[$i] as $a) { if (in_array($a, $shared)) $out[$a][$i]++; } } echo ' <table border="2"> <tr> <td>Word</td> <td>count in Tx1</td> <td>count in Tx2</td> </tr>'; foreach ($out as $w => $b) echo " <tr> <td>$w</td> <td>$b[1]</td> <td>$b[2]</td> </tr>"; echo ' </table>'; ?>[/code] -
[code]<?php include("MySQL.php"); ..... // use pager values to fetch data $query = "select * from Table order by Id DESC limit $offset, $limit"; // <= chamge this line $result = mysql_query($query); ... for($ii = 0; $ii < mysql_numrows($result); $ii++) { // change this 3 lines // $ii = $i; // $ii--; echo "<h1>"; echo mysql_result($result,$ii,"Topic"); echo "</h1>"; echo "<p>"; echo mysql_result($result,$ii,"Txt"); echo "</p>"; echo "<p>"; echo mysql_result($result,$ii,"Sender"); echo " - "; echo mysql_result($result,$ii,"Time"); echo "</p>"; } mysql_close(); ?>[/code]
-
try[code]<?php $a=Array( '0' => Array( 'gameid' => '23', 'odds_V+' => '2.85', 'ovun' =>'', 'visitor' => 'PIT', 'home' => 'PHI' ), '1' => Array( 'gameid' => '23', 'odds_V' => '1.85', 'ovun' =>'', 'visitor' => 'PIT', 'home' => 'PHI' ), '2' => Array( 'gameid' => '23', 'odds_T' => '6.0', 'ovun' =>'', 'visitor' => 'PIT', 'home' => 'PHI' ), '3' => Array( 'gameid' => '23', 'odds_H' => '1.75', 'ovun' =>'', 'visitor' => 'PIT', 'home' => 'PHI' ), '4' => Array( 'gameid' => '23', 'odds_H+' => '2.7', 'ovun' =>'', 'visitor' => 'PIT', 'home' => 'PHI' ), '5' => Array( 'gameid' => '23', 'odds_O' => '1.6', 'ovun' => '6.5', 'visitor' => 'PIT', 'home' => 'PHI' ), '6' => Array( 'gameid' => '23', 'odds_U' => '1.8', 'ovun' => '6.5', 'visitor' => 'PIT', 'home' => 'PHI' ), '7' => Array( 'gameid' => '24', 'odds_V' => '2.1', 'ovun' =>'', 'visitor' => 'CROS', 'home' => 'GAGN' ), '8' => Array( 'gameid' => '24', 'odds_T' => '4.0', 'ovun' =>'', 'visitor' => 'CROS', 'home' => 'GAGN' ), '9' => Array( 'gameid' => '24', 'odds_H' => '2.2', 'ovun' =>'', 'visitor' => 'CROS', 'home' => 'GAGN' ), '10' => Array( 'gameid' => '26', 'odds_V' => '2.1', 'ovun' =>'', 'visitor' => 'SULL', 'home' => 'NASH' ), '11' => Array( 'gameid' => '26', 'odds_T' => '4.0', 'ovun' =>'', 'visitor' => 'SULL', 'home' => 'NASH', ), '12' => Array( 'gameid' => '26', 'odds_H' => '2.2', 'ovun' =>'', 'visitor' => 'SULL', 'home' => 'NASH' ) ); foreach ($a as $b) $out[$b['gameid']] = ($out[$b['gameid']]) ? array_merge($out[$b['gameid']], $b) : $out[$b['gameid']] = $b; print_r($out); // or foreach ($out as $b) $out1[] = $b; print_r($out1); ?> [/code]
-
try[code]<?php function strip_slashes($value) { if (is_array($value)) return array_map('strip_slashes', $value); return get_magic_quotes_gpc() ? stripslashes($value) : $value; } $a = array(0,"This\'s an string\'s","This\'s an string\'s",array("This\'s an string\'s",array("This\'s an string\'s","This\'s an string\'s")),"This\'s an string\'s\\","This\'s an string\'s"); print_r( strip_slashes($a)); $b = "This\'s an string\'s"; print_r( strip_slashes($b)); ?>[/code]
-
try strtotime() function
-
$number = ceil($number / 10) * 10;
-
Update form with checkboxes from many to many relation db
sasa replied to JackRabbitSlims's topic in PHP Coding Help
try[code]$sql = "SELECT p.printerId, IF(SUM(r.deptRef = $dep_id),'cheked=\"cheked\"','') as cheked FROM tbl_printer AS p left join tbl_deptprinter as r ON r.printerRef = p.printerId GROUP BY p.printerId";[/code] -
OK try[code]<?php function my_arr_comb($a,$b){ foreach ($a as $key => $value) $out[$value] = $b[$key]; return $out; } $flds2 = array('pname','use','job','edate','sdate'); $flds2a = array('event','userid','event_type','event_finish','received'); $f = my_arr_comb($flds2,$flds2a); // your code // ... foreach ($f as $key => $value) { if (trim(stripslashes($_POST[$key][$i])) != '') echo $qtmp[] = $value . " = '" . mysql_escape_string(trim(stripslashes($_POST[$key][$i]))) . "'"; // etc. } ?>[/code]
-
try[code]<?php $flds2 = array('pname','use','job','edate','sdate'); $flds2a = array('event','userid','event_type','event_finish','received'); $f = array_combine($flds2,$flds2a); // your code // ... foreach ($f as $key => $value) { if (trim(stripslashes($_POST[$key][$i])) != '') $qtmp[] = $value . " = '" . mysql_escape_string(trim(stripslashes($_POST[$key][$i]))) . "'"; // etc. } ?>[/code]