Jump to content

juanc

Members
  • Posts

    16
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

juanc's Achievements

Member

Member (2/5)

0

Reputation

  1. chigley I've done that......it's just I haven't bothered entering that much detail onto what I've posted here... To sum my question.........how do you keep inserting values into an array that stays persistent across different pages?
  2. Hi I'm trying to make a basic shopping based on the idea that an item selected get's pushed into an array and then that array get's saved into a session variable. If I did this.. <?php $shop = array("plasma TV","DVD recorder","mountain bike","coffee maker"); $_SESSION['cart'] = $shop; ?> I'm able to access $_SESSION['cart'] with all the array values on a completely different page no problem. However I want to have a page listing items for sale then each time a customer clicks on an item that get's added to $_SESSION['cart'] and of course each time you are able to see the latest snapshot of the cart. I wrote this myself......... <?php // 1st page <a href=cart.php?id=1>Computer</a><br /> <a href=cart.php?id=2>CD collection</a> // then on cart.php if(!in_array($_GET['id'],$_SESSION['cart'])) { $items_in_cart[] = $_SESSION['cart']; $new_entry[] = $_GET['id']; $all_the_items = array_merge($items_in_cart,$new_entry); $all_the_items = $_SESSION['cart']; } ?> what basically happens is if I do a foreach loop on $_SESSION['cart'] it's fine...I see all the original items (Plasma TV etc) plus the new one selected....however if I were to leave the page and then re visit I only see the original items in the original $shop array ...and not the latest one to be selected. Hope someone can help.
  3. With regards to the numerical value of each day of the week. ie. Sunday is 0,Monday is 1,Tuesday is 2 and so on. I need the value for the day of the week that falls on the last day of the month. For example this month being August ……….so 31 Aug falls on a Thursday so that would be 4 What I’ve written doesn’t work properly. [code] <?php $month = date('n'); $year = date('Y'); $timestamp = mktime(0,0,0,$month,1,$year); $numOfdays = date('t',$timestamp); $lastDayDate = mktime(0,0,0,$month,$numOfdays,$year); $lastDayNumber = date('w',$lastDayDate); echo 'The number is ' . $lastDayNumber; ?> [/code] This actually works but if I change to being in respect this coming September ($timestamp = mktime(0,0,0,9,1,$year); it gives me 3 when it should be 6 as 30 Sep falls on a Saturday.  Similarly with October I get 4 when it should be 2 as 31 Oct falls on a Tuesday.
  4. thanks very much but I was hoping someone could show me "codewise" how $_SESSION['shopping_cart'] could end up holding all the id's for each item chosen
  5. Hi here’s some code I wrote earlier [code] //page1.php <a href=”page2.php?id=1”>Item 1</a><br /> <a href=”page2.php?id=2”>Item 2</a><br /> <a href=”page2.php?id=3”>Item 3</a><br /> <a href=”page2.php?id=4”>Item 4</a><br /> <a href=”page2.php?id=5”>Item 5</a><br /> //page2.php <?php session_start(); if(isset($_GET[‘id’]) {     $_SESSION[‘shopping_cart’] = $_GET[‘id’];   } ?> [/code] Simply what I want is a way for $_SESSION[‘shopping_cart’] to be able to hold all the id’s for each respective item selected.  For example if the user selected item 1, 3 and 5 the value for $_SESSION[‘shopping_cart’] should be 1, 3 and 5.  How could I do that?  Can the session become an array and I could loop through it with a foreach loop?
  6. Hi there can someone help me here. I'm trying create the same process as on this forum where you can preview the post. Basically I want the contents of a form's textarea to be written to a text file and then output the text file's content to the browser. Below is the code I've used, it works fine as far as writing to the file goes but it doesn't read out to the browser ....ie. echo $data doesn't work. Have I missed something obvious? [code] $file = "../scratchpad/" . $_POST['theID'] . "/scratchpad.txt"; $fh = fopen($file, "w+"); if($_POST['submit'])   {     fwrite($fh, $_POST['code']); // please not that $_POST['theID'], $_POST['submit'] and $_POST['code'] have all come from a form on another page $data = fread($fh,filesize($file)); echo $data; echo "<br /><br />"; echo "<form action=$_SERVER[PHP_SELF] method=post>"; echo "<textarea name=code rows=10 cols=50 wrap=virtual>$_POST[code]</textarea><br />"; echo "<input type=hidden name=theID value=$_POST[theID] />"; echo "<input type=submit name=submit_update value='Send to scratchpad' />"; echo "</form>";   } else if(($_POST['submit_update']) or ($_POST['submit_update2']))   {    fwrite($fh, $_POST['code']); $data = fread($fh,filesize($file)); echo $data; echo "<br /><br />"; echo "<form action=$_SERVER[PHP_SELF] method=post>"; echo "<textarea name=code rows=10 cols=50 wrap=virtual>$_POST[code]</textarea><br />"; echo "<input type=hidden name=theID value=$_POST[theID] />"; echo "<input type=submit name=submit_update2 value='Send to scratchpad' />"; echo "</form>";     }   fclose($fh); [/code][/code][/code]
  7. Hi I’m trying to display some thumbnail images I have via a mysql query. The problem I have though is in trying to achieve a certain layout. I want a row of three individual items then another three underneath and so on.  basically a replica of this…… http://www.templatemonster.com/category.php?type=0&tid=+-+Any+-&search_words=+-+Any+-&from_=&to=&cat=57&style=0&author=0&x=24&y=8 What I’ve always been used to in the past is outputting one item per row, where as this would be three database rows in one html table row.  is there possibly abit of code that could put in a line break each time three items are displayed. while($row = mysql_fetch_array($query))   {         // abit of code here to put in a line break after 3 items       echo row[‘item’];   } Or perhaps someone could suggest another way.
  8. Hey I have to say thanks especially if you just wrote that for me!
  9. Thanks for the reply........I thought about using a database table but the problem with that would be where customers don't go through to the check out ............I'd end up having rows that don't serve any purpose. Even so I was generally asking can a session variable keep having values appended to it and is that the typical approach?
  10. I'm trying to work out the basic mechanics of a shopping cart.......specifically how do the items selected get displayed in a temporary staging area...... Am I right in saying that you can keep appending items onto a session variable...then do an explode or foreach on it. If so can anyone give me any sample code to get me started and also is this the typical approach?
  11. Here’s a weird one for you all out there………. I wrote a script for a client that want’s to be able to upload pdf files that can sometimes be up to 12 meg ………..but typically 3 to 6. Anything up to 5 meg works fine but anything over that and the upload fails…………here’s the weird part………..my hosting service has increased both the post_max_size and upload_max_filesize to 12 m in each case. You can see my phpinfo() here: [a href=\"http://www.digital-services.co.uk/check.php\" target=\"_blank\"]www.digital-services.co.uk/check.php[/a] However when I do echo $_FILES[‘uploadedFile’][‘error’] it gives “1” the error code for when the file exceeds the upload_max_filesize………..plus the error log that gets generated says so too…….. here’s the lines from it….. [25-Apr-2006 16:24:30] PHP Warning: POST Content-Length of 12243998 bytes exceeds the limit of 8388608 bytes in Unknown on line 0 [10-May-2006 08:54:33] PHP Warning: upload_max_filesize of 5242880 bytes exceeded - file [uploadedFile=Derrick May - Strings of Life (Original Mix).mp3] not saved in Unknown on line 0 My guess is that as it’s some form of shared platform so the ini file I’m seeing isn’t really in respect of my instance of php. Before anyone says "contact your helpdesk" I already have but am still waiting to hear from them................I thought perhaps someone might know what the answer could be. Here’s the script I wrote [code] <?php set_time_limit(0); if($_POST['submit']) {    echo "The file is now uploading";     if(copy($_FILES['uploadedFile']['tmp_name'],  "pdfs/" . $_FILES['uploadedFile']['name']))       {         echo "<br /><br />The file has been uploaded successfully";                  unlink($_FILES['uploadedFile']['tmp_name']);       }     else       {         echo "The file was not uploaded<br /><br />";         echo "The error is <b> " . $_FILES['uploadedFile']['error'] . "</b>";               }                  echo "<br /><br /><a href=" . $_SERVER[PHP_SELF] . ">Upload another file</a>";                } else { ?> <form action="<?php echo $_SERVER[PHP_SELF] ?>" method="post" enctype="multipart/form-data"> File: <input type="file" name="uploadedFile" /> <input type="submit" name="submit" value="Submit" /> </form> <?php } ?> [/code]
  12. hi there I was just experimenting with a template engine script I came across......I've found it works up to a point although I'm experiencing a problem.......... The crux of it is that if you were to use an include file it's contents are outputted before any html .........then in the place holder where the contents should be a number "1" appears...........below is the code........I'm just hoping that it's something glaringly obvious that someone can quickly notice.........on the other hand it might be that the code is duff.......(btw.........here's the url for the original tutorial)[a href=\"http://www.tanru.com/php/replacement-template-engine.htm\" target=\"_blank\"]http://www.tanru.com/php/replacement-template-engine.htm[/a] This is the actual template engine script [code] <?php class template { var $ouput = NULL; function parseFile( $file ) { if (file_exists($file)) { $file = $file; } else { $file = "error.html"; } return file_get_contents($file); } function parseTemplate( $templ, $vars ) { $file = $this->parseFile($templ); foreach ($vars as $variable => $data) { $variable = '{' . $variable . '}'; $file = str_replace($variable, $data, $file); } $this->output = $file; } function display() { print $this->output; } } [/code] This is the instantiation of the classes object [code] <?php include ("class_template.php"); $data = array("TEST" => "This is a test", "PHP_FILE" => include("wow.php")); $tpl = new template; $tpl->parseTemplate("test.tpl", $data); $tpl->display(); ?> [/code] Finally this is test.tpl the actual file for the layout...........note that the output of wow.php appears before anything else and the number "1" appears where you see {PHP_FILE} [code] <!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> <title>{TEST}</title> </head> <body> {PHP_FILE} </body> </html> [/code]
  13. Hi can someone help me please, My goal is to add to different times into two different mySQL columns (in the same row and inputted one after the other) then calculate the number of minutes in between each. For each column I input using strftime('%H %M', time()) Then I used this function to calculate the difference [code] function DateDiff ($interval,$date1,$date2) {     // get the number of seconds between the two dates $timedifference = $date2 - $date1;     switch ($interval) {         case 'w':             $retval = bcdiv($timedifference,604800);             break;         case 'd':             $retval = bcdiv($timedifference,86400);             break;         case 'h':             $retval =bcdiv($timedifference,3600);             break;         case 'n':             $retval = bcdiv($timedifference,60);             break;         case 's':             $retval = $timedifference;             break;                  }     return $retval; } [/code] Then I did [code] echo DateDiff('n',$row[start],$row[end]); [/code] but it just gives back 0 .............at the same time I'll add that the mysql columns I originally had as varchar then changed them to time hope someone can help
  14. Hi thanks for this I'm guessing you envisage a button for people to logout and then unset the session............and then call a function to delete the table row where that ip occurs. The thing is it's actually for a company intranet and so everyone will have the same ip and secondly is there any way of doing this if the user justs closes their browser window?
  15. Hi I basically just need to be able to display all logged in users. The actual log in authentication I'm able to cope with and I can also get logged in users into a dbase table so as to display them. However I'm stuck on how to delete them from the table in the event of them logging off the site. I found tutorials but as always seems to be the case they're never exactly what you need. In short how can I clean up a mySQL table if the user logs off and the session ends. thanks Juan
×
×
  • 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.