Need help writting a mysql query

Discussion in 'MySQL' started by phelixx, Jun 30, 2011.

  1. #1
    Table is profile_values

    STRUCTURE

    FID UID VALUE

    FID value of 3 contains some HTML data that I need
    FID value of 2 contains the url to their image
    FID value of 1 contains either a 1 or a 0 if its a 1 then I want the HTML value and the image value but if its a 0 I dont want anything from it

    How can I create a query to display all values and uid's only where that uid's fid1 value is equal to 1
     
    phelixx, Jun 30, 2011 IP
  2. sirgogo

    sirgogo Peon

    Messages:
    19
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    
    //this gets all values and uids. $query only holds resources id#'s
    //so you need a mysql_result or other function to extract the actual data.
    $query = mysql_query("select UID, VALUE from profile_values where FID=1");
    
    //this is to get ONE value fom the table, not sure how to get more?
    $result = mysql_result($query, #); 
    
    Code (markup):
    you may need a for loop of sorts. not sure if this helped :/
     
    sirgogo, Jun 30, 2011 IP
  3. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #3
    You shouldn't store data like this. It is irrational and undermines the point of using a relational database.

    You should do something more like:

    UID, FID, HTML_DATA, PATH_TO_IMAGE

    Theis way, you only need a single query to access everything you need. Not sure about the UID, FID relationship, but something like this.
     
    jestep, Jul 1, 2011 IP