Jump to content
Larry Ullman's Book Forums

Gardacus

Members
  • Posts

    24
  • Joined

  • Last visited

Everything posted by Gardacus

  1. All, I found a nice working way. In the time between posting my question and this answer, I started learning javascripting. Not too far yet, but it gave me some eureka moments. The form now consists of this code, and gets its values from the database: echo '<input type="text" size="11" name="impru_acc" id="impru_acc" value = '.$impru_acc.'>'; echo '<input type="text" size="11" name="impru_rest" id="impru_rest" onchange="calculateAll(this.value)" value = "">'; echo '<input type="text" size="11" name="impru_sold" id="impru_sold" value = '.$impru_sold.'>'; echo '<input type="text" size="11" name="impru_dobanda" id="impru_dobanda" value = '.$impru_dobanda.'>'; I made a separate calculateAll.js file and call it in my header.html file. The code consists of: function calculateAll(){ var form = document.forms["fisa"]; var impruDobandaValue = form.elements["impru_dobanda"]; var impruRestValue = form.elements["impru_rest"]; var impruSoldValue = form.elements["impru_sold"]; var impruDobanda = parseInt(impruDobandaValue.value); var impruRest = parseInt(impruRestValue.value); var impruSold = parseInt(impruSoldValue.value); if (impruDobanda > 0) { var difference = impruDobanda - impruRest; } else { var difference = 0; } if (difference > 0) { impruDobanda = impruDobanda - impruRest; return theForm.elements["impru_dobanda"].value = impruDobanda; } else if (difference < 0) { impruSold = difference + impruSold; impruDobanda = 0; return form.elements["impru_dobanda"].value = impruDobanda, form.elements["impru_sold"].value = impruSold; } else if (difference == 0) { impruDobanda = 0; var impruSold = impruSold - impruRest; return form.elements["impru_dobanda"].value = impruDobanda, form.elements["impru_sold"].value = impruSold; } } But I ran into a small issue. When you make a mistake, the form did not use it's original values, but recalculates from the changed values. Which is logical. To work around this, I created a reset button for the impru_rest field in the form. It resets that field and recovers the original values of the impru_sold and impru_dobanda values in the form. After that correction is possible. I thought it was best to code this in PHP <?php echo "<input type=\"button\" value=\"Reset\" onclick=\"var reset = this.form.elements['impru_rest']; reset.value = reset.defaultValue; this.form.impru_dobanda.value=".$impru_dobanda."; this.form.impru_sold.value=".$impru_sold.";\">" ?> So all in all it took me a bit, but I wanted to share my findings with you. Thanks for your help! Mike
  2. I am using the wonderful onkeyup argument to auto update values in forms. I have a question though. Example: I have five values. Loan, Terms, Saldo, Payment, Interest The form is built up that it gets its data from a database. The Loan, Terms and Interest rate will be entered as a default value to handle the rest of the terms, payment and saldo. example: loan = 1000, terms = 12 Interest = 215 Saldo = Loan = 1000 The form will be filled in as an overview of payments and saldo, to check how much money still needs to be paid. For the next entry, the term will count down 1, and I can enter a payment, example 102. Paying a payment will first influence the interest amount until it is 0. From that moment on the Saldo will go down from it's default value of a 1000. Until it is zero I have managed to auto update my form entries automatically when a payment is entered, so that the Interest goes down accordingly. Everytime the payment in this example should be 102. At a certain moment the interest will drop from 215 to 113 to 11. But then I am stuck. Added below is a part of the code. The calculation and check should be done right after // Fill in the payment and deduct it from interest as long as interest is bigger than 0. I know the code is not correct, because at its current state, it won't touch the value of Loan when interest = 0. Not knowing how to catch this, the interest will just become negative. Is there a way to deduct and thus update the form fields in such a matter that when the interest hits 0 the remainder of the payment will be deducted from the Saldo value and in the process keep my form fields being auto updated? Thanks! Mike <?php // Generate split between Interest bigger or equal to zero if (!empty($loan) and $interest >= 0) { // fill in or echo the size of the loan if (!empty($loan)) { echo '<input type="text" size="11" name="loan" value = '.$loan.'></div></td>'; } else { echo '<input type="text" size="11" name="loan" value="" /></div></td>'; } echo '<td><div align="center">'; } // Fill in the payment and deduct it from interest as long as interest is bigger than 0. if (!empty($interest)) { echo '<input type="text" size="11" name="payment" onkeyup="document.forms[0].interest.value = '.$interest.'*1 - document.forms[0].payment.value*1;"></div></td> <td><div align="center"><input type="text" size="11" name="saldo" value="'.$loan.'" readonly="readonly" />'; } else { echo '<input type="text" size="11" name="payment" value="" /></div></td>'; echo '<td><div align="center"><input type="text" size="11" name="impru_sold" />'; } echo '</div></td><td><div align="center">'; ?> I stopped entering the code here, because it is quite long, and the magic should happen after // Fill in the payment and deduct it from interest as long as interest is bigger than 0. If more code is needed, I will be happy to enter it here.
  3. Hello HartleySan I will add some answers and comments to yours 1. These are the (existing) systems I want to make inquiries in: Sidecode 4 (XX-99-XX) Sidecode 5 (XX-XX-99) Sidecode 6 (99-XX-XX) Sidecode 7 (99-XXX-9) Sidecode 8 (9-XXX-99) Hence the flexibility I am searching for in creating the begin and end point. 2. No, no reason, it is an adjusted array of one of Larry's scripts 3. That's why I want to be the first 4. Yes I have legit access, but these things are all besides the point. I have java scripts available, but first things first. as answers to your ) - numbered remarks; 1) I want to exclude non-existing combinations, by providing a fixed selection (hence the letter array) 2) and 3) Good idea to limit it. So remains... how can I build this array? Any ideas how to start this? Thanks again
  4. Hey HartleySan Thank you so much for looking with me Yes, more or less Except we're limited to these letters: $letter = array (1 => 'D', 'F', 'G', 'H', 'J', 'K', 'L', 'N', 'P', 'R', 'S', 'T', 'X', 'Y', 'Z'); All others are not necessary. All digits are possible. This is just one of the many series of possible combinations Example... currently we are at 1 digit - three letters - 2 digits (9-xxx-99). So I was trying to create a script that I can easily apply to all kinds of possible (and future) ranges Thanks Mike
  5. Hi guys I have a new challenge. Short intro. I am from Holland. In Holland we have a car license plating system that links a license plate to a car. And looking up a license plate, can show the known data of that car (technical info, not personal) There are a bunch of sites where you can get the data for one car at the same time. I am thinking to build a site where I can draw information for a whole range of license plate numbers at once. I don't know if I should create an array or another means to create the range. Example at one time, the numbering on our license plates was: 2 digits - 2 letters - 2 digits (99-xx-99) I wrote a script already that can set the begin and end value... but I have no clue how to create an array with all possible combinations between begin and end value. the code I am using to create the begin and end value for the range is as follows: as part of index.php: $letter = array (1 => 'D', 'F', 'G', 'H', 'J', 'K', 'L', 'N', 'P', 'R', 'S', 'T', 'X', 'Y', 'Z'); $number = range (0, 9); echo '<form action="select.php" method="post">'; // create select for range 1 echo '<p>Set range 1'; echo '<select name="letter11">'; foreach ($letter as $key => $value) { echo "<option value=\"$value\"> $value</option>\n"; } echo '</select>'; echo '<select name="letter12">'; foreach ($letter as $key => $value) { echo "<option value=\"$value\"> $value</option>\n"; } echo '</select>'; echo '<select name="digit11">'; for ($number = 0; $number <= 9; $number++) { echo "<option value=\"$number\"> $number</option>\n"; } echo '</select>'; echo '<select name="digit12">'; for ($number = 0; $number <= 9; $number++) { echo "<option value=\"$number\"> $number</option>\n"; } echo '</select>'; echo '<select name="letter13">'; foreach ($letter as $key => $value) { echo "<option value=\"$value\"> $value</option>\n"; } echo '</select>'; echo '<select name="letter14">'; foreach ($letter as $key => $value) { echo "<option value=\"$value\"> $value</option>\n"; } echo '</select></p>'; // create select for range 2 echo '<p>Set range 2'; echo '<select name="letter21">'; foreach ($letter as $key => $value) { echo "<option value=\"$value\"> $value</option>\n"; } echo '</select>'; echo '<select name="letter22">'; foreach ($letter as $key => $value) { echo "<option value=\"$value\"> $value</option>\n"; } echo '</select>'; echo '<select name="digit21">'; for ($number = 0; $number <= 9; $number++) { echo "<option value=\"$number\"> $number</option>\n"; } echo '</select>'; echo '<select name="digit22">'; for ($number = 0; $number <= 9; $number++) { echo "<option value=\"$number\"> $number</option>\n"; } echo '</select>'; echo '<select name="letter23">'; foreach ($letter as $key => $value) { echo "<option value=\"$value\"> $value</option>\n"; } echo '</select>'; echo '<select name="letter24">'; foreach ($letter as $key => $value) { echo "<option value=\"$value\"> $value</option>\n"; } echo '</select></p>'; echo '<input type="hidden" name="sc" value="sc4">'; echo '<input name="submit" type="submit" value="Create List"'; } After pressing the submit, it will send all data to select.php for now I simply plot the beginning and end in it as follows: $letterrange11 = ($_POST ['letter11']).($_POST ['letter12']); $digitrange11 = ($_POST ['digit11']).($_POST ['digit12']); $letterrange12 = ($_POST ['letter13']).($_POST ['letter14']); $letterrange21 = ($_POST ['letter21']).($_POST ['letter22']); $digitrange21 = ($_POST ['digit21']).($_POST ['digit22']); $letterrange22 = ($_POST ['letter23']).($_POST ['letter24']); echo '<p>'.$letterrange11.'-'.$digitrange11.'-'.$letterrange12.' until '.$letterrange21.'-'.$digitrange21.'-'.$letterrange22.'</p>'; So the big question is now... The code I used til now, is it a good basis to create the array that I need? If so, How do I build an array that will look like as follows... What I need is if I select DD-00-DD to DZ-99-ZZ, to plot all possible values in an array. This based on the $letter array. e.g. DD-00-DD DD-01-DD DD-02-DD etc, etc, etc, DZ-99-ZV DZ-99-ZX DZ-99-ZZ This data I can then send per license plate to the to-be-built script. I realize it is a huge list, but I am curious how this could work out. Any help is welcome. THANKS GUYS! Regards Mike
  6. Hi all I am not sure if this topic exists or where to place it, so please forgive me if I posted this on the wrong site. I am looking for a smart (PHP preferred) solution to redirect mobile devices to a mobile version of a website. At this moment this is my javascript solution, but it is not fool-proof: <script type="text/javascript"> if ((navigator.userAgent.indexOf('iPhone') != -1) || (navigator.userAgent.indexOf('iPod') != -1) || (navigator.userAgent.indexOf('iPad') != -1) || (navigator.userAgent.indexOf('Blackberry') != -1) || (navigator.userAgent.indexOf('Opera Mini') != -1) || (navigator.userAgent.indexOf('WebKit') != -1)) { document.location ="mobile/index.html"; } </script> It works on the devices mentioned, but Safari on an iMac also is seen as a mobile device, and therefore redirected to the mobile site. Is there any smart solution for this that I can build in PHP? Thanks all! Mike
  7. Hello HartleySan It's a bit of work, but it will safe me a lot of problems later indeed. Thanks again Holland or The Netherlands is kind of used randomly, but I notice that in the "spoken" language, Holland is more used than "The Netherlands" In official writing I would say The Netherlands is mostly used. Though "The Netherlands" is the official English translation. "Holland" is an old term actually, and nowadays in Dutch only used in the name of 2 provencies: North-Holland (Noord-Holland) and South-Holland (Zuid-Holland) This site may explain a bit more: http://www.archimon.nl/general/holland.html or http://www.worldatlas.com/aatlas/infopage/holland.htm Regards Mike
  8. Hello HartleySan Thanks for your response. I did figure out a workaround, which is actually commonly used here in Holland. I just did not realize. What most web builders seem to do is make an extra column for these prepositions and ask the users to put them in there and the last part of the last name to enter as last name. I have to correct about 100 last names, but it makes my life eventually a lot easier. Thank you again. Regards Mike
  9. Hello all I am still working on the login script from this book, and implementation on my own site works very very well At the moment I am strugling with our last-name convention here in Holland We have names like "van der Vaart", "de Wit" and "in 't Groen" and more alike. The current script does not take this into account and puts them in alphabetical order. So all the "van" and "de" names are in one row. Here in Holland it is therefore customary to split the last name like this: "Vaart, van de", "Wit, de" and "Groen, in 't" But of course we also have singular-word last names, like "Groenen", "Smulders" etc, etc. Does anybody know how I can do this, before injecting them into the database? As a person will always enter it in the orignal way. I was thinking to search for a space before the last word in that line or so, but I might be digging in the dark, and I don't know how to write the code for that. This is a line from the script which already checks for a last name: // Check for a last name: if (preg_match ('/^[A-Z \'.-]{2,40}$/i', $trimmed['last_name'])) { $ln = mysqli_real_escape_string ($dbc, $trimmed['last_name']); } else { echo '<p class="error">Fill in your last name, please!</p>'; } and the line from the form is as follows: <tr><td><b>Last Name:</b></td><td><input type="text" name="last_name" size="20" maxlength="40" value="<?php if (isset($_POST['last_name'])) echo $_POST['last_name']; ?>" /></td></tr> Thanks! Mike
  10. Larry, you're welcome Glad I can do something in return! You're a great teacher and I love reading and learning from your books! Thanks again Mike
  11. Larry I found this and added it in the header file of the login script: if(function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc() === 1){ $_POST = array_map( 'stripslashes', $_POST ); $_GET = array_map( 'stripslashes', $_GET ); $_COOKIE = array_map( 'stripslashes', $_COOKIE ); } It seems to do the trick... as I need this on more locations (us Dutchies are like the French with our apostrophs hahaha) Mike
  12. Hi Larry Thanks for your answer (and your wisdom!!!) That's going to be a challenge... I will have to find a workaround for this, as I am running the scripts from a hosted site, in which I cannot change anything in the php.ini. I will snoop around Mike
  13. Hi Paul Thanks for your help! Unfortunately the result remains the same. But I have no idea why... So even with your code, it still show in \'t Groen Plus The fact that the apostroph is not accepted by the preg_matching I guess... what else would stop it? I am not even injecting it yet in the database. What I mean is, the rest of the original register.php as written in Larry's book, checks if you enter a first name, last name, email address and twice your password. So forgetting either of those, will fill in the already entered info and warn you about the wrong or forgotten ones. But I have no idea what causes the preg_match to state that the entered last name, containing the ' is not a valid last name. Any ideas? Thanks Mike
  14. Hi everyone. I am running into a problem at the register.php script I am from Holland and in both our city names as in first and last names, apostrophs and other punctuation marks are used. For intance 's-Gravenhage is the official name of The Hague. Or a common last name is In 't Groen The script does not seem to allow this, because it keeps returning that I need to enter a valid last name. the code is: // Trim all the incoming data: $trimmed = array_map('trim', $_POST); // Assume invalid values: $fn = $ln = $e = $p = FALSE; ---------- // Check for a last name: if (preg_match ('/^[A-Z \'.-]{2,40}$/i', $trimmed['last_name'])) { $ln = mysqli_real_escape_string ($dbc, $trimmed['last_name']); } else { echo '<p class="error">Fill in your last name please!</p>'; } ----------- If I enter a name as in the example In 't Groen... it would re-fill the line with In \'t Groen. To prevent that from happening I rewrote the form for the last name: <tr><td><b>Last Name:</b></td><td><input type="text" name="last_name" size="20" maxlength="40" value="<?php if (isset($trimmed['last_name'])) echo stripslashes($trimmed['last_name']); ?>" /></td></tr> My question is, how can I allow these characters such as ' and é ï, which we also use a lot, to pass beyond the script and inject it safely into the database? Thanks again! Mike
  15. Hahaha... no problem at all.. I am still just a beginner, and Larry's books are helping a lot. And I love the way this forum works! Great inspiration and great helpers! Thanks again
  16. Hi Paul, thanks for your answer, but I got Margaux' code to work for me. I had to adjust a bit here and there, but this is the final code I implemented: I got inspired and found the following working based on the query I had already working ok on the page. Some things like the $vehicle[$i] I split, to make it clearer for myself what is going on. $q = "SELECT event_id, selected_vehicles, event_year, DATE_FORMAT(event_reg_date, '%d-%m-%Y') AS vrd, user_id FROM event_entries WHERE user_id=$usrid AND event_year=$evnt_year ORDER BY event_id LIMIT $start, $display"; $r = @mysqli_query ($dbc, $q); while ($row=mysqli_fetch_array($r, MYSQLI_ASSOC)){ echo '<td align="left"><small>' . $row['event_id'] . '</small></td>'; // explode vehicles to brand and type $selection=$row['selected_vehicles']; $vehicles=explode(',',$selection); $numVehicles=count($vehicles); for ($i=0; $i<$numVehicles; $i++){ $v = $vehicles[$i]; $qv = "SELECT brand, type FROM vehicles WHERE vehicle_id=$v"; $rv = @mysqli_query ($dbc, $qv); $rowv = mysqli_fetch_row($rv); echo '<td><small>'. $rowv[0] . ' ' .$rowv[1] . '</td>'; } Thanks Margaux and all others! You're the best Mike
  17. Margaux... Thanks I will try the code first thing tomorrow... past midnight here now, and I got square eyes ! Will let you know what I found! Thanks again! Oh... that code $q = "SELECT * FROM vehicles WHERE vehicle_id IN ('".join("','", $selection)."')"; was a piece of code I found online and changed it to my needs. It goes way beyond my knowledge so far, but it seemed to do what I wanted to reach: Print back the vehicle details from the imploded comma separated vehicle_id's Mike
  18. Thanks for your reactions so far! @Margaux. A vehicle is bound to a user, as a user owns it. Even though multiple user can have a similar vehicle, every vehicle is unique. Indeed the vehicle can be used in more entries of the user, but I will limit the visibility of event_entries to the current year only for normal users. The "problem" is that we decided to implode multiple vehicle selection into a comma separated table row. So, if a user selects his vehicle_id numbers, which is generated at the moment the vehicle data is entered (auto-incremental), it will be entered in a row selected_vehicles e.g. 1, 2, 6, 8 exploding it for one user works fine, in such a way that it will match the vehicle_id in the vehicles database, and nicely fills out all the vehicle details. But I lack the knowledge to repeat this in a list for all event_entries. @antonio table design: users: -- phpMyAdmin SQL Dump -- version 3.4.10.1 -- http://www.phpmyadmin.net -- -- Host: localhost -- Generation Time: May 15, 2012 at 03:59 PM -- Server version: 5.0.95 -- PHP Version: 5.2.9 SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO"; SET time_zone = "+00:00"; /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; /*!40101 SET NAMES utf8 */; -- -- Database: `oldtimer_regtest` -- -- -------------------------------------------------------- -- -- Table structure for table `users` -- CREATE TABLE IF NOT EXISTS `users` ( `user_id` int(10) unsigned NOT NULL auto_increment, `first_name` varchar(20) NOT NULL, `last_name` varchar(40) NOT NULL, `email` varchar(80) NOT NULL, `pass` char(40) NOT NULL, `user_level` tinyint(1) unsigned NOT NULL default '0', `active` char(32) default NULL, `registration_date` datetime NOT NULL, `address` varchar(80) NOT NULL, `zip` varchar(6) NOT NULL, `por` varchar(50) NOT NULL, `tel` varchar(15) NOT NULL, `fax` varchar(15) default NULL, PRIMARY KEY (`user_id`), UNIQUE KEY `email` (`email`), KEY `login` (`email`,`pass`), KEY `user_level` (`user_level`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ; /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; -------------------------------------------------------------------------------------------------------------------- vehicles: -- phpMyAdmin SQL Dump -- version 3.4.10.1 -- http://www.phpmyadmin.net -- -- Host: localhost -- Generation Time: May 15, 2012 at 04:02 PM -- Server version: 5.0.95 -- PHP Version: 5.2.9 SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO"; SET time_zone = "+00:00"; /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; /*!40101 SET NAMES utf8 */; -- -- Database: `oldtimer_regtest` -- -- -------------------------------------------------------- -- -- Table structure for table `vehicles` -- CREATE TABLE IF NOT EXISTS `vehicles` ( `vehicle_id` int(10) NOT NULL auto_increment, `category` varchar(12) NOT NULL, `brand` varchar(30) NOT NULL, `type` varchar(60) NOT NULL, `year` tinytext NOT NULL, `user_id` int(11) NOT NULL, `reg_date_vehicle` datetime NOT NULL, `details` longtext NOT NULL, `cilaant` tinytext NOT NULL, `cilinh` tinytext NOT NULL, `power` tinytext NOT NULL, `origin` text NOT NULL, `prodvol` tinytext NOT NULL, PRIMARY KEY (`vehicle_id`), KEY `user_id` (`user_id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ; /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; -------------------------------------------------------------------------------------------------------------------- event_entries: -- phpMyAdmin SQL Dump -- version 3.4.10.1 -- http://www.phpmyadmin.net -- -- Host: localhost -- Generation Time: May 15, 2012 at 03:58 PM -- Server version: 5.0.95 -- PHP Version: 5.2.9 SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO"; SET time_zone = "+00:00"; /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; /*!40101 SET NAMES utf8 */; -- -- Database: `oldtimer_regtest` -- -- -------------------------------------------------------- -- -- Table structure for table `event_entries` -- CREATE TABLE IF NOT EXISTS `event_entries` ( `event_id` int(11) NOT NULL auto_increment, `user_id` int(10) NOT NULL, `event_year` year(4) NOT NULL, `selected_vehicles` varchar(100) NOT NULL, `tour` tinytext NOT NULL, `parade` varchar(100) NOT NULL, `sales` tinytext NOT NULL, `remarks` varchar(1000) default NULL, `event_reg_date` datetime NOT NULL, PRIMARY KEY (`event_id`), KEY `user_id` (`user_id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ; /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; ------------------------------------------------------------------------------------------------------------------------- Hope this helps
  19. Hi all. I am running into an issue that I cannot solve with my still limited knowledge. I am developing a login and user page based on the login script of chapter 16. In short, the site is a login part of an oldtimer vehicle site. People can register an account, enter their vehicles and then register for an annual event by selecting vehicles they want to show on that event. I am currently trying to build a page where an admin-level user can print all the registered events for all the users with all the vehicles per event registration. The way we developed it is that the selected vehicles are imploded as a comma delmited line in the event_entries table. By means of an explode I am able to print all the selected vehicles back into a table. But only for 1 user. I am definitely using the wrong code, but I am stuck. I have 3 tables: users, vehicles and event_entries. I would like to print all the registrations for the event of for instance 2012. So the code should select the first event of 2012, then print all the information including the explosion of the selected vehicles. And then go on with the next event, etc, etc. This is how I exploded the values: while ($row = mysqli_fetch_array($r)) { $selection = $row['selected_vehicles']; } $selection = explode(',', $selection); // run query of selected vehicles to show in the rest of the form $q = "SELECT * FROM vehicles WHERE vehicle_id IN ('".join("','", $selection)."')"; $r = @mysqli_query ($dbc, $q); while ($row = mysqli_fetch_array($r)) { // echo several of these rows } Does anyone have any idea how I can repeat this process for all the rows in the database? I hope I make any sense and someone can help me with this limited info. Thanks! Mike
  20. Hello! I am almost at the end of the book, and after building and testing script 13.1 test_pattern.php, I get the following screen result, including error. The result of checking against is Deprecated: Function eregi() is deprecated in D:\xampp\htdocs\php-course\chapter_13\test_pattern.php on line 24 Warning: eregi() [function.eregi]: REG_EMPTY in D:\xampp\htdocs\php-course\chapter_13\test_pattern.php on line 24 FALSE! How can I work around this to continue testing this chapter? Thanks for your help! Loving the book! Mike
  21. Hi Stuart No I don't mind this feedback at all. And will also pass it to my "assistant". 1. I will dig into that Still a beginner, but I get what you mean. 2. I was already wondering myself how some variables never return. But since the thing works 3. Very nice! This one will be appeciated by my guy! Thanks again for your time helping me out! I'm having a ball making things up like this and actually seeing them into action. Eagerly learning PHP whenever I can Regards Mike
  22. Hello Stuart Thans for your reply. I also consulted a 19 year old nephew of my wife Very very smart kid. He's way ahead of me in PHP (why would I be reading the books otherwise) We figured something out that seems to work. And I would like to share that code if you allow me. Some words are in Dutch, but they don't matter for the script itself anyway. He made the basic script. I was able to turn it into functions after reading the last paragraphs of chapter 10 about globalizing. And we got it to work! I stored this code in the header.php I use and I call the functions when I need them in my bodies. Does the script make any sense? Thanks Mike <?php date_default_timezone_set('Europe/Amsterdam'); function date_in_words($num) { switch($num) { case 13: return "dertiende"; case 14: return "veertiende"; case 15: return "vijftiende"; case 16: return "zestiende"; case 17: return "zeventiende"; case 18: return "achtiende"; case 19: return "negentiende"; case 20: return "twintigste"; case 21: return "eentwintigste"; case 22: return "tweeentwintigste"; case 23: return "drieentwintigste"; } } $day=0; //$day store the value 1 (first day in month) (for some reason I figured out we had to change the value to 0, as it skipped if it was actually a FIRST of September $month=9; //$month store the value 9 (september) $year_long=date("Y"); //$year_long store the value of current year of server in long format (example "2011") $year_short=date("y"); //$year_short store the value of current year of server in short format (example "11") $date=strtotime("$day.$month.$year_long"); //$date store the timestamp for first day of steptember of current year $p=strtotime("next sunday", $date);//$p store the timestamp of next sunday from $date (that means it stores the timestamp of first sunday of september) $data_event=strtolower(date("j F Y ", $p)); //$data store the date of first sunday of september (we convert the timestamp in date format d-m-Y) $current_date=strtotime(date("j F Y")); function print_event() { global $current_date; global $p; global $year_short; if($p<$current_date) { $day_after=date("Y",strtotime("next year")); print date_in_words($year_short+3) ." "; //number of oldtimer edition is the year in short format +2 } else { print date_in_words($year_short+2) ." "; //number of oldtimer edition is the year in short format +2 } } function print_date() { global $current_date; global $p; global $year_short; global $day; global $month; global $data_event; if($p<$current_date) { $day_after=date("Y",strtotime("next year")); print strtolower(date("j F Y ", strtotime("next sunday", strtotime("$day.$month.$day_after")))); } else { print $data_event; } } ?>
  23. Dear Larry I have been reading edition 3 of the VQG with great interest and my mind is boiling over with ideas for a website that I build from scratch. Before I read the book even. Now. I am not through the book yet, but I was wondering if you could help me with the following. The event is a yearly oldtimer event. Every first Sunday of September at 23:59 I should change a couple of terms on a website, so that these terms count for the next year. Currently we are at the thirteenth event, which is on Sept 4th 2011 the word Thirteenth and the date are the variables I wish to print automatically every year. I was thinking to build an array providing the words Thirteenth, Forteenth, etc, etc But how can I print the 1st Sunday of the next year AND Change this automatically on the first Sunday of the current year at 23:59 Is this possible at all? Thanks a lot for your inspiring writing! I am ploughing through this one and then on to the php6 and mysql 5 book. It's already waiting for me Regards Mike
×
×
  • Create New...