show image in query if...

Discussion in 'PHP' started by mezner, Jun 22, 2010.

  1. #1
    I've been working on another database that I can't figure out how to set up and execute properly. The database will consist of...

    id primary auto_incr
    item varchar(255)
    price varchar(255)
    bulk null

    Now I'm not sure what to do about the 'bulk'. Let me explain how I want it to work. If the admin clicks the radio box for 'bulk', in the query it will leave a checkmark. That checkmark will be an image from inside my server (or even from any url for that matter). If the user DOESN'T click bulk, then nothing will appear.

    I was wondering how I should setup the database, as well as what I should do for the query. The query will simply get and display the item name, price and a checkmark if the bulk option is selected all within a table.

    Im thinking something like I normally do. Put the values into variables and then call them with the query, but I never done a query with an if then statement (which is what I'm thinking I have to do. If checkbox/radio is selected, then paste image. I'm also assuming I can place the image location inside of a variable, but again, never done that so I'm not sure how/if it will work).

    edit: hate asking so many php questions, but you guys and gals are really helpful.
     
    Last edited: Jun 22, 2010
    mezner, Jun 22, 2010 IP
  2. sarahk

    sarahk iTamer Staff

    Messages:
    28,901
    Likes Received:
    4,555
    Best Answers:
    123
    Trophy Points:
    665
    #2
    Not sure I follow you but... bulk can be

    char(1) and be either y/n depending on the check
    tinyint(3) and be either 0/1
    binary and hold the contents of the image file (if the image is specific to the user)
     
    sarahk, Jun 23, 2010 IP
  3. mezner

    mezner Peon

    Messages:
    289
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Yeah I understand that, but how do I bring up the image, if bulk is 1 (as in the boolean for true). Do I store it in a variable before running the query? kinda like...

    if bulk = 1
    then print (image here)
    else
    do nothing.
     
    mezner, Jun 23, 2010 IP
  4. techbongo

    techbongo Active Member

    Messages:
    309
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    80
    #4
    Thanks. I also had confusion on the same.
     
    techbongo, Jun 23, 2010 IP
  5. sarahk

    sarahk iTamer Staff

    Messages:
    28,901
    Likes Received:
    4,555
    Best Answers:
    123
    Trophy Points:
    665
    #5
    I'd do

    if bulk=1 then echo "<img src='/showimage.php?id=$id'>"

    and showimage.php gets the image code, outputs the appropriate headers and shows the image.
     
    sarahk, Jun 23, 2010 IP