Jump to content

aebstract

Members
  • Posts

    1,105
  • Joined

  • Last visited

Posts posted by aebstract

  1. It's not a query problem, I have it working fine.. I'm just translating it over so that it works globally depending on the variable that is set, which comes from the url from the previous page. All I need to do is plop a variable in, which means I need to actually create a variable from the result of another variable. Which logically would be $$sheet or $($sheet). If $sheet = ph then I want $ph. If $sheet = fp then I want $fp.

     

    $sheet = ($_GET['sheet']);
    
    mysql_connect("localhost","berryequipment","gU8Kso8Y") or die(mysql_error());
    mysql_select_db("berryequipment_net");
    
    $id = $_SESSION["id"];
    $result = mysql_query("SELECT * FROM plants WHERE id='$id'") or DIE(mysql_error());
    
    while($r=mysql_fetch_array($result))
    {
    
    $id=$r["id"];
    $plantloc=$r["plantloc"];
    $address=$r["address"];
    $ph=$r["PH"];
    $fp=$r["FP"];
    
    if ($$sheet == 0) {
    header("Location: acchome.php");
    }
    }
    
    

     

     

     

    $result2 = mysql_query("SELECT * FROM parts WHERE MCHN=$sheet 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"];
    

     

    Two different parts that would feed off of this, but I really just need to get that variable created?

  2. I guess that is how I could explain it..

    Here is what I have:

    if ($$sheet == 0) {
    header("Location: acchome.php");
    }

     

    Which isn't working, probably pretty obvious. I have a variable "sheet" and need to check if it is set to 0. The variable sheet could be set to a number of different things, and depending on what it is, it will check against the correct db column, which is what sheet is set to. This is why I need a $ in front of my variable. Is there a way to do this?

  3. As I stand now, I have my form display correctly, when I put in a value and go back, it updates the 0's to the new numbers. Problem is that I am doing this within a while so that I can use my unique id's, though when I put a foreach to split my session array up and then show the form, it displays each row 18 times (or however many items I have).

     

    $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'])){
    foreach ($_SESSION['cart'] as $product_id => $quantity) {
    $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++;
    }
    

  4. Yeah I am lost. Here was my attempt, which is failing to work correctly:

     

    if (isset ($_SESSION['cart'])){
    foreach ($_SESSION['cart'] as $product_id => $quantity) {
    $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>";
    }
    

     

    Also, something that is important is that the items have a unique id in the database, which is what we should be matching these results up with. (pid) This way, if they were to go to another order page (there will be multiple order forms, different ones for each machine) it has the values set in the boxes the correct way it should.

  5.  

     

     

    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
    

     

     

    This is still going to just override the information I have already saved rather than merging it together as one/new value, isn't it?

  6. The reason I am not just replacing is:

     

    If they added 5 of item one to start, then they went and added 10 more of item one.. they should have 15 of item one. If I replaced it, they would just end up with 10 of item one. Another example for not just replacing it with the new values is: If they add 10 of item one, and then go back and add 10 of item two, it would replace item one with 0 and they would be left with only item two. I hope that makes sense. I need some way for it to check each line in the array and add the qty's of the previous values with the qty's of the new values and keep it all in the session.

  7. I've got a script I am working on to function as a shopping cart. I can add items to the cart and it sets in my session, though I am trying to get a way so that if I was to add another item or even update the items that I already have, I can update my session with the new numbers. Be it adding, subtracting or keeping the values the same. I am trying to use array_merge, though atm when I go back and try to add more items, it simply starts numbering at the bottom and adding more. Right now I have 18 items, and here is what you get after going back and adding more items a few times:

    1 - 10
    
    2 - 0
    
    3 - 0
    
    4 - 0
    
    5 - 0
    
    6 - 0
    
    7 - 0
    
    8 - 0
    
    9 - 0
    
    10 - 0
    
    11 - 0
    
    12 - 0
    
    13 - 0
    
    14 - 0
    
    15 - 0
    
    16 - 0
    
    17 - 0
    
    18 - 0
    
    19 - 15
    
    20 - 6
    
    21 - 3
    
    22 - 2
    
    23 - 9
    
    24 - 0
    
    25 - 0
    
    26 - 0
    
    27 - 0
    
    28 - 0
    
    29 - 0
    
    30 - 0
    
    31 - 0
    
    32 - 0
    
    33 - 0
    
    34 - 0
    
    35 - 0
    
    36 - 0

     

    As you can see, it just keeps going. This is a problem because I am matching up the stored id of the items with the database, which if it continues down like this, it won't match up. Here is what I have:

     

    
    
    if (isset ($_POST['submit']))
    {
    
    if (isset ($_SESSION['cart'])){
    $_SESSION['cart'] = array_merge ($_SESSION['cart'], $_POST['items_quantity']);
    } else {
    foreach ($_POST['items_quantity'] as $product_id => $quantity) {
    $_SESSION['cart'] = $_POST['items_quantity'];
    }
    }
    }
    
    

  8. <?php
    session_start();
    header("Cache-control: private");
    if(!isset($_SESSION["id"]))
    {
    header("Location: account.php");
    }
    
    mysql_connect("localhost","berryequipment","gU8Kso8Y") or die(mysql_error());
    mysql_select_db("berryequipment_net");
    
    $id = $_SESSION["id"];
    $result = mysql_query("SELECT * FROM plants WHERE id='$id'") or DIE(mysql_error());
    
    while($r=mysql_fetch_array($result))
    {
    
    $id=$r["id"];
    $plantloc=$r["plantloc"];
    $address=$r["address"];
    $ph=$r["PH"];
    
    if ($ph == 0) {
    header("Location: acchome.php");
    }
    }
    
    
    
    
    if (isset ($_POST['submit']))
    {
    
    if (isset ($_SESSION['cart'])){
    $_SESSION['cart'] = array_merge ($_SESSION['cart'], $_POST['items_quantity']);
    } else {
    foreach ($_POST['items_quantity'] as $product_id => $quantity) {
    $_SESSION['cart'] = $_POST['items_quantity'];
    }
    
    }
    
    ?>
    

     

    I'm almost certain it is not anywhere else in the page. There error is saying:

    Parse error: parse error, unexpected $ in /home/virtual/site130/fst/var/www/html/cart.php on line 199

    199 is the last line of the code. (the entire page isn't shown, shown is like lines 1-something)

  9. Are you wanting to click calculate and then reload the page with the answer or are you wanting it to display the answer immediately without reload? If the second option is what you want, you need javascript to go with this. If you are going strictly php with a reload on the page, why not just make 4 forms?

  10. <?php
    
        $color1 = "#dddddd"; 
        $color2 = "#c0c0c0"; 
        $row_count = 0;
    $parts .= "<table width=732 cellpadding=3><tr bgcolor=#b2b2b2 cellspacing=6><td width=10 align=center>L</td><td width=10 align=center><strong>R</td><td width=10 align=center></td><td width=10 align=center>LOC</td><td>Part Number</td><td>Description</td></tr><br />";
    
    
    $result2 = mysql_query("SELECT * FROM parts WHERE MCHN='PH' ORDER BY LOC ASC") or DIE(mysql_error());
    while($r2=mysql_fetch_array($result2)) 
    { 
    $loc=$r2["LOC"];
    $pn=$r2["PN"];
    $desc=$r2["DESC"];
    
    $row_color = ($row_count % 2) ? $color1 : $color2;
    
    $parts .= "<tr cellspacing=6><td align=center>1</td><td align=center>2</td><td align=center>3</td><td align=center bgcolor=\"$row_color\">$loc</td><td bgcolor=\"$row_color\">$pn</td><td bgcolor=\"$row_color\">$desc</td></tr><br />";
    
    $row_count++;
    }
    
    $parts .= "</table>";
    
    
    
    $content .= "
    <p><u>$plantloc</u> - Paw Harvester</p>
    ";
    
    
    
    echo "$content";
    echo "$parts";
    
    ?>

     

    This script is causing a weird gap of blank space between $content & $parts and I don't see a reason for it to do so?

  11. I have a lot of items in a database and when I go to pull them out and display them in the browser, I want to put them in order by their "loc" number. What it is doing is putting them in the following order:

     

    1,10,11,12,13,14,15,16,17,18,19,2,20,21, etc...

     

    what I want it to display as is:

    1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, etc..

     

    the code:

    $result2 = mysql_query("SELECT * FROM parts WHERE MCHN='PH' ORDER BY LOC") or DIE(mysql_error());
    
    while($r2=mysql_fetch_array($result2)) 
    { 
    $loc=$r2["LOC"];
    $pn=$r2["PN"];
    
    $parts .= "$loc - $pn<br />";
    
    
    }
    

  12. Hopefully this bit of information might help as well:

     

    <select name="dropdown"><option value="18">Pilgrim's Pride - </option>
    <option value="16">Tyson Foods - A</option>
    <option value="1">Tyson Foods - Clarksville, AR</option>
    <option value="17">Tyson Foods - G</option>
    </select>

     

    This was when I went to the page and click view > page source to see if the id was actually inserting in to the value. It is, so I am not grabbing it correctly somehow?

×
×
  • 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.