Thread: form values

    #1
  1. No Profile Picture
    The Dude Abides
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Feb 2000
    Location
    grass valley,ca
    Posts
    1,062
    Rep Power
    16
    Need a little help. I'm trying to print search results from a mysql database. In the results I need the following:
    print ("<INPUT TYPE="CHECKBOX" NAME="addit" VALUE="item description^price^1">")

    the info in the value area needs to be called from a mysql database. The ^ symbols need to be between each of the mysql results. I've tried a few different methods but none seem to display the results.

    Suggestions???

    Thanks in advance

    ------------------
    Chris Staniar
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2000
    Posts
    79
    Rep Power
    15
    Why would u want to put more than 1 results in as the default value for a checkbox anyway?


    Basil
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2000
    Location
    durham, nc, usa
    Posts
    14
    Rep Power
    0
    I am not sure I understand the poster's question. You are having trouble outputting your parse delimiters (^)? or you are having trouble getting proper html output in general?

    When I do something like this I am generally in a loop outputting html table rows for (for instance) a shopping cart. I have the results of my SQL query in separate variables (i.e., $sku, $qty, $description, etc.) and use printf with an appropriate format string.
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>printf ("<tr><td><input type=checkbox name="addit[]" value = "%s^%d^">%s</td></tr>n", $description, $price, $description);[/code]

    It's freehand, so it may be a little whacky. If so, I'll correct it as soon as I get home, but it should work out and output something like

    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre><tr><td><input type=checkbox name=addit[] value = "testitem^2.23^>testitem</td></tr>[/code]

    You may want to reexamine the value field, which looks as though you're trying to combine a key with a price. If this info is in your base already, why not just pass the sku number (or whatever)?

    Also, If you're dealing with multiple items, be sure to name the checkbox with name = "addit[]" or whatever so that it knows to send PHP an array of items. good luck.

    jim


    [This message has been edited by jodonnell (edited February 29, 2000).]

    [This message has been edited by jodonnell (edited February 29, 2000).]
  6. #4
  7. No Profile Picture
    The Dude Abides
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Feb 2000
    Location
    grass valley,ca
    Posts
    1,062
    Rep Power
    16
    Sorry, I should have been more specific. The value of the checkbox needs to be this way in order to pass data to a shopping cart. The ^ symbols break up the data so the shopping cart can utilize the data. The ^ symbols are not going to be printed from the database, only the product description and price.

    Where you see description^price these need to be separate values called from a mysql db. Below is a more detailed section of the code.

    Thanks


    mysql_select_db (chrisdb);

    if ($prodname == "")
    {$prodname = '%';}

    $result = mysql_query ("SELECT * FROM products
    WHERE prodname LIKE '$prodname%'
    ");

    if ($row = mysql_fetch_array($result)) {

    do {
    print ("<TR><TD>");
    print ("<INPUT TYPE="CHECKBOX" NAME="addit" VALUE="description^price^1"></TD>");
    print ("<TD>");
    print $row["prodname"];
    print ("</TD><TD>");
    print $row["description"];
    print ("</TD><TD>");
    print $row["price"];
    print ("</TD><TD><INPUT TYPE="submit" VALUE="Order"></TD></TR></TABLE>");
    } while($row = mysql_fetch_array($result));

    } else {print "Sorry, no records were found!";}
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 1999
    Location
    London
    Posts
    110
    Rep Power
    0
    the following code should do it, its only a couple of changes to your original...

    <?
    mysql_connect("whatever");
    $result = mysql_db_query ("databasename","SELECT * FROM products WHERE prodname LIKE '$prodname%'");
    if ($row = mysql_fetch_array($result))
    {
    do
    {
    print ("<TR><TD>");
    print ("<INPUT TYPE="CHECKBOX" NAME="addit" VALUE="".$row["0"]."^".$row["1"]."^".$row["2"].""></TD>");
    print ("<TD>");
    print $row["0"];
    print ("</TD><TD>");
    print $row["1"];
    print ("</TD><TD>");
    print $row["2"];
    print ("</TD><TD><INPUT TYPE="submit" VALUE="Order"></TD></TR></TABLE>");
    }
    while($row = mysql_fetch_array($result));
    } else {print "Sorry, no records were found!";}
    ?>

    hth

    timbo

    sorry should have said just replace the "0" "1" etc with whatever your column names are
    ------------------
    cheers


    [This message has been edited by timbo (edited March 01, 2000).]
  10. #6
  11. No Profile Picture
    The Dude Abides
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Feb 2000
    Location
    grass valley,ca
    Posts
    1,062
    Rep Power
    16
    Thanks, that worked great!

    ------------------
    Chris Staniar

Similar Threads

  1. HTTP Error 400: Bad Request, with basic form
    By crackwombat in forum PHP Development
    Replies: 1
    Last Post: January 23rd, 2004, 06:40 PM
  2. Adding form values based on variable selection
    By lamborn in forum HTML Programming
    Replies: 0
    Last Post: January 17th, 2004, 07:51 AM
  3. form after submit keep values as default
    By Germanjulian in forum HTML Programming
    Replies: 2
    Last Post: January 8th, 2004, 07:48 AM
  4. Zip code validation
    By krwyth in forum MySQL Help
    Replies: 2
    Last Post: January 5th, 2004, 01:29 PM
  5. manually supplying form values
    By rebbit in forum PHP Development
    Replies: 9
    Last Post: January 3rd, 2004, 06:37 PM

IMN logo majestic logo threadwatch logo seochat tools logo