Jump to content

fesan

Members
  • Posts

    114
  • Joined

  • Last visited

Everything posted by fesan

  1. Hi, is there possible to search and "choose" a certain arrey key by user input? And when the input is not "korrect" how to choose the closest one? Input = 22 $kz should chose key 21.3 => 1.17 $kz = array( 4.6 => 0.85, 6.1 => 0.90, 7.6 => 0.94, 9.1 => 0.98, 12.2 => 1.04, 15.2 => 1.09, 18 => 1.13, 21.3 => 1.17, 24.4 => 1.21, 27.4 => 1.24, 30.5 => 1.26, 36.6 => 1.31, 42.7 => 1.36, 48.8 => 1.39, 54.9 => 1.43, 61.0 => 1.46, 76.2 => 1.53, 91.4 => 1.59, 106.7 => 1.64, 121.9 => 1.69, 137.2 => 1.73, 152.4 => 1.77,); To explain some more, the array is part of a math solving. where the key is a height in meters and the value are the responding coefficient. $qz = 0.613 * $kz * 1 * 1 * pow($vind2, 2) *1;
  2. I really donĀ“t have a good answer for that! When i first started with PHP i got some code from another forum and i guess some of it is still left and in very much use unfortunately! Could i ask what the correct syntax would be? I guess it is time to convert to mysqli soon as well?
  3. create a completely new file and see if this could help you a bit:(i have not tested the code) <?php $status = !empty($_POST ['status']) ? $_POST['status'] : ''; if($_GET['task'] == 'edit') { $dbhost = ""; $dbusr = ""; $dbpass = ""; $db = ""; $dbtable = ""; $conn = mysql_connect($dbhost, $dbusr, $dbpass); mysql_select_db($dbtable, $conn); $sql = "UPDATE ${dbtable} SET status = '$staus' WHERE id = '$_GET[id]'"; $result = mysql_query($sql, $conn) or die (mysql_error()); echo "Success"; } else {echo "Trouble";} ?> <table> <tr> <td><strong>ID</strong></td> <td><strong>Contact Name</strong></td> <td><strong>Contact Number</strong></td> <td><strong>Contact second number</strong></td> <td><strong>Date Set</strong></td> <td><strong>Notes</strong></td> <td><strong>Status</strong></td> <td><strong>Save</strong></td> </tr> <?php $dbhost = ""; $dbusr = ""; $dbpass = ""; $db = ""; $dbtable = ""; $conn = mysql_connect($dbhost, $dbusr, $dbpass); mysql_select_db($dbtable, $conn); $query = "SELECT * FROM $dbtable"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)){ echo "<tr>\r\n"; echo "<form id='form1' name='form1' action='".$_SERVER['PHP_SELF']."?task=edit&id=".$row['id']."' method='POST'>\r\n"; echo "<td>".$row['id']."</td>\r\n"; echo "<td>".$row['contact_name']."</td>\r\n"; echo "<td>".$row['contact_number_primary']."</td>\r\n"; echo "<td>".$row['contact_number_secondary']."</td>\r\n"; echo "<td>".$row['date_set']."</td>\r\n"; echo "<td>".$row['notes']."</td>\r\n"; echo "<td><select name='status' id='status'> <option selected value='".$row['status']."' >". $row['status']."</option> <option value='1'>1</option> <option value='2'>2</option> <option value='3'>3</option> </select></td>\r\n"; echo "<td><input type='submit' name='submit' id='submit' value='Save' /></td>\r\n"; echo "</tr></table>\r\n"; } ?> was a bit quick there!
  4. yea, that is just what the code should do. It is snipped from a page of mine that does the same thing: http://www.bahrawy.net/dev/cal_snip.PNG on the picture every green field is a input field where i can write directly into the table. hit enter or the button at the end saying "Lagre" and it saves. The output of your first code should go straight to a <form> with a <select> input. add an extra column to your HTML table to get the submit button. the URL not found seems like you have added the header code and not updated to the correct path of your page?
  5. you are so absolutely right Barand, but i actually have it in a code of mine here and it works just fine! It doesn't make it more right though! no, you don't have to have an ID column, but as far as i know it is good practice. It is a way of separating all the rows from each other with an unique id. If set to unique and auto increment. Unless you have some other unique column that makes us able to choose that particular row? The while function should print out every row in your DB and separate them by printing the row ID(or other sort of ID) in the action"" field of the <form>. After getting this to work you could choose to just print one row, or CSS it to something more view able.
  6. sorry for the missing bracket! what page turns out blank? the first or the second? The second page "proc.php" has no code after the row update. you could use a header to get back to the previous page header("Location: http://sitename"); Or you could just an a link: echo "<a href='updateform.php'>back...</a>
  7. You need a form to update fields without phpmyadmin. I'm very pro outputting my data directly into a form and change it on the fly. I tend to CSS the form so it does not look like an traditional form. Alternatively you could use Java/AJAX. example of code: $dbhost = "yourhost"; $dbusr = "yourusername"; $dbpass = "yourpassword"; $db = "yourbatabase"; $dbtable = "yourtable"; mysql_connect ($dbhost, $dbusr, $dbpass) || die("Could not connect to the server."); mysql_select_db($db) || die("Could not find the Data Base"); $conn = mysql_connect($dbhost, $dbusr, $dbpass); mysql_select_db($dbtable, $conn); $query = "SELECT * FROM $dbtable"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)){ echo "<form id='form1' name='form1' action='yourprocesspage.php&id=".$row['id']."' method='POST'>\r\n"; echo "<input type='text' name='yourfield' id='yourfield' size='6' value='". $row['your_DB_row']."' />\r\n"; echo "<input type='submit' name='submit' id='submit' value='Submit' />\r\n"; echo "</form>\r\n"; you would then need to process the data sent to the process page: //get the variables and making sure they are not empty $yourfield = !empty($_POST ['yourfield']) ? $_POST['yourfield'] : ''; $dbhost = "yourhost"; $dbusr = "yourusername"; $dbpass = "yourpassword"; $db = "yourbatabase"; $dbtable = "yourtable"; mysql_connect ($dbhost, $dbusr, $dbpass) || die("Could not connect to the server."); mysql_select_db($db) || die("Could not find the Data Base"); $conn = mysql_connect($dbhost, $dbusr, $dbpass); mysql_select_db($dbtable, $conn); $sql = "UPDATE $dbtable SET your_DB_row = '$yourfield', WHERE id = '$_GET[id]'"; //we sent the row id with the adressbar and are retreiveing it via $_GET[''] $result = mysql_query($sql, $conn) or die (mysql_error());
  8. Try setting the file permission to 744 in your script. http://php.net/manual/en/function.chmod.php change it back to 644 or whatever your correct mode is after executing the zip.
  9. fesan

    header

    Ahhh.... i found the error! Just me doing stupid things without thinking! My process page is not included in my index where the rest of my includes are. Therefore my variables where not set in the process page. Thanks for the push!!
  10. fesan

    header

    i did a var_dump() on all 3 variables: string(15) "www.bahrawy.net" string(13) "/dev/ballroom" string(9) "index.php" echo $host.$uri."/".$page; www.bahrawy.net/dev/ballroom/index.php I can't see the the difference between these two: - header("Location: http://$host$uri/$page"); - header("Location: http://www.bahrawy.net/dev/ballroom/index.php"); and thanks for the help by the way!
  11. fesan

    header

    yea, i missed out the dollar sign while copying! it is in the original code. There is no change in the pages except from i have changed the header goal from an direct URL to a PHP made url. Before i changed the code everything worked out as i wanted. The Index.php has a "session_start()" at the veyr start so it s re-declared every time the page is refreshed.
  12. fesan

    header

    Hi... Updating a small site of mine. I had a header that read header("location: full-web-page-url"). I replaced this code so it is a bit easier to update my pages in the future. I then added this code: host = $_SERVER['HTTP_HOST']; $uri = rtrim(dirname($_SERVER['PHP_SELF']), '/\\'); $extra = 'index.php'; The page has worked flawless before i did this and now i have a "refresh delay". The first page is a form that a user submits. This takes the user to a new page with the execute code(no visuals for user). after execution the page runs this code(se below) to take them back with info about the execution. _SESSION["message"] = "Eventinfoen er endret."; header("Location: http://$host$uri/$extra"); The header works fine and the code executes fine, but the session message is not echoed on the next page before i press refresh in my browser. In the php manual i find this: Does this involve every session variables? If that is the case how do i use a SID constant to transfer all my variables?
  13. fesan

    Functions

    ahh... Thanks. And if there are allot of variables i need to get out of the function? Do i have to return them all?
  14. Happy Saturday. Can someone explain why this code returns nothing? function test(){ $test = "test"; } test(); echo $test;}
  15. fesan

    Date

    Wow... Great guys! I'm gonna try to log inn to the shell and see if there is a other name etc. Thanks for all the help!!
  16. You have to end the first line or add some more code... $message="Navn: $name \nTelefon nummer: $phone \nGruppe nummer: $grpnr \nAfdeling: $afdeling \n\n " ; foreach ($_SESSION['contents'] as $_SESSION['id']=>$_SESSION['qty']) { $sql = "SELECT * FROM entries WHERE id = '$_SESSION[id]'"; $result = mysql_query($sql); $row = mysql_fetch_row($result); "Produktnavn: $row[1]\n IRIS: $row[6]\n"; }
  17. fesan

    Date

    ahhh.... thanks!! it appears my host doesn't have Norwegian installed. <?php setlocale(LC_ALL, 'no_NO'); echo strftime('%A %e %B', strtotime('2012-10-29')); ?> Result: Monday 29 October
  18. fesan

    Date

    Thanks... I might be using it wrong, but adding setlocale(LC_ALL, 'no_NO'); did not do the trick. I'm not sure if the host has installed the Norwegian language but it is a Norwegian host with it's servers located in Norway. On top of my index i added setlocale(LC_ALL, 'no_NO'); as the first PHP code. Also tested to add it just to the code where i want it to effect...
  19. Can you show the code where you uses the divs to sort you output?
  20. Hi... Can you implode all your variables in to an array. Then sort the array and explode it back out for the users output? http://php.net/manual/en/array.sorting.php
  21. fesan

    Date

    Hi... Can i somehow change the output of php using code under? I would like the output to be in Norwegian. (Monday = Mandag) date('l', strtotime($row['dato'])
  22. No, that was not it, but you got me thinking. Thanks for that! I solved this by adding the row id to the fields name and retrieving it on the post page. Form: echo '<td><input readonly="readonly" type="text" name="dato'.$row['id'].'" id="dato'.$row['id'].'" class="'.$class.'" value="'.date('d.m.Y', strtotime($row['dato'])).'" /></td>'; Handler / Post page: $date_make = "dato" . $_GET['id']; if(!empty($_POST[$date_make])){$dato = $_POST[$date_make];} else {$create = 1;} Thanks for the thinking help!! Only thing left is to make all the java variables with php...
  23. Hi... I have a web page that writes out several rows from a database. The rows are printed directly into forms so it is easy to update. One of the fields is a date field where the user could enter the date with a Java-script date-picker. To not change all the date input fields at once every input needs a separate name even so that there is only one form submitted at a time. To create separate names for each input filed created by PHP i could just use a while loop for number of output rows left. But when the form is submitted and i need to handle the single input from one form but i don't know which... hos can i solve this? The Form: echo '<form id="form1" name="form1" action="edit.php?task=edit&id='.$row['id'].'" method="POST">'; echo '<td><input readonly="readonly" type="text" name="dato" id="dato" class="'.$class.'" value="'.date('d.m.Y', strtotime($row['dato'])).'" /></td>'; // date1, date2. etc. The process script: $dato = !empty($_POST ['dato']) ? $_POST['dato'] : ''; // i need to set this variable to the correct one. if($_GET['task'] == 'edit') { include("admin/conn.php"); $sql = "UPDATE ${dbtable} SET dato = '$mysql_dato', kunde = '$kunde', kontaktperson = '$kontaktperson', telefon = '$telefon', epost = '$epost', type = '$type', status = '$status', lyd = '$lyd', lys = '$lys', kommentar = '$kommentar', last_edit_by = '$last_edit_by', email_sent ='ikkesent' WHERE id = '$_GET[id]'"; $result = mysql_query($sql, $conn) or die (mysql_error()); $_SESSION["message"] = "Eventinfoen er endret."; header("Location: http://bahrawy.net/dlight/ballroom/index.php"); } The Javascript that connects the input to the java: <script type="text/javascript"> $(function() { $('#dato').datepick({dateFormat: 'dd.mm.yyyy'}); }); </script> Did i in some way explain my issue so it is understandable?
  24. Nice! Thanks all for the help!!
  25. Well, this site is mostly the one page! So what you intend to say is that we don't want to include larger files than we need to.? Both for security reasons, server load and page load time?
×
×
  • 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.