Jump to content

ejaboneta

Members
  • Posts

    168
  • Joined

  • Last visited

Posts posted by ejaboneta

  1. Ok so I think I need something like a WHERE clause before joining.....

     

    This doesn't work

    SELECT q.id, q.question, r.answer, r.user
    FROM poll_questions q 
    WHERE r.user = 0
    LEFT JOIN poll_responses r ON q.id = r.poll
    

     

     

     

    and adding it to the end, just selects the rows from the combined table.

    SELECT q.id, q.question, r.answer, r.user
    FROM poll_questions q
    LEFT JOIN poll_responses r ON q.id = r.poll
    WHERE r.user = 0

  2. I should mention I'm somewhat of a beginner. I understand the sql and I modified it to fit my database but it looks like the r.user=0 takes out all the Null values which is the opposite of what I want... And besides that, questions may be answered by other users so the r.user column isnt always going to be null.

     

    But thanks for the help. I'm gonna play around with it to see if I can come up with something.

     

    SELECT q.id, q.question, r.answer, r.user FROM poll_questions q LEFT JOIN poll_responses r ON q.id=r.poll WHERE r.user=0 AND r.id is NULL ORDER BY q.priority

  3. Oh yea, version 4.1.....

     

     

    and heres an example.

     

    under the questions table:

    id        question                  priority

    1      Favorite Color?                3

    2      Favorite Fruit?                  2

    3        Country?                      3

    4        Gender?                      4

     

    Under Answers:

    id      question id      answer      user

    0              1                blue        22

    1              1                red          4

    2              3                US          22

     

     

    I want the php code and/or query to find questions that user 22 hasn't answered and return one with the highest priority rating. It can find it the other way around, i dont care. So it would find questions 2 and 4 because there is no answers with those id numbers and user 22 and then select question 2 because it's priority is higher.

     

    Maybe I'm just tired, but i dont know how where to start. I have some other columns and tables involved in this problem but this is the basic function i'm working on. I plan on having alot of questions and even more answers, so i'm hoping for a solution that will be fast..

  4. so i have 2 tables, one with questions, and one with responses. I don't want users to be asked the same questions twice.

     

    In the response table, there is an answer id, user id, question id and the answer.

     

    In the question table, theres question id, and the question.

     

    I want to pick a question that the user hasn't answered yet. Any ideas?

     

  5. I want a link to open in a new window when clicked. Sorry, i didn't mean popups.

     

    Well honestly.... I don't know javascript... so thats why I haven't been using it. But I was thinking some simple html. I haven't tried to open anything in a new window in a really long time, so I tried <a target="_blank"> and it works in IE but not Firefox.

     

    I'll try using javascript.

  6. Try this. I forgot the <tr></tr> tags for the questions...

     

    <?php
    
    ### GET PAGE ###
      if(isset($_GET['page'])) {
        $page = $_GET['page'];
      } else {
        $page = 1;
      }
      $tolimit = 4;
      $showend = $page * $tolimit;
      $showstart =  $showend - 4;
    
    ### GET TOPICS ###
      $getthreads="SELECT * FROM forumtutorial_posts WHERE parentid ='0' ORDER BY parentid DESC LIMIT $showstart, $tolimit";
      $findamount = mysql_query($getthreads) or die (mysql_error());//for showing the four newest posts
    
    ### DETERMINE PAGES ###
    function pager() {
      $query= "SELECT COUNT(*) as cnt  FROM forumtutorial_posts";//efficant way of counting rows
      $query2 = mysql_query($query) or die (mysql_error());//because we dont want to call it yet we set it to another variable
      $row = mysql_fetch_array($query2);
      $num_rows=$row['cnt'];
      $pagestoshow = floor($num_rows/$tolimit);
      for ($i = 1; $i <= $pagestoshow; $i++){
        print "<a href='index.php?page=$i'> $i </a>";
      }
    }  
    
    ### GRAB CONTENT ###
      function grabContent($r) {
        $answer=$r["answered"];
        $title=$r["title"];
        $id=$r["postid"];
        if ($answer == 0){
          $answer = "no";
        } else {
          $answer = "yes";
        }
        print '<tr>';
        print '<td bgcolor="#FFFFFF"><div align="left" class="style17"><a href="showquestion.php?page=' . $id . '">' . $title . '</a></div></td>';
        print '<td bgcolor="#FFFFFF"><div align="center" class="style17">' . $answer . '</div></td>';
        print '</tr>';
      }
    ?>
    
    <table width="467" border="0" align="center" cellpadding="5" cellspacing="5">
      <tr>
        <td width="366" bgcolor="#E6E6E6"><div align="left"><strong>Question:</strong></div></td>
        <td width="85" bgcolor="#E6E6E6"><div align="center"><strong>Answered?</strong></div></td>
      </tr>
    
        <?php
          while($r=mysql_fetch_array($findamount)) { 
            grabContent($r);
          }
        ?>
    
      <tr>
        <td>Page: </td>
        <td><?php pager(); ?> </td>
      </tr>
    
      <tr>
        <td bgcolor="#FFFFFF" colspan="2">
        <?php
          if ($session->logged_in){ 
            print 'Have a question you would like answered?, <a href="questionform.php">Click Here</a>';
          } else {
            print 'You must be logged in to ask a question, to log in <a href="login.php">Click Here</a>';
          } 
        ?>
        </td>
      </tr>
    </table>
    

  7. Your code was pretty confusing so I tried to re-organize it. I hope it works, I would have tested it but I can't use your database and I dont feel like setting up a test. I used a couple functions so that the php doesn't have to be all mixed up in the html.

     

    <?php
    
    ### GET PAGE ###
      if(isset($_GET['page'])) {
        $page = $_GET['page'];
      } else {
        $page = 1;
      }
      $tolimit = 4;
      $showend = $page * $tolimit;
      $showstart =  $showend - 4;
    
    ### GET TOPICS ###
      $getthreads="SELECT * FROM forumtutorial_posts WHERE parentid ='0' ORDER BY parentid DESC LIMIT $showstart, $tolimit";
      $findamount = mysql_query($getthreads) or die (mysql_error());//for showing the four newest posts
    
    ### DETERMINE PAGES ###
    function pager() {
      $query= "SELECT COUNT(*) as cnt  FROM forumtutorial_posts";//efficant way of counting rows
      $query2 = mysql_query($query) or die (mysql_error());//because we dont want to call it yet we set it to another variable
      $row = mysql_fetch_array($query2);
      $num_rows=$row['cnt'];
      $pagestoshow = floor($num_rows/$tolimit);
      for ($i = 1; $i <= $pagestoshow; $i++){
        print "<a href='index.php?page=$i'> $i </a>";
      }
    }  
    
    ### GRAB CONTENT ###
      function grabContent($r) {
        $answer=$r["answered"];
        $title=$r["title"];
        $id=$r["postid"];
        if ($answer == 0){
          $answer = "no";
        } else {
          $answer = "yes";
        }
        print '<td bgcolor="#FFFFFF"><div align="left" class="style17"><a href="showquestion.php?page=' . $id . '">' . $title . '</a></div></td>';
        print '<td bgcolor="#FFFFFF"><div align="center" class="style17">' . $answer . '</div></td>';
      }
    ?>
    
    <table width="467" border="0" align="center" cellpadding="5" cellspacing="5">
      <tr>
        <td width="366" bgcolor="#E6E6E6"><div align="left"><strong>Question:</strong></div></td>
        <td width="85" bgcolor="#E6E6E6"><div align="center"><strong>Answered?</strong></div></td>
      </tr>
    
      <tr>
        <?php
          while($r=mysql_fetch_array($findamount)) { 
            grabContent($r);
          }
        ?>
      </tr>
    
      <tr>
        <td>Page: </td>
        <td><?php pager(); ?> </td>
      </tr>
    
      <tr>
        <td bgcolor="#FFFFFF" colspan="2">
        <?php
          if ($session->logged_in){ 
            print 'Have a question you would like answered?, <a href="questionform.php">Click Here</a>';
          } else {
            print 'You must be logged in to ask a question, to log in <a href="login.php">Click Here</a>';
          } 
        ?>
        </td>
      </tr>
    </table>
    

  8. Everything was working fine and then suddenly the varibles in the URL were not being passed. I tried creating a test page to test it and it didnt work there either. I emailed my host and they said it was working fine and after that it did. I thought it might be my browser settings and whatnot but then I had other people tell me they experienced the same thing when it was happening to me.

     

    Is there a reason this could have happened? The host said there was no server side reason for it. I just don't want it to happen again.

     

     

    If I wasn't clear, the script would say <?php echo $a; ?>

    The url would be http://site.com?a=hello

    and there would be no output.

  9. I've been using php to include my css files. I decided to instead link them but when i do, the results aren't the same. Some things aren't working. For example, when i link it, if a tables width or height is set to 100%, it won't work. I even tried putting the height in the actual table but its not working there either. Some of the background colors aren't working as well. Is there a way to fix this or am I going to have to just include it like I have been?

  10. <?php
      $to = 'email@address.com';
      $subject = 'Form Subject';
      $message = 'Contact Name: ' . $_POST['name'];
      $message .= 'Company Name: ' . $_POST['company'] . "\n";
      $message .= 'Email: ' . $_POST['email'] . "\n";
      $message .= 'Product: ' . $_POST['description'] . "\n";
      $message .= 'Comments: ' . $_POST['body'] . "\n";
      $headers = "From: $email"; 
      mail ($to,$subject, $message, $headers);
    ?>
    

     

     

    Thats what I meant.. the \ was taken out of my code. when I use that, I get an email with

     

    "Contact Name: example company\nEmail: name@email.com\nProduct: product1\nComments: here is the comments

     

    what I want is

     

    "Contact Name: example company

    Email: name@email.com

    Product: product1

    Comments: here is the comments

     

  11. I'm trying to email a form with multiple lines of information. I want the information included in the body of the message each on its own line. I know its probably really simple but I can't fingure it out. I read somewhere to use \n or \r for new lines but thats not working.

     

    <?php
      $to = 'email@address.com;
      $subject = 'Form Subject';
      $message = 'Contact Name: ' . $_POST[name];
      $message = $message . 'Company Name: ' . $_POST[company] . '\\r\\n';
      $message = $message . 'Email: ' . $_POST[email] . '\\r\\n';
      $message = $message . 'Product: ' . $_POST[description] . '\\r\\n';
      $message = $message . 'Comments: ' . $_POST[body] . '\\r\\n';
      $headers = "From: $email"; 
      mail ($to,$subject, $message, $headers);
    ?>
    

  12. Alright I've validated it. I've done it in HTML 4.01 Transitional.... I don't really understand doctypes... Is there any benefit from choosing another?

     

    I'll look into using divs instead of tables... I've always used a combination of divs and tables but those fancy cartoons are telling I shouldn't....

     

    Thanks but I'm sure I can do the graphic design myself.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.