SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    Almeaty Member
    Join Date
    Jul 2000
    Location
    Nowhere
    Posts
    278
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here's the code:

    Code:
    $sql_result = mysql_query("SELECT * FROM developers,projects,pro_dev WHERE developers.id = pro_dev.did AND projects.id = pro_dev.pid"); 
    
    while($row = mysql_fetch_array($sql_result_dev)) 
    { 
      // define vars 
      $id = $row["id"]; 
      $title = $row["title"]; 
    
      echo( "<a href=\"projectdetail.php3?id=" . $id . "\">" . $title . "</a><br>\n"); 
    }
    This code is again inside a WHILE loop to fetch info for the individual developers. However the code above shows the same projects for every single developer again and again... meaning that every developer is involved in the same projects.

    When I added the table's name in front of the "row" declarations the vars suddenly are empty:

    Code:
    e.g. $id = $row["project.id"];
    Any ideas how I can solve it? I'm really confused and don't know what there should be wrong...

    Thanks alot!

  2. #2
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You might try
    $sql_result = mysql_query("SELECT developers.*, projects.*, pro_dev.* FROM developers,projects,pro_dev WHERE developers.id = pro_dev.did AND projects.id = pro_dev.pid");

    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  3. #3
    Almeaty Member
    Join Date
    Jul 2000
    Location
    Nowhere
    Posts
    278
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry, still doesn't work. It's the same result ;( I think I should post the entire code, maybe then it's easier to find the problem:

    Code:
    <?php
    
      // defining var of row
      while($row = mysql_fetch_array($sql_result))
      {
    								
      // define vars
      $name = $row["name"];
      $email = $row["email"];
      $url = $row["url"];
      $text = $row["text"];
      
      if ($url > 0)
      {
        echo( "<tr><td class=plaintext12 bgcolor=lightgrey colspan=2><b><a class=anchor12 href=\"mailto:" . $email . "\">" . $name . "</a></b></td></tr>\n"
    								        . "<tr><td class=plaintext12 bgcolor=#eeeeee colspan=2><a href=\"" . $url . "\" target=_blank>" . $url . "</td></tr>\n"
    								        . "<tr><td class=plaintext12 bgcolor=#dddddd>" . $text . "</td><td class=plaintext12 bgcolor=#dddddd align=left width=150>\n");
      }
      else
      {
        echo( "<tr><td class=plaintext12 bgcolor=lightgrey colspan=2><b><a class=anchor12 href=\"mailto:" . $email . "\">" . $name . "</a></b></td></tr>\n"
    								        . "<tr><td class=plaintext12 bgcolor=#dddddd>" . $text . "</td><td class=plaintext12 bgcolor=#dddddd align=left width=150>\n");
      }
    								
    								
      $sql_result_dev = mysql_query("SELECT developers.*, projects.*, pro_dev.* FROM developers,projects,pro_dev WHERE developers.id = pro_dev.did AND projects.id = pro_dev.pid");
    								
        while($row_dev = mysql_fetch_array($sql_result_dev))
        {
          // define vars
          $id = $row_dev["id"];
          $title = $row_dev["title"];
    									
          echo( "<a href=\"projectdetail.php3?id=" . $id . "\">" . $title . "</a><br>\n");
        }
    								
        echo( "</td></tr>" );
      }
    	
    ?>
    To see the test page click here

    HTH...

  4. #4
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The one other thing that comes to mind is are there some fields which have the same name in two tables, what I mean is there a field called name in two different tables, if so you need to specify the fields you was access to print in the select statement like:
    $sql_result = mysql_query("SELECT developers.id as did, developers.name as dname, projects.id as pid, pro_dev.id as prid FROM developers,projects,pro_dev WHERE developers.id = pro_dev.did AND projects.id = pro_dev.pid");

    Then you can access them by the new names assigned to them.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  5. #5
    SitePoint Wizard edshuck's Avatar
    Join Date
    Jul 2000
    Posts
    1,200
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi

    i would look closely at those double quotes around the $name part of the code. i seem to recall a question from a couple weeks ago where the " were causing the value to show blank.

    thanks ed

  6. #6
    SitePoint Wizard edshuck's Avatar
    Join Date
    Jul 2000
    Posts
    1,200
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi

    to finish the thought. the problem a couple weeks ago was the pair count was off on the quotes and the result showed blank.

    ed

  7. #7
    Almeaty Member
    Join Date
    Jul 2000
    Location
    Nowhere
    Posts
    278
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    But the vars are not blank...

    It's just that this code displays the exactly same projects for every developer again and again...

    What's up?

  8. #8
    Your Lord and Master, Foamy gold trophy Hierophant's Avatar
    Join Date
    Aug 1999
    Location
    Lancaster, Ca. USA
    Posts
    12,305
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Isn't there a fetch next command in PHP?

    SO the Pseudo code would be....

    Get Recordset
    row$ = Get FIrst Row
    While Not EOF
    Process Row
    Get Next Row
    Repeat loop.
    Wayne Luke
    ------------


  9. #9
    Almeaty Member
    Join Date
    Jul 2000
    Location
    Nowhere
    Posts
    278
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh boy, oh boy! It works!!!

    Maybe that's why I love programming. It simply gives a wonderful feeling if one has accomplished a task succesfully.

    Thanks to you all, for all your appreciated help!


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
  •