Jump to content

sasa

Staff Alumni
  • Posts

    2,804
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by sasa

  1. you must pass values to your function like this <?php require_once("samoi.php"); // which has the information of the database. $username = $_POST['username']; $password = $_POST['password']; function samoi($username, $password){ // add start function block and function variables if(!$username || !$password) { echo "Insert inputs"; } else { $sql_insert = "INSERT INTO sam (username, password) VALUES ('$username', '$password')"; $qry_insert = mysql_query($sql_insert); echo "the data has been saved!"; } } // end function block samoi($username, $password); //call function with values ?>
  2. where is object $cartweaver created
  3. add WHERE `user` = 'some value' to you query
  4. try <?php foreach ($routes as $key => $val){ foreach ($val as $key2 => $val2){ $routes_new[$key][$key2] = str_replace('cats', $row['link'], $val2); } } ?>
  5. create script navbar.php <?php $navbar = array( 'solar' => 'solarpower.php', 'wind' => 'windpower.php', 'nuclear' => 'nuclearpower.php', 'bio' => 'biofuel.php', 'hibrids' => 'hybridcars.php', 'hydrogen' => 'hydrogenpower.php', 'about' => 'about.php', 'blog' => 'blog.php' ); $a = explode('/',$_SERVER['SCRIPT_NAME']); $activ_link = array_pop($a); foreach ($navbar as $text => $link){ $class = $activ_link == $link ? 'navlinkactive' : 'navlink'; echo "<div class='$class'><a href='$link'>$text</a></div>\n"; } ?> and include it in your scripts
  6. are you want to resize name ( from 'abcdefgh' to 'abc') or you want to change font size
  7. ups i make kistake code must be <pre><?php /* 1 67 20 107 43 116 77 153 125 161 */ $data = <<<DATA {loop} Some data {loop} Nested data {loop} More nests! {/loop} {loop} Another deep nest {/loop} {/loop} {loop} Not quite so deep {/loop} {/loop} {loop} More data {loop} Foobar {/loop} {loop} Warmer {loop} Waaaarmer {loop} Too hot! {/loop} {/loop} {/loop} {loop} More depth {loop} this is getting stupid {/loop} {/loop} {/loop} DATA; $time = microtime(1); for ($i=0; $i <100;$i++){ $pairs = getPairs($data, '{loop}', '{/loop}'); } echo 'getPairs - ', microtime(1) - $time,"\n"; $time = microtime(1); for ($i=0; $i <100;$i++){ $pairs = my_getPairs($data, '{loop}', '{/loop}'); } echo 'my_getPairs - ', microtime(1) - $time, "\n"; $time = microtime(1); for ($i=0; $i <100;$i++){ $pairs = my_getPairs1($data, '{loop}', '{/loop}'); } echo 'my_getPairs1 - ',microtime(1) - $time; //foreach( $pairs as $pair ) // echo substr( $data, $pair[0], $pair[1]-$pair[0] ) . "\n\n\n--------\n\n\n"; function getPairs( $data, $openTag, $closeTag ) { $opening = getOffsets( $data, $openTag ); $closing = getOffsets( $data, $closeTag, FALSE ); if( ($size = count($opening)) !== count($closing) ) die( "Invalid syntax detected" ); $offsets = array(); for( $i = 1; $i < $size; $i++ ) { static $last = 0; if( isset($opening[$i+1]) === FALSE || $opening[$i+1] > $closing[$i] ) { $offsets = array_merge( $offsets, parseNest(array_slice($opening,$last,$i-$last+1), array_slice($closing,$last,$i-$last+1)) ); $last = $i+1; } } return $offsets; } function getOffsets( $data, $tag, $open = TRUE ) { $return = array(); $offset = 0; while( ($c = strpos($data, $tag, $offset)) !== FALSE ) { $offset = strpos( $data, $tag, $c ) + 1; $return[] = $offset - 1 + ( $open == TRUE ? strlen($tag) : -1 ); } return $return; } function parseNest( $opening, $closing ) { $pairs = array(); foreach( array_reverse($opening) as $oVal ) { foreach( $closing as $cKey => $cVal ) if( $oVal < $cVal ) { $pairs[] = array( $oVal, $cVal ); unset( $closing[$cKey] ); break; } } return array_reverse( $pairs ); } function my_getPairs1($data, $openTag, $closeTag){ $out = array(); $stack = array(); $offset = 0; $l = strlen($openTag); $a = strpos($data, $openTag, $offset); $b = strpos($data, $closeTag, $offset); $count = 0; while($a !== false or $b !== false){ if ($a!==false and $a<$b){ $offset = $a + $l; $stack[++$count] = $offset; $a = strpos($data, $openTag, $offset); } else { if ($count < 1) die('Invalid syntax detected.'); $out[] = array($stack[$count--] , $b); // i change this line $offset = $b + 1; $b = strpos($data, $closeTag, $offset); } } if ($count!=0) die('Invalid syntax detected'); sort($out); return $out; } function my_getPairs($data, $openTag, $closeTag){ $out = array(); $stack = array(); $offset = 0; $l = strlen($openTag); $a = stripos($data, $openTag, $offset); $b = stripos($data, $closeTag, $offset); $count = 0; while(1){ if ($a===false and $b===false) break; if ($a!==false and $a<$b){ array_push($stack, $a + $l); $count++; $offset = $a + 1; $a = stripos($data, $openTag, $offset); } else { if ($count < 1) die('Invalid syntax detected.'); $out[] = array(array_pop($stack), $b); $count--; $offset = $b + 1; $b = stripos($data, $closeTag, $offset); } } if ($count!=0) die('Invalid syntax detected'); sort($out); return $out; } ?></pre>
  8. i speedup my code (change stripos to strpos) and do some check <pre><?php /* 1 67 20 107 43 116 77 153 125 161 */ $data = <<<DATA {loop} Some data {loop} Nested data {loop} More nests! {/loop} {loop} Another deep nest {/loop} {/loop} {loop} Not quite so deep {/loop} {/loop} {loop} More data {loop} Foobar {/loop} {loop} Warmer {loop} Waaaarmer {loop} Too hot! {/loop} {/loop} {/loop} {loop} More depth {loop} this is getting stupid {/loop} {/loop} {/loop} DATA; $time = microtime(1); for ($i=0; $i <100;$i++){ $pairs = getPairs($data, '{loop}', '{/loop}'); } echo 'getPairs - ', microtime(1) - $time,"\n"; $time = microtime(1); for ($i=0; $i <100;$i++){ $pairs = my_getPairs($data, '{loop}', '{/loop}'); } echo 'my_getPairs - ', microtime(1) - $time, "\n"; $time = microtime(1); for ($i=0; $i <100;$i++){ $pairs = my_getPairs1($data, '{loop}', '{/loop}'); } echo 'my_getPairs1 - ',microtime(1) - $time; //foreach( $pairs as $pair ) // echo substr( $data, $pair[0], $pair[1]-$pair[0] ) . "\n\n\n--------\n\n\n"; function getPairs( $data, $openTag, $closeTag ) { $opening = getOffsets( $data, $openTag ); $closing = getOffsets( $data, $closeTag, FALSE ); if( ($size = count($opening)) !== count($closing) ) die( "Invalid syntax detected" ); $offsets = array(); for( $i = 1; $i < $size; $i++ ) { static $last = 0; if( isset($opening[$i+1]) === FALSE || $opening[$i+1] > $closing[$i] ) { $offsets = array_merge( $offsets, parseNest(array_slice($opening,$last,$i-$last+1), array_slice($closing,$last,$i-$last+1)) ); $last = $i+1; } } return $offsets; } function getOffsets( $data, $tag, $open = TRUE ) { $return = array(); $offset = 0; while( ($c = strpos($data, $tag, $offset)) !== FALSE ) { $offset = strpos( $data, $tag, $c ) + 1; $return[] = $offset - 1 + ( $open == TRUE ? strlen($tag) : -1 ); } return $return; } function parseNest( $opening, $closing ) { $pairs = array(); foreach( array_reverse($opening) as $oVal ) { foreach( $closing as $cKey => $cVal ) if( $oVal < $cVal ) { $pairs[] = array( $oVal, $cVal ); unset( $closing[$cKey] ); break; } } return array_reverse( $pairs ); } function my_getPairs1($data, $openTag, $closeTag){ $out = array(); $stack = array(); $offset = 0; $l = strlen($openTag); $a = strpos($data, $openTag, $offset); $b = strpos($data, $closeTag, $offset); $count = 0; while($a !== false or $b !== false){ if ($a!==false and $a<$b){ $offset = $a + $l; $stack[++$count] = $offset; $a = strpos($data, $openTag, $offset); } else { if ($count < 1) die('Invalid syntax detected.'); $out[] = array($stack[--$count] , $b); $offset = $b + 1; $b = strpos($data, $closeTag, $offset); } } if ($count!=0) die('Invalid syntax detected'); sort($out); return $out; } function my_getPairs($data, $openTag, $closeTag){ $out = array(); $stack = array(); $offset = 0; $l = strlen($openTag); $a = stripos($data, $openTag, $offset); $b = stripos($data, $closeTag, $offset); $count = 0; while(1){ if ($a===false and $b===false) break; if ($a!==false and $a<$b){ array_push($stack, $a + $l); $count++; $offset = $a + 1; $a = stripos($data, $openTag, $offset); } else { if ($count < 1) die('Invalid syntax detected.'); $out[] = array(array_pop($stack), $b); $count--; $offset = $b + 1; $b = stripos($data, $closeTag, $offset); } } if ($count!=0) die('Invalid syntax detected'); sort($out); return $out; } ?></pre> output in my local wamp is getPairs - 0.020164012908936 my_getPairs - 0.080213069915771 my_getPairs1 - 0.010028839111328 btw. way you use variable $last as static?
  9. try <?php $string = trim($_POST['barCode']); //$string = 'SNPL12345'; echo preg_match('/^SNPL[0-9]{5,5}$/',$string) ? 'true' : 'false'; ?>
  10. look http://www.php.net/manual/en/function.imagettfbbox.php and users notes
  11. try this <pre> <?php $data = <<<DATA {loop} Some data {loop} Nested data {loop} More nests! {/loop} {loop} Another deep nest {/loop} {/loop} {loop} Not quite so deep {/loop} {/loop} {loop} More data {loop} Foobar {/loop} {loop} Warmer {loop} Waaaarmer {loop} Too hot! {/loop} {/loop} {/loop} {loop} More depth {loop} this is getting stupid {/loop} {/loop} {/loop} DATA; $pairs = my_getPairs($data, '{loop}', '{/loop}'); foreach( $pairs as $pair ) echo substr( $data, $pair[0], $pair[1]-$pair[0] ) . "\n\n\n--------\n\n\n"; function my_getPairs($data, $openTag, $closeTag){ $out = array(); $stack = array(); $offset = 0; $l = strlen($openTag); $a = stripos($data, $openTag, $offset); $b = stripos($data, $closeTag, $offset); $count = 0; while(1){ if ($a===false and $b===false) break; if ($a!==false and $a<$b){ array_push($stack, $a + $l); $count++; $offset = $a + 1; $a = stripos($data, $openTag, $offset); } else { if ($count < 1) die('Invalid syntax detected.'); $out[] = array(array_pop($stack), $b); $count--; $offset = $b + 1; $b = stripos($data, $closeTag, $offset); } } if ($count!=0) die('Invalid syntax detected'); sort($out); return $out; } ?> </pre>
  12. add enctype="multipart/form-data" in form tag
  13. try <?php $a = array( 2, 29, 54, 77 ); $b = array( 66, 72, 102, 107 ); $edge = array(); foreach ($a as $v) $edge[$v] = 1; foreach ($b as $v) $edge[$v] = -1; ksort($edge); $count = 0; $starts = array(); foreach ($edge as $k => $v){ $count += $v; if ($count<0)die('Data error'); if($v < 0){ $pair[] = array(array_pop($starts),$k); } else array_push($starts, $k); } if ($count != 0) die('Data error'); print_r($pair); ?>
  14. you need separate table for country and cites
  15. try // hiii mkdir ("./$userid/", 0755, true); $myFile = "./$userid/index.php"; $fh = fopen($myFile, 'w') or die("can't open file"); $filename = "./$userid/index.php"; $somecontent = ' <?php $con = mysql_connect(\'localhost\',\'root\',''); if (!$con) { die(\'Could not connect: \' . mysql_error()); } mysql_select_db("signup", $con); $result = mysql_query("SELECT * FROM user_signup where userid=\'$userid\'"); while($row = mysql_fetch_array($result)) { echo $row[\'email\'] . " " . $row[\'name\']; echo "<br />"; } mysql_close($con); ?> '; // Let's make sure the file exists and is writable first. //if (is_writable($filename)) { // In our example we're opening $filename in append mode. // The file pointer is at the bottom of the file hence // that's where $somecontent will go when we fwrite() it. if (!$handle = fopen($filename, 'a')) { echo "Cannot open file ($filename)"; exit; } // Write $somecontent to our opened file. if (fwrite($handle, $somecontent) === FALSE) { echo "Cannot write to file ($filename)"; exit; } echo "Success"; fclose($handle); //hiii
  16. try<?php $t = microtime(1); for ($i=0;$i<100000;$i++); echo microtime(1)-$t,"\n"; $t = microtime(1); $b = count($a); for ($i=0;$i<100000;++$i); echo microtime(1)-$t,"\n"; ?>
  17. 1st change form to <?php echo "<form name='form1' method='post' action='insert.php'>\n"; echo "<table border=\"0\" width=\"500\" cellpadding=\"3\" cellspacing=\"3\"> <tr> <td align='center'>Event</td> <td>Time</td> <td>Result</td> </tr>"; $query1 = mysql_query("SELECT * FROM `football` WHERE `date` = '$today' && `time` < '$time' ORDER BY `football`.`time` ASC"); $num_rows = mysql_num_rows($query1); echo $num_rows; if($query1 >=1) { while($row = mysql_fetch_assoc($query1)) { echo "<tr> <td align='center'>$row[home_team] Vs $row[away_team]</td> <td>$row[time]</td> <td><input type=\"text\" size=\"10\" name=\"result[".$row['game_id']."]\" /></td> </tr> "; } echo "</table><br>"; echo "<input type='submit' name='submit' value='Submit'>\n"; echo "</form>\n"; } else echo"error"; ?> and <?php $checkEmpty = 0; //counter to keep track of the amount of empty rows submitted. $success = array(); //keep records that were successfully inserted into DB for success msg. //$query1 = mysql_query("SELECT * FROM `football` WHERE `date` = '$today' && `time` < '$time' ORDER BY `football`.`time` ASC"); $num_rows = count($_POST['result']); //for ($i = 0; $i < $num_rows; ++$i) foreach ($_POST['result'] as $game_id => $result) { $result = mysql_real_escape_string($result); if (empty($result)) { ++$checkEmpty; //count each empty row continue; } else { //while($row = mysql_fetch_assoc($query1)) //{ //$game_id = $row[game_id]; $sql= mysql_query("UPDATE `football` SET `result`='$result' WHERE `date` = '$today' && `time` < '$time' && `game_id`='$game_id'"); $success[] = $result; //} } } //if all 5 rows were empty, echo the error msg. else, print success msg echo ((count($success) == 0) ? ("You can't send a blank form") : ("The following records are added:<br><br>")); echo "'", implode("', '", $success),"'<br />\n"; //print information that was added to the DB echo "<br><br>"; echo "<b>$num_rows</b>"; mysql_close($con) ?>
  18. are you change value of variable $checks to 20?
  19. try <?php $test = 'aas,df?asd.,xxx'; $t = microtime(1); for ($i=0;$i<10000;$i++){ $foo = split(',|\.|\?',$test); } echo 'split: ',microtime(1)-$t,"\n"; $t = microtime(1); for ($i=0;$i<10000;$i++){ $foo = preg_split('/,|\.|\?/',$test); } echo 'preg_split: ',microtime(1)-$t,"\n"; ?> on my mychine otput is split: 0.23552489280701 preg_split: 0.32364296913147
  20. $result = split(',|\.|\?',$para);
  21. look coments in code <?php include 'library/config.inc.php'; $conn=mysql_connect($dbhost, $dbuser, $dbpass) or die('Error connecting to mysql'); mysql_select_db($dbnamemain); $query1=mysql_query("SELECT folder_id, fol_name FROM folders JOIN cabinets ON(cabinets.cabinet_id=folders.cabinet_id) WHERE cab_name='Bills' ORDER BY fol_name ASC ") or die(mysql_error()); $col_width=100/count($row=mysql_fetch_array($query1)); // in vaiable $row is 1st row of data (credit card) // change to $col_width=100/mysql_num_rows($query1); while($row=mysql_fetch_array($query1)) { // in vaiable $row is 2nd row of data (internet) $query2=mysql_query("SELECT bill_date_due, bill_amount FROM items WHERE folder_id=$row[folder_id] ORDER BY bill_date_due ASC ") or die(mysql_error()); $dataset=array(); while(list($date,$amt)=mysql_fetch_row($query2)) { $t=strtotime($date); $values=array ("year"=>date('Y',$t), "month"=>date('m',$t), "amount"=>$amt); $dataset[$values[month]]=$values[amount]; } $filename="images/graphs/$row[folder_id]$values[year].png"; if($dataset!=NULL) { ignore this code } echo "<table width='100%' align='center' border='1'> <tr>"; // move this line before 1st while while($row=mysql_fetch_array($query1)) {// in vaiable $row is 3rd row of data (telephone) and goes to end // remove this line echo "<th width='$col_width%'>$row[fol_name]</th>"; } // and remove this too echo "</tr></table>"; //move this line after end of while loop //else { echo "<i>Not data entered for this bill folder!</i>"; } //echo "<p>"; } mysql_close($conn); ?>
  22. try <?php $foo = $site; for($i = 1; $i <= $checks; $i++) if (!$site[$i]) unset($foo[$i]); $foo = array_values($foo); print_r($foo); ?> or look my last post
  23. try while ($row = mysql_fetch_row($result)){ $status[$row[1]][] = array( "boss" => $row[2], "comp" => $row[3], ) }
  24. change names of ALL checkbox to name="url[]" and try to print_r($_POST['url']);
×
×
  • 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.