Jump to content

h20boynz

Members
  • Posts

    27
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

h20boynz's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I am still looking for help on this if anyone can assist?...
  2. There is a computation component but the part I am struggling with is creating an array with all of the income/expense items to appear in a particular column and then sum these to determine a balance for each column...I've attached a diagram of what I mean. Looking at the table in the attached doc. you will see that in some cases an income or expense is only in one column. This is because it is a monthly frequency. If the user chose to review 8 weeks worth it would show it twice, in the column corresponding to the correct date range for it. The trick for me is that this all has to be determined from the info in the table which is the next due date, which won't actually change once entered by the user, and the frequency. So...the process is to fetch each inc/exp account that, using the next due date from each record and the corresponding frequency, will occur within the next 4 weeks, 8 weeks etc etc. Then put this into an array and repeat. This would be repeated for each column I think. (i.e. week 1, week 2 etc). Then it would be a matter or arranging these in the table in the correct columns and with the correct gaps etc....this is where I am really lost. I hope this all makes sense [attachment deleted by admin]
  3. Hello I am busy trying to setup a free to use budgeting and cashflow tool. I was recently going through my finances and whilst I found lots of spreadsheets on the subject, I didn't find a website that would allow me to store my data anonymously and access it when and where I felt fit. Bare in mind that I am a bit of a novice so go easy on me... So firstly, I've setup a page to collect 'account' information...that is, income items and expense items. I ask them to enter the amount, the frequency and when the next due date is. The DB looks like this: CREATE TABLE IF NOT EXISTS `income_accounts` ( `inc_acc_ID` int(11) NOT NULL AUTO_INCREMENT, `user_ID` int(11) NOT NULL, `freq_ID` int(11) NOT NULL, `amount` decimal(7,2) NOT NULL, `next_due` date NOT NULL, `income_typeID` int(11) NOT NULL, PRIMARY KEY (`inc_acc_ID`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=105 ; and the same for expense 'accounts': CREATE TABLE IF NOT EXISTS `expense_accounts` ( `exp_acc_ID` int(11) NOT NULL AUTO_INCREMENT, `user_ID` int(11) NOT NULL, `freq_ID` int(11) NOT NULL, `amount` decimal(7,2) NOT NULL, `next_due` date NOT NULL, `ex_typeID` int(11) NOT NULL, PRIMARY KEY (`exp_acc_ID`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=13 ; So once I have these entered by the user I should be able to then generate a cashflow forecast. For example, I give 5 options for the user: '4 weeks' , '8 weeks', '3 months', '6 months' '12 months'. Selecting one of these will then generate a table listing all of the items that apply for each period with a total at the bottom. Lets take '4 weeks' for an example. First I need to determine if the 'next_due' value is within the time period selected (4 weeks). If it is, what frequency is it? If it is every week then each column of the 4 column table created (i.e. 4 weeks/4 columns) will have it in it. If it is monthly frequency it will be only in the column for which it is due (i.e. column 1 would be todays date to todays date +6, column 2 = todays date + 7 to todays date +13 etc...) This will go through both the income table and the expense table and once all the items have been checked and added to the page table a further row would be added to total all the items in each column, and give a sum (i.e. sum of incomes less sum of expenses). For the '6 month' and '12 month' option, I want to display 1 month per column, rather than 1 week...just to not squeeze things up to much... I do not have a great deal of experience with arrays but my instinct tells me that they are the answer....otherwise I guess I could create a temporary DB table? I'm happy to share the code I've written so far if it helps...otherwise any advice on the best way to achieve this would be great.
  4. Anyone?...I'm still fumbling with this
  5. I have a loop creating a block_vars array for displaying records from a database. (In this case auction listings). The following code creates this array: // get random selection of 6 items for home page display $query = "SELECT id, title, current_bid, pict_url, ends, num_bids, minimum_bid, bn_only, buy_now, subtitle, starts, ends, reserve_price FROM " . $DBPrefix . "auctions WHERE closed = 0 AND suspended = 0 AND starts <= " . $NOW . " ORDER BY RAND() DESC LIMIT 6"; $res = mysql_query($query); $system->check_mysql($res, $query, __LINE__, __FILE__); $showendtime = false; $has_ended = false; $k = 0; while($row = mysql_fetch_assoc($res)) { $ends = $row['ends']; $difference = $ends - time(); if ($difference > 0) { $ends_string = FormatTimeLeft($difference); } else { $ends_string = $MSG['911']; } $high_bid = ($row['num_bids'] == 0) ? $row['minimum_bid'] : $row['current_bid']; $high_bid = ($row['bn_only'] == 'y') ? $row['buy_now'] : $high_bid; //determine whether the auction has a Buy Now price, show if appropriate. if($row['buy_now'] == '0.0000') { $bnamount = ""; } else { $bnamount = "<a href='" . $system->SETTINGS['siteurl'] . "buy_now.php?id=" . $row['id'] ."'>$" . substr($row['buy_now'], 0, -2) . "<br />" . "Buy Now</a>"; } //determine if the auction has a reserve set and if it has been met. display appropriate symbol if($row['reserve_price'] == '0.0000' && $row['bn_only'] == 'n' && ($row['current_bid'] < $row['minimum_bid'])) { $flag = '<img src="images/noreserve.gif" alt="No Reserve">'; $flagdesc = " No Reserve!"; $bnonly = "Current Bid<br />"; } else { if($row['current_bid'] >= $row['reserve_price']) { $flag = '<img src="images/reservemet.gif" alt="Reserve Met">'; $flagdesc = " Reserve Met!"; $bnonly = "Current Bid<br />"; } else { $flag = '<img src="images/noflag.gif">'; $flagdesc = ""; $bnonly = "Current Bid<br />"; } } if($row['reserve_price'] == '0.0000' && $row['bn_only'] == 'y') { $flag = '<img src="images/noflag.gif">'; $flagdesc = ""; $bnonly = "Asking Price "; $bnamount = ""; } $template->assign_block_vars('randomitems', array( 'ID' => $row['id'], 'BID' => $bnonly . "$" . substr($high_bid, 0, -2), 'IMAGE' => (!empty($row['pict_url'])) ? 'getthumb.php?w=' . $system->SETTINGS['thumb_show'] . '&fromfile=' . $uploaded_path . $row['id'] . '/' . $row['pict_url'] : 'images/email_alerts/default_item_img.jpg', 'TITLE' => $row['title'], 'BUY_NOW' => $bnamount, 'SUBTITLE' => $row['subtitle'], 'TIMELEFT' => $ends_string, 'NUMBIDS' => $row['num_bids'], 'FLAG' => $flag, 'FLAGDESC' => $flagdesc )); $k++; } Pretty straightforward. You will see I have a TIMELEFT value which will show on my home page as no.days, no.hours, no.mins until it closes etc. Here is the html in the tpl file: <!-- BEGIN randomitems --> <div style="float:left;display:block;width:99%;border-bottom:#CCCCCC 1px solid;padding:2px;"> <div style="display:block;"> <table width="100%"> <tr> <td align="center" style="vertical-align:middle;width:120px" > <a href="{SITEURL}item.php?id={randomitems.ID}"><img src="{randomitems.IMAGE}" alt="{randomitems.TITLE}" style="border: none;width:120px"></a> </td> <td align="left" width="40%"> <table style="width:100%; vertical-align:middle; margin:0 auto"> <tr> <td><a id="itemdesc" href="{SITEURL}item.php?id={randomitems.ID}">{randomitems.TITLE}</a><br /> {randomitems.SUBTITLE}</td> </tr> <tr> <td id="closes">Closes in:{randomitems.TIMELEFT}</td> </tr> <tr> <td>{randomitems.FLAG}{randomitems.FLAGDESC}</td> </tr> </table> </td> <td id="buynow" align="center" width="15%"> {randomitems.BUY_NOW} </td> <td id="currentbid" align="center" width="25%"> {randomitems.BID} </td> </tr> </table> </div> </div> <!-- END randomitems --> This works quite nicely for me. What I want, and cannot manage thus far is to have the TIMELEFT value count down. The closest I have come is using a function like this: <script type="text/javascript"> $(document).ready(function() { var currenttime = '{randomitems.TIMELEFT}'; function padlength(what) { var output=(what.toString().length == 1)? '0' + what : what; return output; } function displaytime() { currenttime -= 1; if (currenttime > 0){ var hours = Math.floor(currenttime / 3600); var mins = Math.floor((currenttime - (hours * 3600)) / 60); var secs = Math.floor(currenttime - (hours * 3600) - (mins * 60)); var timestring = padlength(hours) + ':' + padlength(mins) + ':' + padlength(secs); $("#ending_counter").html(timestring); setTimeout(displaytime, 1000); } else { $("#ending_counter").html('<span class="errfont">{L_911}</span>'); } } setTimeout(displaytime, 1000); }); </script> This code is placed in the tpl file and I simply give an html element the appropriate ID. The problem with this is that it would only show a countdown timer for the first item returned, which is no good as there are always six items returned. Can anyone offer a suggestion on how I could go about this? I can PM anyone with suggestions with a link to my development site so you know what I am raving about.
  6. Solved! My big problem was in not understanding how a tpl file works. Solved the problem as follows: // Prepare categories sorting if ($system->SETTINGS['catsorting'] == 'alpha') { $catsorting = ' ORDER BY cat_name ASC'; } else { $catsorting = ' ORDER BY sub_counter DESC'; } $query = "SELECT cat_id FROM " . $DBPrefix . "categories WHERE parent_id = -1"; $res = mysql_query($query); $system->check_mysql($res, $query, __LINE__, __FILE__); $query = "SELECT * FROM " . $DBPrefix . "categories WHERE parent_id = " . mysql_result($res, 0) . " " . $catsorting . " LIMIT " . $system->SETTINGS['catstoshow']; $res = mysql_query($query); $system->check_mysql($res, $query, __LINE__, __FILE__); while ($row = mysql_fetch_assoc($res)) { $template->assign_block_vars('cat_list', array( 'CATAUCNUM' => ($row['sub_counter'] != 0) ? '(' . $row['sub_counter'] . ')' : '', 'ID' => $row['cat_id'], 'IMAGE' => (!empty($row['cat_image'])) ? '<img src="' . $row['cat_image'] . '" border=0>' : '', 'COLOUR' => (empty($row['cat_colour'])) ? '#FFFFFF' : $row['cat_colour'], 'NAME' => $category_names[$row['cat_id']] )); $subcats = getsub($row['cat_id'],$catsorting); while($subrow = mysql_fetch_assoc($subcats)) { $template->assign_block_vars('cat_list.sub_list', array( 'SNAME' => $subrow['cat_name'], 'SID' => $subrow['cat_id'] )); } } This creates a nested block_vars, then I just needed to get my html right in the tpl file, as follows: <div id="menu"> <ul> <li id="top"><a href="browse.php?id=0">{L_276}</a></li> <!-- BEGIN cat_list --> <li> <a href="browse.php?id={cat_list.ID}">{cat_list.IMAGE}{cat_list.NAME}</a> <ul> <!-- BEGIN sub_list --> <li><a href="browse.php?id={cat_list.sub_list.SID}">{cat_list.sub_list.SNAME}</a></li> <!-- END sub_list --> </ul> </li> <!-- END cat_list --> <li id="bottom"><a href="{SITEURL}browse.php?id=0">{L_277}</a></li> </ul> </div> Seems to be doing the job now...though as suggested above its probably not the most efficient method. Any further advice would still be appreciated.
  7. Thanks Thorpe I found that tutorial and read it but can't figure out how to apply that to my example. The table has a cat_id field which is unique and a parent_id field that relates a submenu item to its parent. The first query gets the record with the parent_id of -1. Only one record has this and that is the category 'ALL', which has a cat_id of '1'. Each first level category in the table then has a parent_id value of 1 and these records get queried in the second query. Now I apply each result row to an array which builds my menu of 1st level categories. Now I've got clever with my CSS (Not really) and generated flyout menus which I'd like to populate with the 2nd level categories. I figured I could do this within the loop, for each row of the 1st level category query. I only went for the function because putting a second loop inside the existing while wasn't working for me either. I'm certainly open to any other suggestions? ...
  8. I've created a function getsub(). The idea is that this function contains a query that grabs records from the categories table, using the $row['cat_id'] that I pass to it from within an existing while ($row=mysql_fetch_assoc($res)) loop. Heres the function: function getsub($rowid,$catsort) { global $system, $LANGUAGES, $subres; $subquery = "SELECT * FROM webid_categories WHERE parent_id = " . $rowid . " " . $catsort; $subres = mysql_query($subquery); $system->check_mysql($subres, $subquery, __LINE__, __FILE__); return $subres; } And heres the code that calls this function and passes the $row['cat_id'] value to it: // prepare categories list for templates/template // Prepare categories sorting if ($system->SETTINGS['catsorting'] == 'alpha') { $catsorting = ' ORDER BY cat_name ASC'; } else { $catsorting = ' ORDER BY sub_counter DESC'; } $query = "SELECT cat_id FROM " . $DBPrefix . "categories WHERE parent_id = -1"; $res = mysql_query($query); $system->check_mysql($res, $query, __LINE__, __FILE__); $query = "SELECT * FROM " . $DBPrefix . "categories WHERE parent_id = " . mysql_result($res, 0) . " " . $catsorting . " LIMIT " . $system->SETTINGS['catstoshow']; $res = mysql_query($query); $system->check_mysql($res, $query, __LINE__, __FILE__); while ($row = mysql_fetch_assoc($res)) { $subcats = getsub($row['cat_id'],$catsorting); while($subrow = mysql_fetch_assoc($subcats){ $template->assign_block_vars('sublist', array( 'SID' => $subrow['cat_id'], 'SNAME' => $category_names[$getrow['cat_id']] )); } $template->assign_block_vars('cat_list', array( 'CATAUCNUM' => ($row['sub_counter'] != 0) ? '(' . $row['sub_counter'] . ')' : '', 'ID' => $row['cat_id'], 'IMAGE' => (!empty($row['cat_image'])) ? '<img src="' . $row['cat_image'] . '" border=0>' : '', 'COLOUR' => (empty($row['cat_colour'])) ? '#FFFFFF' : $row['cat_colour'], 'NAME' => $category_names[$row['cat_id']] )); } then a .tpl file just references the {sublist.SID} and {sublist.SNAME} variables. BUT.... It ain't working. My page just goes blank. Any help would be massively appreciated.
  9. Hey there... Yeah quite right. I'll make that change as I go along. I was mainly just trying to get it to work when I used those names
  10. I'm trying to teach myself how to use functions and includes in my scripts. As an exercise I am trying to create a registration system that I can re-use on other future projects. I have my main register.php page as follows: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta content="text/html; charset=utf-8" http-equiv="Content-Type" /> <title>Register</title> </head> <body> <?php ini_set('display_errors', 1); ini_set('log_errors', 1); ini_set('error_log', dirname(__FILE__) . '/error_log.txt'); error_reporting(E_ALL); // Check to see if query string is set, if not pass empty array to function. if((!isset($_GET['success'])) && (!isset($_GET['active'])) && (!isset($_GET['valid']))) { include ('registerform.php'); $invalidcode = array(); regform($invalidcode); } //If success is set, use value to determine response if(isset($_GET['success'])) { if($_GET['success'] == "false") { echo "There has been an error with your registration. You will be redirected to the registration page in 5 SECONDS."; echo "<meta http-equiv=refresh content =\"5; URL=index.php\">"; } if($_GET['success'] == "true") { echo "Thanks for registering. An activation email has been sent to your registered email address.<br />"; echo "Please check you email and follow the activation link contained within it."; } } //if active is set, determine response (note: code to be added here in future) if(isset($_GET['active'])) { if($_GET['active'] == "true") { echo "Thank you for activating this account.<br />"; echo "You may now return to the home page and login!"; } } //if valid is set there was a problem with the form validation. //get valid from query string, convert back to an array and pass array to the form display script if(isset($_GET['valid'])) { $invalidcode = $_GET['valid']; $invalidcode = unserialize(urldecode($invalidcode)); include ('registerform.php'); regform($invalidcode); } ?> </body> </html> When the page loads it first checks for any variables passed in the url to determine action. Heres the code for the function regform(): <?php function regform($errors) { //set variables to initial value to prevent undefined variable error $errors0 = 0; $errors1 = 0; $errors2 = 0; $errors3 = 0; $errors4 = 0; $errors5 = 0; $errors6 = 0; $errors7 = 0; //check to make sure the array that was passed was not empty //from my validation script the errors are in matching order to the display on this page. //I have only prepared 2 errors for this inital testing, there will be one for each field on the form. $i = count($errors); if($i > 0){ $errors0 = $errors[0]; $errors1 = $errors[1]; //$errors2 = $errors[2]; //$errors3 = $errors[3]; //$errors4 = $errors[4]; //$errors5 = $errors[5]; //$errors6 = $errors[6]; //$errors7 = $errors[7]; } echo "<form id='register' name='register' method='post' action='doreg.php' >"; echo "<table>"; //if the variable = 1 there was an error validating the field in the validate script if($errors0 == 1){ echo "<tr><td><font color='red'>First Name</font></td><td><input type='text' name='firstname' /></td><tr>"; } else { echo "<tr><td>First Name</td><td><input type='text' name='firstname' /></td><tr>"; } if($errors1 == 1){ echo "<tr><td><font color='red'>Last Name</font></td><td><input type='text' name='lastname' /></td><tr>"; } else { echo "<tr><td>Last Name</td><td><input type='text' name='lastname' /></td><tr>"; } //additional errors to be added, as per abov,e for the code below echo "<tr><td>Email Address</td><td><input type='text' name='email' /></td><tr>"; echo "<tr><td>Password</td><td><input type='password' name='password1' /></td><tr>"; echo "<tr><td>Confirm Password</td><td><input type='password' name='password2' /></td><tr>"; echo "<tr><td></td><td></td><tr>"; echo "<tr><td>Accept Terms?</td><td><input type='checkbox' name='accept' /></td><tr>"; echo "<tr><td>Security String</td><td><input type='text' name='secstring' /></td><tr>"; echo "<tr><td></td><td><input type='submit' name='submit' value='submit' /></td><tr>"; echo "<tr><td></td><td><input type='hidden' name='form_submit' value='1' /></td><tr>"; echo "</table>"; echo "</form>"; } ?> So the form takes the array ?valid passed to the register page and determines which fields had a validation error and highlights them red. (I'll modify this highlighting to be what ever I need later...just testing my logic ) The form then calls doreg.php on submit. This will firstly run the validate script, then perform DB actions if all ok, else it will return to register with the error array passed in a query string: <?php if($_POST['form_submit'] == 1) { include ('validate.php'); //the validate script returns $errorarray. Need to figure out better way to test values to determine if any error flags are set if(($errorarray[0]!=0) or ($errorarray[1]!=0) or ($errorarray[2]!=0)) { $errorarray = urlencode(serialize($errorarray)); echo "<meta http-equiv=refresh content=\"0; URL=register.php?valid=$errorarray\">" ; } echo "<meta http-equiv=refresh content=\"0; URL=register.php?success=true\">"; } ?> php] And finally there is the actual validation script. I was hoping to be able to use this for all form validations across the site. I'll just add if(isset) for the various form fields and make sure I standardize my field names across my sites forms. [code=php:0] <?php $errorarray = array(); if($_POST['firstname'] == "") { $errorarray[0] = 1; } else {$errorarray[0] = 0; } if($_POST['lastname'] == "") { $errorarray[1] = 1; } else {$errorarray[1] = 0; } if($_POST['email'] == "") { $errorarray[2] = 1; } else {$errorarray[2] = 0; } return $errorarray; ?> For this example I have just done simple empty string checks. I'd really appreciate any advice on the code I've written to date. Im quite sure there are more elegant ways to achieve what these scripts do and I would greatfully accept any feedback. (Be gentle...I'm new ) Thanks
  11. It wasn't that I thought it was insecure...just that this particular book offered this as an option.
  12. What I have done in the past is created a conn.php file, used as an include, when I wish to connect to my DB. As a security measure, rather than have my connection info in a file that could potentially get accessed by unauthorised users, I read that I could use environment variables and store the database connection string values i.e username, password etc for retrieval. Can anyone offer some guidance on going about this? Thanks
  13. Hey Octo That works kinda...now I need to make a couple of mods, insert the results in a table, and query. I'll give it a good crack and post my results back! Thanks again!
×
×
  • 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.