Trouble with join query's, query just dosent produce results

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Stu

    #1

    Trouble with join query's, query just dosent produce results

    I have the following code which I am having difficulty getting to
    work. I think it may be a problem with the $got query that is being
    run as if I set that to a set value then my site seems to run ok, but
    I also have checked the data whichi is being held in $detailsrow[1] by
    echoing them and it is perfect. I have also sutstituted the values and
    ran the query in mysqql directly and it gives me the exat results I am
    expecting!

    Ive been on it for hours now and I cant get it to work so any help
    will be fantastic,

    Make me a happy man with my first post!

    Thanks
    Stu



    <select name="type">
    <?PHP
    $mod = ("select name from modules");
    $modnames = @mysql_query($m od);
    $getfulltype = ("select modules.name from modules, devices where
    modules.code= $detailsrow[1] and devices.type = $detailsrow[1]");
    $got = mysql_query($ge tfulltype);
    while($row = mysql_fetch_row ($modnames))
    {
    if ($got == $row[0])

    {

    echo ("<option selected value=\"$got\"> $got</option> ");
    }

    else {
    echo ("<option value=\"$row[0]\">$row[0]</option>");
    }
    }
    ?>
    </select>
  • Geoff Berrow

    #2
    Re: Trouble with join query's, query just dosent produce results

    I noticed that Message-ID:
    <4784b647.05020 11541.1357c215@ posting.google. com> from Stu contained the
    following:
    [color=blue]
    >$got = mysql_query($ge tfulltype);
    > while($row = mysql_fetch_row ($modnames))
    > {
    > if ($got == $row[0])[/color]


    $got is a resource. How can you compare it to $row[0] ?
    --
    Geoff Berrow (put thecat out to email)
    It's only Usenet, no one dies.
    My opinions, not the committee's, mine.
    Simple RFDs http://www.ckdog.co.uk/rfdmaker/

    Comment

    • stu.trout@gmail.com

      #3
      Re: Trouble with join query's, query just dosent produce results

      Geoff, firstly thanks very much for the fast response but can you
      expand on your comment, I have only been doing PHP a week so not
      completley sure what you mean

      Thanks
      Stu

      Comment

      • News Me

        #4
        Re: Trouble with join query's, query just dosent produce results

        stu.trout@gmail .com wrote:[color=blue]
        > Geoff, firstly thanks very much for the fast response but can you
        > expand on your comment, I have only been doing PHP a week so not
        > completley sure what you mean
        >
        > Thanks
        > Stu
        >[/color]

        I think what Geoff is trying to say is you need to spend some time here:


        Comment

        • Geoff Berrow

          #5
          Re: Trouble with join query's, query just dosent produce results

          I noticed that Message-ID:
          <4784b647.05020 11541.1357c215@ posting.google. com> from Stu contained the
          following:
          Lets see if I can follow what you are trying to do

          define query to get all names[color=blue]
          >$mod = ("select name from modules");[/color]
          run query suppressing errors[color=blue]
          > $modnames = @mysql_query($m od);[/color]
          Define query to get names which match certain criteria[color=blue]
          > $getfulltype = ("select modules.name from modules, devices where
          >modules.code = $detailsrow[1] and devices.type = $detailsrow[1]");[/color]
          Run second query[color=blue]
          > $got = mysql_query($ge tfulltype);[/color]
          Loop through first query[color=blue]
          > while($row = mysql_fetch_row ($modnames))
          > {[/color]
          Compare name to resource identifier (will always be false)[color=blue]
          > if ($got == $row[0])
          >
          > {
          >
          > echo ("<option selected value=\"$got\"> $got</option> ");
          > }[/color]
          Echo all names[color=blue]
          > else {
          > echo ("<option value=\"$row[0]\">$row[0]</option>");
          > }
          > }
          >?>
          > </select>[/color]

          --
          Geoff Berrow (put thecat out to email)
          It's only Usenet, no one dies.
          My opinions, not the committee's, mine.
          Simple RFDs http://www.ckdog.co.uk/rfdmaker/

          Comment

          • stu.trout@gmail.com

            #6
            Re: Trouble with join query's, query just dosent produce results

            ok I'm looking into it now, another quick question, which is making me
            think that the query isnt running is that when I try and echo $got I
            never actually see the value I'm expecting, this is why I thought there
            was an error with the query but like I said it runs in cmd mysql fine!
            Stu

            Comment

            • stu.trout@gmail.com

              #7
              Re: Trouble with join query's, query just dosent produce results

              dont worry about the above now, I've just realised that while I was
              fidling to get it to work I had omitted the quotations around the
              variables! but it still gives me a resource error when I try and print
              even when i limit the result to 1

              Comment

              • stu.trout@gmail.com

                #8
                Re: Trouble with join query's, query just dosent produce results

                Ok I am looking into this now and I will see what I find out. When I
                try to echo the got query i also get a resourse ID error but this
                should only be returning 1 row with 1 column within it. as I am
                limiting the query to 1 result. Am I right in thinking that as the
                while loop the $row[0] value will change each time it runs s therefore
                my values will be "appliance module", "lamp module" and "infrared
                device" therfore each time it runs it will be the next row that it
                finds.

                Cheers
                Stu

                Comment

                • Geoff Berrow

                  #9
                  Re: Trouble with join query's, query just dosent produce results

                  I noticed that Message-ID:
                  <1107342071.475 958.38040@f14g2 000cwb.googlegr oups.com> from
                  stu.trout@gmail .com contained the following:
                  [color=blue]
                  >Ok I am looking into this now and I will see what I find out. When I
                  >try to echo the got query i also get a resourse ID error but this
                  >should only be returning 1 row with 1 column within it. as I am
                  >limiting the query to 1 result.[/color]

                  why aren't you doing:

                  <select name="type">
                  <?PHP
                  $getfulltype = ("select modules.name from modules, devices where
                  modules.code= $detailsrow[1] and devices.type = $detailsrow[1]");
                  $got = mysql_query($ge tfulltype);
                  while($row = mysql_fetch_row ($got)){
                  echo ("<option selected
                  value=\"".$row[0]."\">".$row[0]."</option> ");
                  }
                  ?>
                  </select>

                  --
                  Geoff Berrow (put thecat out to email)
                  It's only Usenet, no one dies.
                  My opinions, not the committee's, mine.
                  Simple RFDs http://www.ckdog.co.uk/rfdmaker/

                  Comment

                  • iMedia

                    #10
                    Re: Trouble with join query's, query just dosent produce results

                    > $got = mysql_query($ge tfulltype);
                    simply defines the query with a resource id. Now you need to do
                    something with that query "Resource ID" to get the data.

                    Try
                    $gotcha = mysql_result($g ot, n);
                    where n = is the column number of the row returned and will get you the
                    data of that cell.

                    If you need more from that row, then you need to dump that row query
                    into something like:

                    $gotcha = mysql_fetch_row ($got);
                    and then $gotcha will contain an array with each element containing one
                    field from the row.

                    If you need more that that then you will need to look into "foreach()"




                    Comment

                    • stu.trout@gmail.com

                      #11
                      Re: Trouble with join query's, query just dosent produce results

                      Thanks for all your help, I ebentually have figured something out,
                      geoff I used your suggestion but the problem was that I wanted all the
                      options to appear in the drop down box as it was an 'edit' screen so
                      they needed to be able to change the value to anything they wanted, I
                      have just finished doing it and at the moment it seems to be performing
                      perfectly which is nice

                      <td><select name="type">


                      <?PHP
                      $mod = ("select name from modules");
                      $allmodnames = mysql_query($mo d);
                      $getfulltype = ("select modules.name from modules, devices where
                      modules.code= '$detailsrow[1]' and devices.type = '$detailsrow[1]'
                      limit 1 ");
                      $got = mysql_query($ge tfulltype);
                      $row = mysql_fetch_row ($got);

                      $number = mysql_query("se lect name from modules");
                      $amount = mysql_num_rows( $number);


                      for ($am =1 ; $am < $amount+1 ; $am++ )
                      {
                      if ($row == ($modnames = mysql_fetch_row ($allmodnames)) )
                      {
                      echo ("<option selected
                      value=\"".$row[0]."\">".$row[0]."</option> ");
                      }
                      else
                      {
                      echo ("<option
                      value=\"".$modn ames[0]."\">".$modname s[0]."</option> ");
                      }
                      }
                      ?>
                      </select>

                      Comment

                      Working...