Jump to content

Daleeburg

Members
  • Posts

    105
  • Joined

  • Last visited

    Never

Contact Methods

  • Website URL
    http://thebetatester.blogspot.com

Profile Information

  • Gender
    Male

Daleeburg's Achievements

Member

Member (2/5)

0

Reputation

  1. So I got this whack job idea that I would like to build a zip program. Not that I expect it to go anywhere, just use it as a personal learning experience and work on my PHP skills. I really like PHP and like to use it as a prototyping language because of how easy it is to work with, but I have run across one question that I have not been able to find an answer for. Is it possible to read the binary of a file? Everything on a computer is 1s and 0s, so in PHP is it possible to read all the 1s and 0s of a file and have them come out as a 1s and 0s string? Thanks for any help head of time.
  2. I spend a lot of time going through my data structures to attempt to make them as efficient as possible without repeating any data. On any given project I normally spend a large chunk of my time charting out my tables and the such to try to accommodate for everything. I am a big believer of 3rd normal form. I think the reason why the MySQL is normally the first thing to go down is because I am using shared hosting. I know that is not the best, but since I have to work on a tight budget, it normal fits the build the best. It just means that I have to consider things like caching. I have never though about checking the file time. It does make a lot of sense though. Normally i just run a regen of the cache whenever the an edit was done, but this would occasional cause problems.
  3. Simple Question: I am looking at building a website just for kicks, but I think it may see some heavy load. The front page would deal be dynamic in the fact that it would be updated, but it would only be updated ever 3 or 4 days. After looking at my options I have come with with 3 possible solutions: 1. Use MySQL to pull all the data all the time. This is probably the simplest and most straight forward way. Unfortunately on other websites i have made that got busy, it always seems like MySQL was the first thing to die, so I am kind of shying away from this. 2. Use XML. I have been playing around with XML lately and think it might be a good fit for this. I can keep an XML document with the data that would be on the homepage. When a visitor comes, the XML is parsed and displayed. I dont know how well this would work though, so I am looking for anybody with input. 3. Use PHP to create a static HTML page. I have done this before, pretty much I am making a cache of the page. It is really good at keeping CPU and memory usage at a minimum, but it is a pain to edit anything in the design. Anybody have any other suggestions or comments on how to handle load without installing a PHP caching utility?
  4. Did you put any header information in the file?
  5. i beleive what you are doing is trying to hid the value of $id when they hit up your site. The problem is that the way you are trying to do it is not possible because of how php is processed. Everything is done at run time, so the $id variable will only exist for the few seconds that it takes to run the script, after that it is gone and not longer exist. The value of it also disappears. This is why you can use the same variable on 2 different pages and not have to worry about cross contamination. If you are trying to hid the value from them, you may be best to set up a SQL table that looks at the unique identifier and then grabs the variable out of there. You would still have to pass the user name, or some other unique identifier, in the link, but it would not have to be what you do not want them to see. ~D
  6. Ok, i have been looking at your code of about 30 minutes now, and I think i understand your problem, and i think I have a cure. In the database call you get the product id out (which i am assuming is the $pid ) You are referencing everything in the array by the Product Id: So if the product id is 1234 the spot in the array would be $_SESSION['cart'][1234] If the product id is 4321 the array spot is $_SESSION['cart'][4321] So rather then using a 'foreach' why dont you just call it using the variable $pid ? the call would look like this <?php $result2 = mysql_query("SELECT * FROM parts WHERE MCHN='PH' ORDER BY LOC ASC") or DIE(mysql_error()); while($r2=mysql_fetch_array($result2)) { $pid=$r2["id"]; $loc=$r2["LOC"]; $pn=$r2["PN"]; $desc=$r2["DESC"]; $row_color = ($row_count % 2) ? $color1 : $color2; if (isset ($_SESSION['cart'])){ $quantity = $_SESSION['cart'][$pid]; $parts .= "<tr cellspacing=6><td align=center bgcolor=\"$row_color\">$loc</td><td bgcolor=\"$row_color\" width=\"100\">$pn</td><td bgcolor=\"$row_color\" width=\"330\">$desc</td><td></td><td><input type=\"text\" size=\"5\" name='items_quantity[{$pid}]' value=\"$quantity\" /></td></tr>"; } else { $parts .= "<tr cellspacing=6><td align=center bgcolor=\"$row_color\">$loc</td><td bgcolor=\"$row_color\" width=\"100\">$pn</td><td bgcolor=\"$row_color\" width=\"330\">$desc</td><td></td><td><input type=\"text\" size=\"5\" name='items_quantity[{$pid}]' value=\"0\" /></td></tr>"; } $row_count++; } ?>
  7. Here is the code I promised that works. Copy and paste it into a .php file and give it a run. <?php // Since this is an example, the page calls itself using PHP_SELF. // In production using PHP_SELF can cause a lot of problems. // // creates a session session_start(); setcookie(session_name(), session_id(), 0, "/", ""); // destroy the session, which resets the values IF($_GET['log'] == "out"){ session_destroy(); ECHO'<meta http-equiv="refresh" content="1; url='.$_SERVER['PHP_SELF'].'" />'; }; IF($_POST['order'] == 'order'){ // the oder has been placed $temp[1] = $_POST['product1']; $temp[2] = $_POST['product2']; $temp[3] = $_POST['product3']; $temp[4] = $_POST['product4']; $_SESSION['product'] = $temp; echo 'Stuff has been changed. Redirecting'; ECHO'<meta http-equiv="refresh" content="1; url='.$_SERVER['PHP_SELF'].'" />'; }else{ $product = $_SESSION['product']; echo '<form method="post" action="'.$_SERVER['PHP_SELF'].'">'; echo 'Product1: <input type="text" name="product1" value="'.$product[1].'"><br>'; echo 'Product2: <input type="text" name="product2" value="'.$product[2].'"><br>'; echo 'Product3: <input type="text" name="product3" value="'.$product[3].'"><br>'; echo 'Product4: <input type="text" name="product4" value="'.$product[4].'"><br>'; echo '<input type="submit" name="order" value="order">'; } ?> As for a PID, i have to think about that for a few minutes, but I do believe it is addressable in this context. ~D
  8. More or less yes, but the information gets saved because it is reinserted into the order form. So if there is an 8 in $product[1] then the Product 1 text box will have an 8 in it when they load the page and will still have an 8 in it when they hit submit, unless they edit. So yes, it will be over writinng the data that is already there, but if they dont change it, it will over write with whatever it started with. Give me a few minutes and i will write a working example script of what i am talking about. ~D
  9. I understand what you mean there, but i think I did not explain myself fully. I am assuming (which we all know what that does) you have an order screen that has all of your products listed with input boxes by them. If you made it so that when a user goes into the input screen the page calls the session array and places the values of the array as the default values. example below The values of the array $product = $_session['product']; $product[1] = 0; $product[2] = 5; $product[3] = 0; $product[4] = 1; The order page code (would have to be a forum <?php echo 'Product1: <input type="text" name="product1" value="'.$product[1].'"><br>'; echo 'Product2: <input type="text" name="product2" value="'.$product[2].'"><br>'; echo 'Product3: <input type="text" name="product3" value="'.$product[3].'"><br>'; echo 'Product4: <input type="text" name="product4" value="'.$product[4].'"><br>'; ?> Then when they submit it, it all goes back to the session array. (as below) The submit page $product[1] = $_POST[product1]; $product[2] = $_POST[product2]; $product[3] = $_POST[product3]; $product[4] = $_POST[product4]; $_session['product'] = $product Of course you would want to sterilize it so that you dont get negative numbers or text, but in basic it should work. ~D p.s. Since PHP is a dirty language that doesnt require you to specify array sizes, you could add more products by adding another text input box and adding it to the submit page.
  10. Is there a reason you are trying to merge them rather then replacing the values with the new rows? Have it call the Session array to fill the quantity box, then when they post/add it, just have it go in and change the row of the array. ~D
  11. oh and make sure the data is good and sterilized before you put it in.
  12. <?php $dbhost = '*****'; $dbuser = '*****'; $dbpass = '*****'; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error with database'); $dbname = 'url'; mysql_select_db($dbname); $getlist=mysql_query("SELECT u_id FROM addurl"); while($row=mysql_fetch_array($getlist)){ $text = file_get_contents($row[0]); mysql_query("insert into TableName (TableColoum) values ($text)"); } ?>
  13. If you are using php and dont want to change the tables of the database while using check boxes, then after the forum is submitted you could have it smash the data together with commas. You would still be able to search the data, but it would take a little more work. So if the user selects tuba, banjo, and harmonica, they would have to be in in an array, so that when it is submitted if position 1 has a value of 1 then "tuba," is inserted in the string then if position 3 has a value of 1 then "banjo," is inserted and so on so that the string ends up looking like "tuba,banjo,harmonica," and if you do the coding right you can get rid of the final comma, but it doesnt hurt for it to be there. ~D
  14. It was just a guess, sorry. ~D
×
×
  • 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.