Search the Community
Showing results for tags 'function'.
-
hey guys, so i am messing around with some simple JS, and i was using the onLoad & onUnload handlers. i can easily get the onLoad=(function) to work properly, yet when it comes to getting the onUnload to work when i close the window or refresh the site, noting seems to work <script> function alert1(){ alert("Welcome to the page, enjoy"); } function aler02(){ alert("Thanks for visiting, goodbye"); } </script> <body onLoad="alert01();" onUnload="alert02();"> <p> This is text </p> </body> again when i open the site, it works just fine and as expected. when i close or refresh i expect an alert to let me know i am leaving, yet nothing. any suggestions ?
- 4 replies
-
- javascript
- event handler
-
(and 1 more)
Tagged with:
-
I need help with performance improvement of this script. Script is working fine, but it's quite slow. It loads a lot of data, around 200.000. I am using paging to speed it up, but it's still slow. Can you give me any guide lines how to speed it up or to optimize? //Početak paginga if (isset($_GET['pageno'])) { $pageno = $_GET['pageno']; } else { $pageno = 1; } // if $upit11 = mysql_query("SELECT id FROM kalkulacija_stavke WHERE id_kalkulacija = '$id_kalkulacije' AND kataloski_broj NOT LIKE '1%'") or die (mysql_error()); $brojcanik = mysql_num_rows($upit11); $rows_per_page = 100; $lastpage = ceil($brojcanik/$rows_per_page); $pageno = (int)$pageno; if ($pageno > $lastpage) { $pageno = $lastpage; } // if if ($pageno < 1) { $pageno = 1; } // if $limit = 'LIMIT ' .($pageno - 1) * $rows_per_page .',' .$rows_per_page; mysql_query( "SET NAMES utf8", $veza ); mysql_query( "SET CHARACTER SET utf8", $veza ); if($_SESSION["checked"] = "checked"){ $upit = "SELECT kalkulacija_stavke.*, kalkulacija_zamjene_staro.ne_koristi_se FROM kalkulacija_stavke LEFT JOIN kalkulacija_zamjene_staro ON kalkulacija_stavke.kataloski_broj = kalkulacija_zamjene_staro.kataloski_broj_stari WHERE id_kalkulacija = '$id_kalkulacije' AND ne_koristi_se = '0' AND kataloski_broj NOT LIKE '1%' ORDER BY kataloski_broj ASC $limit"; } else { $upit = "SELECT * FROM kalkulacija_stavke WHERE id_kalkulacija = '$id_kalkulacije' AND kataloski_broj NOT LIKE '1%' ORDER BY kataloski_broj ASC $limit"; } $rezultat = mysql_query($upit,$veza) or die (mysql_error()); while($row = mysql_fetch_array($rezultat)){ $broj = $row["id"]; $id_kalk = $row["id_kalkulacija"]; $id_cjen = $row["id_cjenika"]; $vrijeme = $row["vrijeme"]; $kataloski_broj = trim($row["kataloski_broj"]); $kategorija_artikla = $row["kategorija_artikla"]; $grupa_proizvoda = $row["grupa_proizvoda"]; $podgrupa_proizvoda = $row["podgrupa_proizvoda"]; $cijena_eurska = number_format(round(($row["cijena_EUR"]),2),2,",","."); $cijena_KN = number_format(round(($row["cijena_KN"]),2),2,",","."); $carina = number_format(round(($row["carina"]),2),2,",","."); $spediter = number_format(round(($row["spediter"]),2),2,",","."); $banka = number_format(round(($row["banka"]),2),2,",","."); $transport = number_format(round(($row["transport"]),2),2,",","."); $nabavna_cijena = number_format(round(($row["nabavna_cijena"]),2),2,",","."); $drezga_marza_po_grupi = number_format(round(($row["drezga_marza_po_grupi"]),2),2,",","."); $drezga_zarada = number_format(round(($row["drezga_zarada"]),2),2,",","."); $neto_VPC = number_format(round(($row["neto_VPC"]),2),2,",","."); $neto_MPC = number_format(round(($row["neto_MPC"]),2),2,",","."); $trosak_firme = number_format(round(($row["trosak_firme"]),2),2,",","."); $trosak_firme_p = number_format(round(($row["trosak_firme_p"]),2),2,",","."); $diler_marza_po_grupi = number_format(round(($row["diler_marza_po_grupi"]),2),2,",","."); $preporucena_VPC = number_format(round(($row["preporucena_VPC"]),2),2,",","."); $preporucena_MPC = number_format(round(($row["preporucena_MPC"]),2),2,",","."); $zarada_diler_kn = number_format(round(($row["zarada_diler_kn"]),2),2,",","."); $zarada_diler_p = number_format(round(($row["zarada_diler_post"]),2),2,",","."); $zarada_za_nas_kn = number_format(round(($row["zarada_za_nas_kn"]),2),2,",","."); $zarada_za_nas_p = number_format(round(($row["zarada_za_nas_post"]),2),2,",","."); $brutto_zarada_za_nas_kn = number_format(round(($row["brutto_zarada_za_nas_kn"]),2),2,",","."); $brutto_zarada_za_nas_p = number_format(round(($row["brutto_zarada_za_nas_post"]),2),2,",","."); $datum1 = date("d.m.Y H:i:s",strtotime($vrijeme)); //Dohvačanje starih i zamjenjenih brojeva $upit23 = "SELECT ne_koristi_se, kataloski_broj_novi FROM kalkulacija_zamjene_staro WHERE kataloski_broj_stari = '$kataloski_broj'"; $query23 = mysql_query($upit23) or die (mysql_error()); $row = mysql_fetch_array($query23); $staro = $row["ne_koristi_se"]; $zamjena_novo = $row["kataloski_broj_novi"]; echo ' <tr> <td width="65"> '; if (!empty($zamjena_novo)){ echo '<img src="images/zamjena.png" border="0" title="Broj je zamijenjen sa '.$zamjena_novo.'">'; } if (!empty($staro) AND $staro == 1){ echo ' <img src="images/staro.png" border="0" title="Broj se ne koristi!">'; } //Dohvačanje naziva artikla iz NAV-a $upit233 = "SELECT naziv_artikla FROM kalkulacija_import_kategorija WHERE kat_br = '$kataloski_broj'"; $query233 = mysql_query($upit233) or die (mysql_error()); $row = mysql_fetch_array($query233); $naziv_artikla = $row["naziv_artikla"]; if (empty($naziv_artikla)) { $upit234 = "SELECT naziv FROM kalkulacija_import_cjenik_stavke WHERE kataloski_broj = '$kataloski_broj'"; $query234 = mysql_query($upit234) or die (mysql_error()); $row44 = mysql_fetch_array($query234); $naziv_artikla = $row44["naziv"]; } //Zamjena hrvatskih znakova $some_special_chars = array("æ", "è", "í", "ó", "ú", "Á", "É", "Í", "Ó", "Ú", "ñ", "Ñ"); $replacement_chars = array("ć", "č", "i", "o", "u", "A", "Ć", "I", "O", "U", "n", "N"); $replaced_string = str_replace($some_special_chars, $replacement_chars, $naziv_artikla); echo' </td> <td width="120"><span title="VPC: '.$neto_VPC.' - PVPC: '.$preporucena_VPC.'">'.$kataloski_broj.'</span></td> <td width="200">'.$replaced_string.'</td> <td width="100"><div align="center">'.$kategorija_artikla.'</div></td> <td width="110"><div align="center">'.$grupa_proizvoda.'</div></td> <td width="140"><div align="center">'.$podgrupa_proizvoda.'</div></td> <td width="110"><div align="center">'.$cijena_eurska.'</div></td> <td width="90"><div align="center">'.$cijena_KN.'</div></td> <td width="80"><div align="center">'.$carina.'</div></td> <td width="80"><div align="center">'.$spediter.'</div></td> <td width="100"><div align="center">'.$banka.'</div></td> <td width="80"><div align="center">'.$transport.'</div></td> <td width="100"><div align="center">'.$nabavna_cijena.'</div></td> <td width="80"><div align="center">'.$drezga_marza_po_grupi.' %</div></td> <td width="100"><div align="center">'.$drezga_zarada.'</div></td> <td width="90"><div align="center"><strong>'.$neto_VPC.'</strong></div></td> <td width="90"><div align="center"><strong>'.$neto_MPC.'</strong></div></td> <td width="90"><div align="center">'.$diler_marza_po_grupi.' %</div></td> <td width="100"><div align="center">'.$zarada_diler_kn.'</div></td> <td width="110"><div align="center"><strong>'.$preporucena_VPC.'</strong></div></td> <td width="110"><div align="center"><strong>'.$preporucena_MPC.'</strong></div></td> <td width="90"><div align="center">'.$brutto_zarada_za_nas_kn.'</div></td> <td width="90"><div align="center">'.$brutto_zarada_za_nas_p.'</div></td> <td width="80"><div align="center">'.$trosak_firme_p.' %</div></td> <td width="80"><div align="center">'.$trosak_firme.'</div></td> <td width="100"><div align="center">'.$zarada_za_nas_kn.'</div></td> <td width="80"><div align="center">'.$zarada_za_nas_p.'</div></td> <td width="150"><div align="center"> '; if ($status == 1) { echo '<a href="povjest_redak_kalkulacije.php?id='.$broj.'&id_kalkulacije='.$id_kalkulacije.'&kataloski_broj='.$kataloski_broj.'&id_cjenika='.$id_cjen.'"><img src="images/povjest.png" border="0" width="20" height="20" alt="Povijest" title="Pogledaj povjest artikla"></a> <a href="usporedba_redak_kalkulacije.php?id='.$broj.'&id_kalkulacije='.$id_kalkulacije.'&kataloski_broj='.$kataloski_broj.'&id_cjenika='.$id_cjen.'"><img src="images/history1.png" border="0" alt="Usporedba" title="Usporedba retka sa prošlom godinom" width="25" heigth="25"></a> <a href="calculator.php?id='.$broj.'&id_kalkulacije='.$id_kalkulacije.'" onclick="basicPopup(this.href);return false"><img src="images/calculator_n.png" border="0" title="Kalkulator zarade za dilera"></a></div></td>'; } else { echo'<a href="izmjeni_redak_kalkulacije.php?id='.$broj.'&id_kalkulacije='.$id_kalkulacije.'&id_cjenika='.$id_cjen.'"><img src="images/izmjeni.png" border="0" alt="Izmjeni" title="Izmjeni redak kalkulacije"></a> <a href="obrisi_redak_kalkulacije.php?id='.$broj.'&id_kalkulacije='.$id_kalkulacije.'&id_cjenika='.$id_cjen.'" onclick="provjera(this.href); return false;"><img src="../brisanje.png" border="0" alt="Obrisi" title="Obriši redak kalkulacije"></a> <a href="povjest_redak_kalkulacije.php?id='.$broj.'&id_kalkulacije='.$id_kalkulacije.'&kataloski_broj='.$kataloski_broj.'&id_cjenika='.$id_cjen.'"><img src="images/povjest.png" border="0" width="20" height="20" alt="Povijest" title="Pogledaj povjest artikla"></a> <a href="usporedba_redak_kalkulacije.php?id='.$broj.'&id_kalkulacije='.$id_kalkulacije.'&kataloski_broj='.$kataloski_broj.'&id_cjenika='.$id_cjen.'"><img src="images/history1.png" border="0" alt="Usporedba" title="Usporedba retka sa prošlom godinom" width="25" heigth="25"></a> <a href="calculator.php?id='.$broj.'&id_kalkulacije='.$id_kalkulacije.'" onclick="basicPopup(this.href);return false"><img src="images/calculator_n.png" border="0" title="Kalkulator zarade za dilera"></a></div></td> </tr> '; } } echo ' </table> <p align="center"> </p> <p align="center"> '; if ($pageno == 1) { echo " <font color='#990000'>Početak</font> || Natrag "; } else { echo " <a href='{$_SERVER['PHP_SELF']}?pageno=1&id=$id_kalkulacije'>Prva</a> | "; $prevpage = $pageno-1; echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$prevpage&id=$id_kalkulacije'>Natrag</a> "; } // if echo " ( <font color='grey'>Stranica - <b>$pageno</b> od <b>$lastpage</b></font> ) "; if ($pageno == $lastpage) { echo " Naprijed || <font color='#990000'>Kraj</font> "; } else { $nextpage = $pageno+1; echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$nextpage&id=$id_kalkulacije'>Naprijed</a> | "; echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$lastpage&id=$id_kalkulacije'>Posljednja</a> "; } // if echo " <br />Rezultata: ".$brojcanik." </p>";
-
Hi, I have a little snipplet I am posting here, I am not very experienced with PHP but thought I would ask some of you for help. I have to modify a program and a very small part of it is to remove lines where values are being set to blank or '' null values. Here is the little code snipplet: echo "\t\tfor(index=0; index < $maxclothrows; index++)\n"; echo "\t\t{\n"; echo "\t\t\tdocument.pickDivision.cloth.options[index].text = '';\n"; echo "\t\t\tdocument.pickDivision.cloth.options[index].value = '';\n"; echo "\t\t}\n\n"; This above code is used to set some values to ' ', but then after I would like those blank values removed rather then showing up in the list because when I scroll down you have a whole bunch of blank lines. How can I remove these completely? Maybe: echo "\t\t\if(document.pickDivision.cloth.options[index].text = '') {...some code here to remove this blank line} I read about regex or some str_replace, but am not sure how to use it. This program is around 3000 lines of code, so don't think I can attach the file. Any help would be greatly appreciated!
-
Hi All, A bit of a strange one here. I have created the below function and it works for the most part however I noticed that I was still getting access denied. I checked the httpd log and saw this error: [Tue Oct 01 10:12:46 2013] [error] [client 127.0.0.1] PHP Notice: Undefined index: $access in /var/www/xxxx/public_html/dev/v2.0/inc/functions.php on line 652 I then took a look at the MySQL log to see if there was an issue with the query that the function submits: SELECT grp.Can_View_Users, grp.group_id, group_name, group_enabled, grp.created, grp.updated FROM groups grp LEFT JOIN members AS users USING(group_id) WHERE users.id =27 GROUP BY grp.group_id as you can see here it is setting the parameter correctly but when setting it for the PHP code on line 652 it doesnt work :S confused. function GroupAccess($access){ $db = new DbConnector(); $db->connect(); $sql='SELECT grp.'.$access.', grp.group_id, group_name, group_enabled, grp.created, grp.updated ' .'FROM '.GROUP_TBL.' grp ' .'LEFT JOIN '.USER_TBL.' AS users USING(group_id) ' .'WHERE users.id ='.$_SESSION['uid'].' GROUP BY grp.group_id'; $result = $db->query($sql); $rows = $db->fetchArray($result); if($rows['$access'] == 1 && $rows['group_enabled'] == 1) return true; } the above starts at line 643 any assistance would be appreciated as im pulling my hair out here!!
- 6 replies
-
- undefined index
- php
-
(and 1 more)
Tagged with:
-
<!DOCTYPE html> <html> <head> <script> function HideComment() { document.GetElementById("comments").hide("textarea") } </script> </head> <body> <textarea name="" cols="" rows="" id="comments" onClick="">leave comment</textarea> </body> </html> i am trying to get the text area to hide when i click a button. this is what i have but doesnt seem to work. can someone help me?
- 8 replies
-
- javascript
- textarea
-
(and 2 more)
Tagged with:
-
In my DB class i have a function to do a simple sanitize operation. The function does three things: 1. checks weather the input variable is a integer, if it is then it gets the int value of the variable and returns it. 2. checks weather the input variable is a string, if it is then it escapes it and returns it. 3. if it is neither an integer or a string then the variable is unset and returns a "Variable deleted" message. function sanitizeData($dbc, $input){ if(is_int($input)){ $input = intval($input); return $input; } elseif(is_string($input)){ $input = mysqli_real_escape_string($dbc, $input); return $input; } elseif(!is_int($input) OR !is_string($input)){ unset($input); return "Variable contents unknown, variable deleted!"; } } I wanted other peoples ideas, opinions and suggestions on this function and what you think of it Thanks
-
When I type my Website URL It's all right. But When I press the sub-category to view the inner content then the problem is occur. There is 5 folder in my public_html.. They are: 1.admin 2.avatars 3.FTP 4.images 5.includes and some php files. This is a script. I can't php. ###There's some Error... Deprecated: Function ereg_replace() is deprecated in /home/exwggayd/public_html/includes/functions.php on line 62 Deprecated: Assigning the return value of new by reference is deprecated in /home/exwggayd/public_html/includes/phpflickr/phpFlickr.php on line 91 Deprecated: Assigning the return value of new by reference is deprecated in /home/exwggayd/public_html/includes/phpflickr/phpFlickr.php on line 330 Deprecated: Assigning the return value of new by reference is deprecated in /home/exwggayd/public_html/includes/phpflickr/phpFlickr.php on line 399 Deprecated: Assigning the return value of new by reference is deprecated in /home/exwggayd/public_html/includes/phpflickr/phpFlickr.php on line 468 Deprecated: Assigning the return value of new by reference is deprecated in /home/exwggayd/public_html/includes/phpflickr/PEAR/HTTP/Request.php on line 228 Deprecated: Assigning the return value of new by reference is deprecated in /home/exwggayd/public_html/includes/phpflickr/PEAR/HTTP/Request.php on line 324 Deprecated: Assigning the return value of new by reference is deprecated in /home/exwggayd/public_html/includes/phpflickr/PEAR/HTTP/Request.php on line 602 Deprecated: Assigning the return value of new by reference is deprecated in /home/exwggayd/public_html/includes/phpflickr/PEAR/HTTP/Request.php on line 621 Strict Standards: Redefining already defined constructor for class Net_URL in /home/exwggayd/public_html/includes/phpflickr/PEAR/Net/URL.php on line 122 Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in /home/exwggayd/public_html/includes/phpflickr/PEAR/HTTP/Request.php on line 590 Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in /home/exwggayd/public_html/includes/phpflickr/PEAR/HTTP/Request.php on line 591 Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in /home/exwggayd/public_html/includes/phpflickr/PEAR/HTTP/Request.php on line 603 ##### The function.php inside the "includes" folder...may be there is the problem. But When I reload the page Everything Seems allright. Here is the Codes...Paste on Pastebin!! #function.php# hxxp://pastebin.com/PR4RKSJS #phpFlickr.php# hxxp://pastebin.com/zzaVehBx #Request.php# hxxp://pastebin.com/MPfq5zAL #URL.php# hxxp://pastebin.com/yDMvA7e5
- 1 reply
-
- ereg_replace()
- pereg_replace()
-
(and 3 more)
Tagged with:
-
Hi all I have problem with making custom function to deal with my scripts i tried and look on google but cant find here is code i have function errors() { $errors = array(); $_SESSION['errors'] = $key->$errors; foreach ($_SESSION['errors'] as $error) { return $error; } } and i use it like this in my script $error[] = 'Please enter username and password.'; but when i call function i have errors Notice: Undefined variable: key in C:\xampp\htdocs\core\_func.php on line 37 Notice: Trying to get property of non-object in C:\xampp\htdocs\core\_func.phpon line 37 Warning: Invalid argument supplied for foreach() inC:\xampp\htdocs\core\_func.php on line 38 please help me
-
I have been always questioning myself which should i use return or echo inside a fuction can somone clear this up for me . Thanks in advance. Audittxl
-
I wrote a long explaination, but then the page was refreshed an I lost it... essentially I can't get variables to work between functions, resorted to globals, I can get away with it, but I can't even get that to worl... code: <?php global $checkvar; //get the 'checkvar' this is an array of strings $checkvar = $_GET['checkvar']; checkvariable(); function checkvariable() { var_dump($checkvar); } ?> the dump of $checkvar comes up NULL in the function, but fine right after its been called.
-
Hi guys, It's a simple question really (just getting used to php - actionscript 3.0 developer!) but I need to know how I can pass a CSS class into the arguments in a PHP function, then have it apply that style to text in html. What I have so far is: <?php function addText($text,$class) { ?> <div class= $class > <p><?php echo $text ?></p> </div> <?php } ?> But it doesn't work, the <div class = $class > should be different I think. Anybody got a solution?
-
Trying to make a game where the user plays the computer, the user does not get to place ships and the computer does not try to sink the human's ships. on submit, the game is supposed to tell the user hit or miss or you sank my ship the board is supposed to remember where the user clicked each time until the game is over the computer randomly places 5 boats, I have the computer placing the boats, and I have some fire buttons, but its not connecting, and its not supposed to show where the boats are ( user is not supposed to see that part) <?php session_start() ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html lang="EN" dir="ltr" xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Battleship</title> <style type = "text/css"> #footer {font-size: small; text-align:center; clear:right; padding-bottom:20px; } body { background-image:url("infor.jpg"); color: white;text-align:center } p { color: yellow; text-align:center;} </style> </head> <body> <?php if(isset($_POST['start_game']) || isset($_POST['myGuess'])){ if (isset($_POST["counter"])){ $counter = $_POST["counter"]; } else { $counter = 0; } // end if $counter++; //store new data in counter $_SESSION["counter"] = $counter; if(isset($_POST['start_game']) || isset($_POST['myGuess'])){ if (isset($_POST["counter"])){ $counter = $_POST["counter"]; } else { $counter = 0; } // end if $counter++; //store new data in counter $_SESSION["counter"] = $counter; if(isset($_POST['choice'])){ if($_POST['choice']=="correct") print "<br>I got it! it took me $counter tries. <br>"; } $myGuess=rand($lowest,$highest); //This is used for debugging - keeping track of what each value is when the submit button is pressed // if(isset($_POST['choice'])){ //print_r($_POST); //} $form = "showOptions"; }else{ $form = "showStart"; } if($form == "showOptions"){ ?> <h2> <form method="post" action="" name="target"> <input type="Submit" value="Submit" align="MIDDLE"> </form> </h2> <form action="" method="post" > <table border="1" align="center"> <?PHP $step = $_POST['step']; if ($step > 2) { $step = 0; } else { $step += 1; }//end if if($step == 1) { for ($i = a; $i < k; $i++){ echo "<tr><td width='20' align='right'>$i</td>"; for ($j = 1; $j < 11; $j++){ echo "<td><input type='submit' value='fire' name='$i$j'></td>"; } // end for loop echo "</tr>"; } // end for loop echo "<tr><td></td>"; for ($j = 1; $j < 11; $j++){ echo "<td>$j</td>"; } echo "</tr></table>"; // result of fire } else { echo "Result "; for ($i = a; $i < k; $i++){ echo "<tr><td width='10' align='right'>$i</td>"; for ($j = 1; $j < 11; $j++){ echo "<td><input type='checkbox' checked='checked' disabled='disabled' name='$i$j'></td>"; } // end for loop echo "</tr>"; } // end for loop echo "<tr><td></td>"; for ($j = 1; $j < 11; $j++){ echo "<td>$j</td>"; } echo "</tr></table><br><input type='submit' name='' value='shoot'>"; }//end if ?> <input type="hidden" name="step" value="<?php echo "$step";?>" /> </form> </center> <?php if ($step == 0) { for ($i = a; $i < k; $i++){ echo "<tr><td width='10' align='right'>$i</td>"; for ($j = 1; $j < 11; $j++){ echo "<td><input type='submit' value='fire' name='$i$j'></td>"; } // end for loop echo "</tr>"; } // end for loop echo "<tr><td></td>"; for ($j = 1; $j < 11; $j++){ echo "<td>$j</td>"; } echo "</tr></table>"; //player fireing } else if($step == 1) { for ($i = a; $i < k; $i++){ echo "<tr><td width='10' align='right'>$i</td>"; for ($j = 1; $j < 11; $j++){ echo "<td><input type='submit' value='fire' name='$i$j'></td>"; } // end for loop echo "</tr>"; } // end for loop echo "<tr><td></td>"; for ($j = 1; $j < 11; $j++){ echo "<td>$j</td>"; } echo "</tr></table>"; // result of fire } else { echo "Result "; for ($i = a; $i < k; $i++){ echo "<tr><td width='10' align='right'>$i</td>"; for ($j = 1; $j < 11; $j++){ echo "<td><input type='checkbox' checked='checked' disabled='disabled' name='$i$j'></td>"; } // end for loop echo "</tr>"; } // end for loop echo "<tr><td></td>"; for ($j = 1; $j < 11; $j++){ echo "<td>$j</td>"; } } echo "</tr></table><br><input type='submit' name='' value='shoot'>"; }//end if ?> <input type="hidden" name="step" value="<?php echo "$step";?>" /> <h2>The number of squares for each ship is determined by the type of the ship. <BR /> The ships cannot overlap (i.e., only one ship can occupy any given square in the grid). <BR /> In each round, the Human clicks the target square which is to be shot at. <BR /> The Computer announces whether or not the square is occupied by a ship, <BR /> and if it is a hit they mark this on their own primary grid. <BR /> When all of the squares of a ship have been hit, the ship is sunk, <BR /> and the Computer owner announces this (e.g. You sunk my battleship!!). <BR /> If all of a player's ships have been sunk, the game is over and their opponent wins. </h2> <h2><?php echo "<br> <a href='battleshipmajorstart.php'>Reset Game</a>" ?></h2> <?php error_reporting( E_ALL ); // $ships['Ship Name'] = size (int); $ships = array( 'Carrier' => 5, 'Battleship' => 4, 'Destroyer' => 3, 'Submarine' => 3, 'Patrol Boat' => 2 ); // $grid[x-coord][y-coord] $grid = array(); // Loop through ships for placement foreach( $ships as $name => $size ) { // Begin an infinite loop ( dangerous, but we can break it when // the ship is happily placed ) while ( TRUE ) { // Determine direction of ship // x- horizontal, y- vertical $axis = ( mt_rand(0,1) == 1 ? 'x' : 'y' ); // Maximum values on grid $max = array( 'x' => 10, 'y' => 10 ); // Subtract $size from the max value to compensate for ship size $max[ $axis ] -= $size; // Generate random placement $x = mt_rand( 1, $max['x'] ); $y = mt_rand( 1, $max['y'] ); // Check to see if the grid is empty by checking $size squares in $axis direction for ( $i = 0; $i < $size; $i++ ) { //Create a temporary holder for our coordinates $curr = array( 'x' => $x, 'y' => $y ); ////Add current grid position to the direction we're going $curr[ $axis ] += $i; // Check to see if the grids populated if ( isset( $grid[ $curr['x'] ][ $curr['y'] ] ) ) //If it is, start at the beginning of the while loop and find new coordinates continue 2; } // If the for loop didn't run into a collision, then we know the grid space is empty //and we can break out of the infinite loop! break; } //Now that we have a position for the ship, write it into the grid! for ( $i = 0; $i < $size; $i++ ) { // Create a temporary holder for our coordinates $curr = array( 'x' => $x, 'y' => $y ); // Add current grid position to the direction we're going $curr[ $axis ] += $i; // Add the first letter of the ships name to the grid ( just for example purposes ) $grid[ $curr['x'] ][ $curr['y'] ] = substr( $name, 0, 1 ); } } //Display the grid echo '<table width="300" height="300" border="1" align="center">'; for ( $row = 1; $row <= 10; $row++ ) { echo '<tr>'; for( $col = 1; $col <= 10; $col++ ) { echo '<td width="30" align="center">'; echo ( isset($grid[$row][$col]) ? $grid[$row][$col] : ' ' ); echo '</td>'; } echo '</tr>'; } echo '</table>'; ?> <?php } else{ ?> When play begins, The Computer secretly arranges Her ships on Her primary grid. <BR /> Each ship occupies a number of consecutive squares on the grid, <BR />arranged either horizontally or vertically. <BR /> <BR /> The number of squares for each ship is determined by the type of the ship. <BR /> The ships cannot overlap (i.e., only one ship can occupy any given square in the grid). <BR /> In each round, the Human clicks the target square which is to be shot at. <BR /> The Computer announces whether or not the square is occupied by a ship, <BR /> and if it is a "hit" they mark this on their own primary grid. <BR /> The attacking player notes the hit or miss on their own "tracking" grid, in order to build up a picture of the opponent's fleet. <BR /> When all of the squares of a ship have been hit, the ship is sunk, <BR /> and the ship's owner announces this (e.g. "You sunk my battleship!"). <BR /> If all of a player's ships have been sunk, the game is over and their opponent wins. <form method="post" action="" name="choice"> <input name="start_game" id="start_game" value="Start Game" type="submit" src="game.png" name="image" width="100" height="150"><br> </form> <?php } ?> <p id="footer">Copyright © 2013 DeAnna Riddlespur & Gene Lau & Matthew Semple</p> </body> </html>
-
I recently filled out a job application for a web developer position. In addition to the usual 'tell us about yourself' questions, I was presented with this one. After searching the web and hacking at it for nearly an hour. I just punched in 5. I'm sure it's wrong. Anyway, I was wondering if someone could give me some clarification on what is happening here: <?php /* What value should you replace the '?' with to make the output read 10? */ var x = 6; var y = 4; var a = function(b) { return function© { return y + b + c; } }; x = 2; y = 5; var fn = a(x); x = 1; y = 3; var unknown = ?; console.log(fn(unknown));* ?> Am I reading correctly that the value of var a is equal to the value returned by function(b) which is equal to the value returned by function© which is y + b + c? I concluded that the value of var a = 4 + 2b + 2c. But since var b and var c are not defined how would I go about getting a strictly numeric value as output? Pardon my ignorance, but I have faced questions like this for other job apps and I am tired of staring at the screen like an idiot! Any clarification would be greatly appreciated!
-
I have a simple function public function showtrips($id,$table){ $sql="SELECT * FROM $table WHERE id = :id ORDER BY id DESC"; if(!$stmt = $this->conn->prepare($sql)){ // prepare failed echo "<pre>Prepare failed:\n"; print_r($pdo->errorInfo()); echo "</pre>"; } else { if(!$stmt->execute(array(':id'=>$id))){ // execute failed echo "<pre>Execute failed:\n"; print_r($stmt->errorInfo()); echo "</pre>"; } else { while($r = $stmt->fetch(PDO::FETCH_ASSOC)){ $data[]=$r; } return $data; } } } and a for loop that calls this function foreach($obj->showtrips($id,"trips") as $value){ extract($value); echo <<<show <tr class="success"> <td>$departTime</td> <td>$departPlace</td> <td>$arriveTime</td> <td>$arrivePlace</td> <td>$numberOfPass</td> <td>$purpose</td> <td>$cargo</td> <td>$remarks</td> </tr> show; } In my foreach loop how can I first test if the return variable $data has any data in it?
-
Ok so I am trying to make it so that I have the option to make my site display one of two pages. Maintenance.php if I put the site down, and Index.php for the default site. Here is my code so far but I am unsure as to why it does not work?? Maintenance.php <?php function maintenance($mode){ if($mode = TRUE){ echo '<META HTTP-EQUIV="Refresh" Content="0; URL=maintenance.php">'; exit; } else { echo '<META HTTP-EQUIV="Refresh" Content="0; URL=index.php">'; exit; } } ?> Under maintenance Index.php <?php require_once('maintenance.php') maintenance($mode = TRUE); ?> <!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <title>Home</title> <link rel="stylesheet" type="text/css" href="css/style.css"> <link rel="SHORTCUT ICON" href="favicon.ico"> </head> Not under maintenance What seems to be the problem??
- 1 reply
-
- function
- maintenance
-
(and 1 more)
Tagged with:
-
I have 4 functions which are changing four different parameters. But when i change them one after another every parameter is changing without including 3 left. How can i change that? Here is the code: <script text="text/javascript"> $(function(){ $('#T1Slider').slider({ change: function(){ var T1 = $(this).slider('option','value') $('#lissajousOutput').attr('src', 'lissajous.php?T1='+T1) } }); }); </script> <script text="text/javascript"> $(function(){ $('#T2Slider').slider({ change: function(){ var T2 = $(this).slider('option','value') $('#lissajousOutput').attr('src', 'lissajous.php?T2='+T2) } }); }); </script> <script text="text/javascript"> $(function(){ $('#a1Slider').slider({ change: function(){ var a1 = $(this).slider('option','value') $('#lissajousOutput').attr('src', 'lissajous.php?a1='+a1) } }); }); </script> <script text="text/javascript"> $(function(){ $('#a2Slider').slider({ change: function(){ var a2 = $(this).slider('option','value') $('#lissajousOutput').attr('src', 'lissajous.php?a2='+a2) } }); }); </script> <link rel="stylesheet" href="//code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" /> </head> <center><img src="lissajous.php" id="lissajousOutput"></center> </br></br> <center>T1<div name="T1" style="width: 800px; " id="T1Slider"></div></center> <br> <center>T2<div name="T2" style="width: 800px; " id="T2Slider"></div></center> <br> <center>a1<div name="a1" style="width: 800px; " id="a1Slider"></div></center> <br> <center>a2<div name="a2" style="width: 800px; " id="a2Slider"></div></center>
-
What is difference between require_once(), require(), include(). all the three function usely use to call a file in another file. what is the basic difference?
- 2 replies
-
- differnce
- reqire_once()
-
(and 3 more)
Tagged with:
-
Hey:) I have a question. It may sound dumb, but I can't figure out the problem. What I have: <html><body> <?php $x=5; $z=6; $y=$x+$z; function myTest() { global $x, $z, $y; echo $x . " " . $z . " " . $y . " "; $x++; $z++; } myTest(); myTest(); echo "<br>"; echo $x . " " . $z . " " . $y; ?> </body> </html> Now my problem is that I don't know why the value of y doesn't change. x and z are changing fine, but y isn't. Thanks:) Tim
-
hey guys, since i am so new to php and programming , i am having extreme difficulty creating a function from scratch. i understand functions if i am reading one or if watching a tutorial , but trying to create one based one what i need is proving to be a bit confusing for me. PURPOSE the purpose of the function is to grab an id from my user database , and convert that ID to an md5. i already have a while loop that is grabbing all the content from my database and then extracting it to the page. i then want to display the image id in a loops surrounded by <img> tags to show each individual persons image with the correct id from the DB. so the link would be looking like this if you were to inspect the element if you were to look in text editor it would be like <?php while ($row = mysql_fetch_assoc($content)) { extract($row); echo '<li>'; echo '<div class="profile_pic"><a href="profile.php?member=' .$member_title . '&memberid=' .$id .'"><img src="http://s3.amazonaws.com/fast-network/photos/c4ca4238a0b923820dcc509a6f75849b.jpg" width="101" height="150"></a></div>'; echo '<div class="member_about">'; echo '<div class="member_about_text">'; echo '<h1><a href="profile.php?member=' .$imdb_title . '&memberid=' .$id .'">' . $member_title . ' (2013)</a></h1>'; echo '<div class="c">Class: ' .$class_year . '</div>'; echo 'Courses:' . $_courses_taken . '<br>'; echo 'Views: <span>194526</span> (<span>176</span> votes)<br>'; echo 'Votes:' .$votes .' <br>'; echo '</div>'; echo '<div class="about_rete">'; echo '<div class="vote">'; echo '<div id="Mark">'; echo '<div id="Maro">Rating: $rating . ' </span></div>'; echo '</div>'; echo '</div>'; echo '</div>'; echo '</div>'; echo '</li>'; } ?> HERE IS WHERE I WANT TO ADD THE FUNCTION echo '<div class="profile_pic"><a href="profile.php?member=' .$member_title . '&memberid=' .$id .'"><img src="http://s3.amazonaws.com/fast-network/photos/c4ca4238a0b923820dcc509a6f75849b.jpg" width="101" height="150"></a></div>'; INSTEAD IT WOULD LOOK LIKE THIS echo '<div class="profile_pic"><a href="profile.php?member=' .$member_title . '&memberid=' .$id .'"><img src=" http://s3.amazonaws.com/fast-network/photos/display_member_image($id).jpg " width="101" height="150"></a></div>'; ultimately i would like some feedback as to how to best approach creating this function to what i need it to do .. i will be using this function anywhere i want the image to be shown.
-
Hi, im still in the early learning stages, banging my head against walls looking for clues. Iv been reading the manual to no avail. im building a user log in system based on the phpAcadamy tutorial 'Register & Login'. They use mysql_connect in the tutorial, but I am using a PDO connection to mysql. 1) the function user_id_from_username should return the `user_id` entry for the posted $username. mine does not, im confused about how to simply return the entry, and i just need a little bit of guidance and explanation. 2) the login function works, BUT i need it to return $user_id if TRUE, so that i can set the session. here is my code: function user_id_from_username(PDO $db, $username) { $stmt = $db->prepare('SELECT `user_id` FROM `users` WHERE `username` = 1'); $stmt->bindParam(1, $username); $stmt->execute(); return ($stmt->fetchColumn()); } //??? I NEED THIS FUNCTION TO RETURN THE `user_id` ENTRY FOR $username function login(PDO $db, $username, $password) { $user_id = user_id_from_username($db, $username); $password = md5($password); $stmt = $db->prepare('SELECT COUNT(`user_id`) FROM `users` WHERE `username` = ? AND `password` = ?'); $stmt->bindParam(1, $username); $stmt->bindParam(2, $password); $stmt->execute(); return (bool) $stmt->fetchColumn(); } //??? I NEED THIS FUNCTION TO RETURN $user_id IF TRUE (to set session) //---------------------login.php----------------------- if (empty($_POST) === false) { $username = $_POST['username']; $password = $_POST['password']; if (empty($username) === true || empty($password) === true) { $errors[] = 'You need to enter a username and password.'; } else if (user_exists($db, $username) === false) { $errors[] = 'We can\'t find that username. Have you registered?'; } else if (user_active($db, $username) === false) { $errors[] = 'You haven\'t activated your account!'; } else { $login = login($db, $username, $password); if ($login === false) { $errors[] = 'That username/password combination is incorrect.'; } else { die($login); } } print_r($errors); } So, according to this login script, after a successful login (good username and password, and active account) it should output the $user_id integer: "die($login)". It prints the error array correctly, it logs in ok, except for this next step. Thanks in advance!
-
Hey guys, So i have a small yet very simple question more so than an issue. I am trying to call a variable that is a field from a mysql database. i am using an extract() function so any field title just returns as a variable. i have a member page where i then list the member and want to have on the side of their name the year they are born. for ex. <h1> Name ( year ) </h1> So in my data field the year the person is born is given as a full string of text 1984-14-09 Y/dd/m. All i want is the year from this data and to remove the day/month. So i did some research , and i came up with the solution of using an explode(), creating an array, and then simple echoing the index of that data i want. Problem is that the array is then leaving the entire string as one index in the array, basically not doing what i wanted it to do, which was to split the string into parts, allowing me to then echo whatever part i wanted. my code: <h1><a href="#link"><? echo $member_name; ?> (<? $arr = explode(' ',trim($member_birth_date)); print_r($arr); ?>)</a></h1> end result: any suggestions as to how to get the result i am looking for ? would really appreciate any ideas or solutions thanks guys
-
Good day, I've got a problem getting the value of the parameter on a function I've got this code to append on my div $(' .'+type).append(' <a href="#" id="'+type+'-'+desId+'" class="admin-managers"> <span class="admin-managers" id="'+name+'">'+name+'</span> <span id="'+desId+'" onclick="remove('+type+','+desId+')" class="remove" name="<?php echo $type; ?>"></span></a> '); that is how I append the data and it is working fine, But on the "remove(type,desId)" function on: function remove(type,id){ Alert(type); } the id is working fine, but on the type everytime I alert it it return "javascript:void(0)"> What is that happening,? ?
-
Hey there guys ! so i have finally finished my register log-in page , and with that i have created a couple functions pages , as i am sure you can assume all the functions for logic will be called from these pages. now i have one called users , i.e for login , registration , check if active, etc.. and i have one for more general functions page called general , i.e for redirects, and input sanitation. anyway my register login page works flawless ( well i guess more 90 % done 90 % left to go ). and now when im on the index page or my main page essentially i now see a fatal error: now i see that it is telling me exactly where the error is , yet i dont understand as to why i am seeing this . im not quite sure as to how the function is being declared already , when the function is only being called once or twice on the register page. just to show you guys what im talking about my code: general.php ( FUNCTIONS ARE STORED) function email($to, $subject, $body){mail($to, $subject, $body, 'From: [email protected]'); } function email_to_activate($to, $subject, $body){ mail($to, $subject, $body, 'From: [email protected]'); } function email_user_for_recovery($to, $subject, $body){ mail($to, $subject, $body, 'From: [email protected]'); } function logged_in_redirect(){ if (logged_in() === true ) header("Location: index.php"); } function protect_page() { // redirects if user is not logged in .. user gets no access page if (logged_in() === false ) { header('Location: no_permission.php'); exit(); } } function admin_access() { global $user_data; if (has_access($user_data['user_id'], 1) === false) { header('Location: index.php'); exit(); } } function page_redirect() { // if user not logged in redirect goes to index page if (logged_in() === false ) { header('Location: index.php'); exit(); } } function redirect(){ // redirects regardless of logged in or not header('Location: index.php'); exit(); } function array_sanitize(&$item){ $items = strip_tags(htmlentities(mysql_real_escape_string($item))); } function sanitize($data) { return strip_tags(htmlentities(mysql_real_escape_string($data))); } function output_errors($errors){ $output = array(); foreach($errors as $error){ $output[] = $error ; } return '<ul>' . implode($output) . '</ul>'; } and index.php // CORE FUNCTIONS - DATABASE CONNECT - SESSIONS & COOKIES include('include/init.php'); // HEADER INFO - META TAGS - LINKS - SCRIPTS include('include/header.php'); // LOG USER IN if (logged_in() === true){ include ('include/widgets/loggedin.php'); } else { include('include/widgets/login.php'); } // WEBSITE LOGO include('include/logo_head.php'); // NAVIGATION BAR include('include/navbar.php'); // MAIN PAGE include('include/topbanner.php'); include('include/topbanner2.php'); <----- Error shows up here and cuts off the rest of the page. include('include/mainbody.php'); // FOOTER include('include/footer.php'); as i mention in the code above, the page spits about half the output then cuts off and displays that error message. This confuses me a bit more actually. any suggestions as to why this is happening ? EDIT : to add init.php ( CORE FILE ) if(!isset($_SESSION)) { session_start(); } error_reporting(E_ALL| E_STRICT); ini_set('display_errors', 1); require ('core/database/dbconnect.php'); require ('core/functions/general.php'); require ('core/functions/users.php'); require 'core/queries/dbqueries.php'; $current_file = explode('/', $_SERVER['SCRIPT_NAME']); $current_file = end($current_file); if (logged_in() === true) { $session_user_id = $_SESSION['user_id']; $user_data = user_data($session_user_id, 'user_id', 'username', 'password', 'email', 'gender', 'country', 'month' ,'date' , 'year', 'pass_recover', 'type'); if (user_active($user_data['username']) === false){ session_destroy(); header('Location: index.php'); exit(); } if($current_file !== 'change_password.php' && $current_file !== 'logout.php' && $user_data['pass_recover'] == 1 ){ header('Location: change_password.php?force'); exit(); } } $errors = array();
- 2 replies
-
- fatal error
- cannot re-declare
-
(and 2 more)
Tagged with: