Jump to content

dtyson2000

Members
  • Posts

    93
  • Joined

  • Last visited

Posts posted by dtyson2000

  1. Hi everybody...

     

    I've recently decided to clean up the mess that is my php coding. It's all over the place and I can't keep doing it this way. Does anybody have a reference they would like to share for proper php markup, spacing, etc.? I search around but find bits and pieces of things on various sites.

     

    I would really appreciate it.

     

    Thanks!

  2. Hey there, folks.

     

    I'm not sure where to start with this and really only need to be pointed in the right direction so I can figure it out. So I would appreciate any pointers you may be able to provide.

     

    I have a query that selects all sorts of information from a database and one of those bits of information is CITY. The results pop up fine and everything is ordered by that particular field - CITY. Some cities have 10 results, others 1 and depending on the user input, they can all come out in one big list, which is fine and great and ok and whatever.

     

    What I need is this:

     

    I would like to be able to add some header text above each section of cities:

     

    NEW YORK

    1 | New York

    2 | New York

    3 | New York

     

    Athens

    1 | Athens

    2 | Athens

     

    Paris

    1 | Paris

     

    See what I mean?

     

    Currently, I get:

     

    Athens

    1 | Athens

    Athens

    2 | Athens

     

    So I've just got the city header running through the loop and echoing above each record. Again, I'd just like to echo it one time above a group of cities.

     

    Any info would be appreciated. Thanks!

  3. Ok that's interesting; it looks like you're trying to create a pivot table BUT with an unknown number of potential columns (i.e. quantityPID2, quantityPID9.

     

    My question to you is WHY do you require this? What's wrong with just 2 rows for the orderID 10026? What is it you plan on doing with this information?

     

    It's to simplify an accounting procedure. We're using zen cart software and several months ago, we did the multiple row thing with the query I wrote. It wasn't a HUGE deal to do it that way. I just thought I would simplify the output. The data is subsequently put into Excel and, with multiple rows, requires quite a bit of editing (which, again, isn't a huge deal).

     

    There is actually a finite number of products - I believe there are only 9. So there would really only be a potential of nine columns.

     

    A "pivot table" you say? Hmm... I'll see what I can find about these... Thanks!

  4. Hi mysql guys (or gals, as the case may be). Sorry to bug you with something that is probably pretty simple but...

     

    I have a table for purchases (orders) that includes a column for productID and quantity. When a customer places an order that has more than one product, the order is split into two rows accounting for the productID and a quantity with each row containing the same orderID.

     

    table: orders
    
    orderID || productID || quantity
    10026 || 2 || 10
    10026 || 9 || 1

     

    I want to produce a query that combines the orderID and the productID and quantity into one row.

     

    SELECT orderID, productID, quantity FROM orders GROUP BY orderID;
    
    This results in:
    
    orderID || productID || quantity
    10026 || 9 || 1

     

    How can I produce the following result:

     

    orderID || quantityPID2 || quantityPID9
    10026 || 10 || 1

     

    I have a basic understanding of MySQL and can certainly implement solutions as I find them in the manual but I just don't know where to start. I've thought about JOIN, SUM, GROUP_CONCAT, etc, etc... But I just can't come up with a solution.

     

    Any thoughts?

     

    Thanks, in advance!

  5. Hi All...

     

    I've used a script that I found (very simple one) to upload files to a server via a handy-dandy form. The form also has other text fields - no problem. Everything goes into my database including the file name and the file uploads to the directory I need.

     

    Here's the problem:

     

    Suppose I realize that I've made a spelling error in one of those text fields. I click to edit the record and make the change, submit and "where did the filename that was attached to that record go??"

     

    If I need to actually edit the record and change the file, no problems. What I see happening is that, if I don't select a file to upload (because I may not need to), the script is attempting to upload a file without one actually being chosen, then wiping the filename out of the database.

     

    Here's the form item:

    <input type= 'file' name='event_file' value='$event_file'>
    

     

    Here's the function:

    function upload(){
      $target_path = "../upload/";
    
      $target_path = $target_path . basename( $_FILES['event_file']['name']);
      $_FILES['event_file']['tmp_name'];
    
      if(move_uploaded_file($_FILES['event_file']['tmp_name'], $target_path)) {
          echo "The file ".  basename( $_FILES['event_file']['name']). 
          " has been uploaded";
          $event_file = basename( $_FILES['event_file']['name']);
      } else{
          echo "There was an error uploading the file, please try again!";
      }
    }
    
    

     

    I'm using the standard UPDATE table SET column='updated column'... in the database.

     

    Should I be using ISSET or something where the value of the file input in the form is concerned? If you need more code, let me know. Thanks, in advance!

     

  6. Ok... now I'm wondering. I don't think there's anything initially wrong with the way that the first query is done (or is there?). It's just your basic form with multiple search fields.

     

    <table>
    ...
    <tr>
    <td>Zip Code:</td>
    <td><input type='text' name='zipcode' size='47'></td>
    </tr>
    </table>
    
    <table>
    <tr>
    <td>
    <input type='checkbox' name='day[]' value='Sunday'>Sunday 
    <input type='checkbox' name='day[]' value='Monday'>Monday 
    <input type='checkbox' name='day[]' value='Tuesday'>Tuesday 
    <input type='checkbox' name='day[]' value='Wednesday'>Wednesday 
    <input type='checkbox' name='day[]' value='Thursday'>Thursday 
    <input type='checkbox' name='day[]' value='Friday'>Friday 
    <input type='checkbox' name='day[]' value='Saturday'>Saturday
    </td>
    </tr>
    </table>
    

     

    Two examples of the input used to perform a search. There are several more text input fields and several more checkbox fields to further limit the search. When you say "user input", what exactly are you talking about? The text input fields? Something else?

     

    Could you provide me with some reading on the issue that you see? I would really like to read into this and deal with issues that I'm apparently overlooking where a simple search query is concerned.

  7. Page 1:

    <input type='hidden' name='query' value='$query'>
    

     

    New Page:

    $query = $_GET['query'];
    
    mysql_connect("blah","blah","blah");
    mysql_select_db("blah") or die("Unable to select database");
    
    $query = "$query";
    
    $numresults=mysql_query($query);
    
    $numrows=mysql_num_rows($numresults);
    

     

    Again, I just want the new page to run the same query the original did. I just need to pass the query from Page 1 to the New Page. Is that enough code?

     

     

  8. Hi all...

     

    I've searched up and down but don't think I'm searching for the right terms.

     

    I have a database that takes a query and returns results - just fine. Works like a charm.

     

    What I would like to do is take the same query that was just run and send it to another page that has the same results laid out a little differently.

     

    I've tried messing around with the whole $_GET thing but to no avail. I've also tried sending it as a hidden variable (input type='hidden' name='query' value='$query') but to no avail here either.

     

    Anybody willing to give me a hint as to how to pass the same query to another page?

     

    Thanks!

     

  9. I need to combine those tables into one table (T3) but with multiple rows containing the same information (except for one bit - product_ord), I thought I could combine the rows that have common information (by say the order number).

     

    T3:

    order_id |cust_name |cust_addr |cust_zip |product_ord

    21DavidHollywood Blvd902103, 6 (or even split these values into two cells)

     

    I hope that makes more sense. I'm relatively new to this stuff but am learning a lot, thanks to you guys!

  10. Hello. Here is what's happening:

     

    I need to run a query on a couple of tables.

     

    T1:

    order_id |cust_name |product_ord

    21David3

    21David6

     

    T2:

    cust_name |cust_addr |cust_zip

    DavidHollywood Blvd90210

    JaneMain St90210

     

    Now, the customer orders a couple of products, which go into the database as separate rows. If I try to pull info from both tables, I get two rows for David using something like

     

    select t1.*, t2.* from t1, t2 where t1.cust_name = t2.cust_name

     

    T3:

    order_id |cust_name |cust_addr |cust_zip |product_ord

    21DavidHollywood Blvd902103

    21DavidHollywood Blvd902106

     

    If I try a GROUP BY order_id, the resulting table shows only the last row containing only the order for product 6.

     

    The question is, am I even on the right track for combining all info from these two tables into one row?

     

    Also, how do you guys do those nicely laid out table examples? Mine look horrible, for which I'm sorry.

     

    Thanks, in advance!

  11. Hello...

     

    The following query:

    SELECT customers.*, orders.*, orders_products.* FROM customers, orders, orders_products WHERE (customers.customers_id = orders.customers_id) && (orders.orders_id = orders_products.orders_id);
    

    returns orders placed by customers which are entered into the database as separate rows for each product ordered. So If Customer 1 orders a dog, a cat and a bird, it returns three rows saying such (each with the same customer info, same order id but different product):

     

    customers_id | orders_id | orders_products

    1 | 1 | dog

    1 | 1 | cat

    1 | 1 | bird

     

    I would like to return this information in one row saying:

     

    customers_id | orders_id | orders_products

    1 | 1 | dog, cat, bird

     

    As it is, when I use GROUP BY either customers_id or orders_id, I get only the last row in the set (i.e. 1 | 1 | bird).

     

    I've tried various JOINS but am not sure how this is to be done.

     

    Anybody able to help out?

  12. Thanks Barand. I'll give it a shot right now. By the way, I think it was one of your posts that set me on the right track to getting the DAY one to work. Thanks!

    So the syntax would be like this?

    [code]
    if($_POST['type_array']) {
    $types = $_POST['type_array'];
    $query .="(";
    foreach($types as $chosen) {
    $query .= "$chosen IN (1,2,3,4,5)";
    }
    $query = rtrim($query," || ");
    $query .= ") && ";
    }
    [/code]

    I can see the chosen values being evaluated against the but I'm not sure how this works. It's still not limiting the results to just those records that have say '12' as $chosen.

    I'm just not sure how the IN syntax works and reading the MySQL manual on the matter is like reading Hesse to figure out how to fix my Volkswagen.
  13. [quote author=corbin link=topic=120465.msg494123#msg494123 date=1167550642]
    Does mysql use ||?  I dont remember, but I dont think it does.
    [/quote]

    Yeah... it does.

    [URL=http://www.phpfreaks.com/manuals/mysql/functions.html#logical-operators]http://www.phpfreaks.com/manuals/mysql/functions.html#logical-operators[/URL]

    Just felt like using those. I have no particular reason.
  14. I'm like 95% done with this pain in the butt but can't get past this thing.

    I have a search page that takes values from multiple form elements and pieces together a query. I've come up with a solution for a multiple checkbox search that queries the database column DAY and returns whatever days are selected in the checkboxes. It may not be pretty but looks like this:

    [code]
    FORM:
    input type "checkbox" name="day[]" value="Sunday"... etc.

    PHP PAGE:
    if($_POST['day'] != '') {
    $days = $_POST['day'];
    $query .= "(";
    foreach($days as $chosen) {
    $query .= "day = '$chosen' || ";
    }
    $query = rtrim($query," || ");
    $query .= ") && ";
    }
    [/code]

    The next part is the same idea but a little more tricky

    [code]
    FORM:
    <input type "checkbox" name="type_array[]" value="red">
    <input type "checkbox" name="type_array[]" value="green">
    <input type "checkbox" name="type_array[]" value="blue">
    [/code]

    The problem is that in the database, the column that is queried is full of numeric equivalents to the types in the array. So in that column you have "1,2,3" or "1,3" etc. (depending on what was input and it goes through like 22).

    I'm trying to use the same sort of query as with the DAY column but am certainly open to suggestion. Here's what I've been working with:

    [code]
    if($_POST['type_array']) {
    $types = $_POST['type_array'];
    $query .="(";
    foreach($types as $chosen) {
    $query .= "type LIKE '$chosen' || ";
    }
    $query = rtrim($query," || ");
    $query .= ") && ";
    }
    [/code]

    Again, some people may only need to call rows that include like 1 and 22 - others may need 4,5,6,13 for this part of the larger query. Usually, they will search for one at a time but may need more.

    Any thoughts, anyone?

    Thanks, in advance!
  15. Ok...

    so this is a shameless "bump" to see if anybody else might have an idea. I apologize if bumping is against the rules. I'm just at a total loss.

    Again, what is happening is that the record is edited with the result that the record with the old information is reloaded and followed by a display of the record with the new information. I just want the new information to replace the form above it altogether.
  16. Ok... I tried to clean up my code as best as possible. I hope it's legible.

    This is what I'm working with. Again, it provides the form with the info to be edited but then, instead of replacing it with the function added(), it adds the contents of the function to the end of the form.

    I've chopped lots of extraneous stuff out.

    [code]
    <?php
    // get ID for edit
    $id = $_GET['id'];

    // Connect to MySQL and Dbase
    mysql_connect("...", "...", "...") or die(mysql_error());
    mysql_select_db("...") or die(mysql_error());

    $query = "SELECT * FROM table WHERE id='$id'";
    $result=mysql_query($query);
    $num=mysql_numrows($result);
    mysql_close();

    // get information for edit
    $i=0;
    while ($i < $num) {
    $id=mysql_result($result,$i,"id");
    et cetera...

    echo "
    <p align='center'><a href='adminpanel.php'>Return to Admin Panel</a></p>
    <form action='' method= 'post'>
    <table width='90%' border='0' align='center' style='margin-bottom:15px;'>
    et cetera...
    <tr>
    <td colspan='8' align='right'><input type='submit' name='ud_update' value='Update'></td>
    </tr>
    </table>
    </form>";
    $i++ ;
    }

    $ud_id = $_POST['ud_id'];
    et cetera...

    function added(){
    $id = $_GET['id'];

    mysql_connect("...","...","...");
    mysql_select_db("...") or die("Unable to select database");

    $query = "SELECT * from table where id = $id";

    $numresults=mysql_query($query);
    $numrows=mysql_num_rows($numresults);
    $result = mysql_query($query) or die("Couldn't execute query");
    $a = $numrows;

    while ($row= mysql_fetch_array($result)) {
    $id = $row["id"];
    et cetera...

    echo "
    <table width='600px' align='center' style='border: 1px solid #ccc; background-color: #fff; padding: 3px 3px 3px 5px;'>
    <tr>
    <td colspan='3' valign='top'><b>Admin</b>: (<a href=\"edit.php?id=$id\">EDIT</a> - <a href=\"del.php?id=$id\">DELETE</a>)
    </tr>
    </table>
    <br>";
    }
    }

    if ($ud_update){
    global $id;
    mysql_connect("...", "...", "...") or die(mysql_error());
    mysql_select_db("...") or die(mysql_error());
    $query = "UPDATE table SET ... WHERE id='$id'";

    $result = mysql_query($query) or die("Error: ". mysql_error(). " with query ". $query);
    mysql_query($query);
    mysql_close();
    }

    if (isset($ud_update)){
    added();
    }
    ?>
    [/code]
  17. Hi Folks...

    I've grown tired of searching and have tried everything to resolve this. Maybe you can give me a pointer or two?

    I have a basic "edit" form that pulls a row from a database for editing. That works fine. I also have placed a function into that file (after the form) that returns the new information with an option to further edit. That works fine too.

    The problem is this: The returned table (from the function added()) with the new information is underneath the form into which I type the new information. I would like for it to replace that form.

    I've tried some "if" statements with and without "isset" but I just can't get this.

    Should I make two functions? One for "edit" (into which one puts new info) and one for "added" (which displays the new info with a choice to further edit)?

    Gosh this is so vague but I'm really embarrassed to post the code for this. It's such a mess. Do you get what I'm asking?
  18. Excellent.... Thanks to both of you (JP128 & Submerged)!

    JP128: I used your advice for two files. The first file with the form and the hidden values was perfect. In fact, I was thinking about hidden values but am not that proficient yet to know exactly what to do with them. The second file kept giving me a parse error.

    Submerged: I used your meta-refresh in the second file and it worked perfectly.

    There's our solution. The JP128/Submerged method.

    Thanks, again!
  19. [quote author=drifter link=topic=119011.msg486803#msg486803 date=1166388415]
    for this, you can either post back to the form, read the variables in and then use header("location: $newurl");

    or you can have the form use an onclick in javascript - then read the field and assemble the URL and then send you there.

    [/quote]

    Post back to the form? I'm not sure what you mean.

    I would definitely like to stay away from javascript. If a user doesn't have it turned on, that puts the screws to that...
  20. Hi all...

    I'm having a bit of a hard time with something that seems like it should be simple. Here goes:

    I would like to use a form to have a user input a zip code that would (upon clicking submit) be inserted into the middle of a URL that has constants on both sides and then they should be directed to that URL.

    I've got definitions for both sides of the URL set as "const1 and const2"...

    I've got my form, the action on which I've only gotten close with

    ACTION="$const1$userzip$const2" METHOD="post"

    The field in the form is named "userzip"...

    So the current result is to direct me to the new url minus the userzip.

    make sense?

    Here's the code:

    [code]
    // driving direction link
    $const1 = "http://maps.google.com/maps?saddr=";
    $const2 = "&daddr=27%20Main%20St%20+90210&hl=en";
    echo "<table align='center' style='background-color:#eeeeee;'>
    <tr>
                        <td align='center'>Need Directions?<br>Just put your zip code in the box below.</p></td>
    </tr>
    <tr>
    <td align='center'>
    <form name='form' action='$const1$userzip$const2' method='post'>
      <input type='text' size='11' name='userzip' value='Your Zip Code'>
      <input type='submit' name='submit' value='Get Directions'>
    </form></td>
    </tr>
    </table>";
    [/code]

    Thanks, in advance!
×
×
  • 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.