PHP query problem

Discussion in 'PHP' started by izlik, Dec 26, 2008.

  1. #1
    Hello

    I have this problem i hope someone can help me to solve. in my database i have a row called "Private" in the table "images" where 0 is not private and 1 is private. if private is set to 1 the image uploaded is hidden on the site, if it's 0 anyone can se it on the site.

    in my code for the page to view images at the top im doing this query

    $db->setQuery("select i.id,i.views,i.name,i.size,i.width,i.height,s.domain,u.gid,i.server_id,i.private
                   from images as i
                   left join users as u on u.id=i.uid
                   left join server as s on s.server_id=i.server_id
                   where i.id='$id'");
    PHP:
    After this im doing this

    $safe = "private";
    $template->assign_var('private',$row[$safe]);
    
    if ( private == 1 ) {
    	echo "This";
    } else {
    	echo "That";
    }
    PHP:
    now the problem. When i upload the file with this code, is shows "This" even if private is set to 0. why is this ?
     
    izlik, Dec 26, 2008 IP
  2. Danltn

    Danltn Well-Known Member

    Messages:
    679
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    120
    #2
    Unless it's does define, private evals to (int) 1. Turn error_reporting(E_ALL); to understand more.

    if ( $private == 1 ) {

    Maybe?

    (Assuming assign_var does something along the lines of ${$var} = $value;)
     
    Danltn, Dec 26, 2008 IP
  3. izlik

    izlik Well-Known Member

    Messages:
    2,399
    Likes Received:
    50
    Best Answers:
    0
    Trophy Points:
    185
    #3
    when i now checked the output it dosent show any value for assign_var :/ so i need to ask. by the db query above, do you know if there is another way to check if private is 1 or 0 and then do the if/else?
     
    izlik, Dec 26, 2008 IP
  4. Danltn

    Danltn Well-Known Member

    Messages:
    679
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    120
    #4
    Not unless you post the class code...
     
    Danltn, Dec 26, 2008 IP