Results 1 to 2 of 2

Thread: Php & Mysql - Picture display

  1. #1
    Join Date
    Jan 2007
    Posts
    94
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Cool Php & Mysql - Picture display

    Hey all,
    I have two tables. One holds comments and the other holds the question/picture info.

    What I want to do is if a logged in user has already commented on a picture, for that picture to not display (there is a drop down that allows them to sort by male/female). And if all the questions in the database are answered for the user to see smthg that says like "no more records". I know this should be so easy for me but i'm having the hardest time with this and i dont know why!

    I know none of this is secure either that's my next step once i get the basic functionality going. (i have to do some research and reading on how to prevent injunctions) here's what I have... it still displays all the questions that have already been answered AND not answered by the user.

    PHP Code:

    <?php 

    $getqry88 
    "select distinct(questid) from comments where commid = $id";
        
    $getres88 mysql_query($getqry88)or die(mysql_error());
        
    $getrows88=mysql_num_rows($getres88);
        if(
    $getrows88 0){
        while(
    $getarray88=mysql_fetch_array($getres88)){

        
    $hqid12 $getarray88['questid'];

    }}    

    //if male only
    if ($_REQUEST['sort'] == 'male')
    {

    $getqry "select * from questions where approved = 'yes' and status = 'active' and quest_gender = 'male'  and getquest_counter != $hqid12 order by rand()";

    }

    //if  female only
    if ($_REQUEST['sort'] == 'female')
    {

    $getqry "select * from questions where approved = 'yes' and status = 'active' and quest_gender = 'female'  and getquest_counter != $hqid12 order by rand()";
    }


    $getres mysql_query($getqry)or die(mysql_error());
    $getrows=mysql_num_rows($getres);
    if(
    $getrows 0){
    while(
    $getarray=mysql_fetch_array($getres)){
            
        
    $pic $getarray['pic1'];
        
    $qid2 $getarray['getquest_counter'];
        
    $question $getarray['question'];
            }
    }    

    else 

    echo 
    "no records";
    ?>
    I've tried moving the brackets around to include the second query, but that doesn't work either.

    any help would be greatly appreciated!

  2. #2
    Join Date
    Jan 2007
    Posts
    94
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    ok, so i figured out a way to make it work.... however, now i keep getting an error message when the person has commented on all questions. It shows my custom message and then this at the bottom of the page:
    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

    I researched this online and it says something about magic quotes and addslashes. I don't think I need that because I'm just really focusing on querying an integer right? am i wrong about this?? here's my code now....

    Code:
    <?php 
    //if male only
    if ($_REQUEST['sort'] == 'male')
    {
    
    $getqry = "select * from questions where approved = 'yes' and status = 'active' and quest_gender = 'male'  and getquest_counter not in(select questid from comments where commid = $id)  order by rand()";
    } 
    
    //if female only
    if ($_REQUEST['sort'] == 'female')
    {
    
    $getqry = "select * from questions where approved = 'yes' and status = 'active' and quest_gender = 'female'  and getquest_counter not in(select questid from comments where commid = $id)  order by rand()";
    
    
    } 
    
    $getres = mysql_query($getqry)or die(mysql_error());
    $getrows=mysql_num_rows($getres);
    if($getrows > 0){
    while($getarray=mysql_fetch_array($getres)){
            
        $pic = $getarray['pic1'];
        $qid2 = $getarray['getquest_counter'];
        $question = $getarray['question'];
            }
    }    
    
    else if($getrows == 0){
    
    echo "No new questions to answer.";
    
    }
    ?>

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •