Php "WHERE clause

Collapse
X
Collapse
+ More Options
Posts
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • Antonio878
    Master Sergeant

    • Sep 2007
    • 68

    Php "WHERE clause

    Ok I am having a problem with the WHERE clause part. I have the whole thing correct but...with the WHERE part it only pulls out 1 data out of the database when there is 4 more to be taken out. See I have the names in another database and the information in the other. Here is the one I want to work but only 1 data comes out. (userid = '1' is not in the other database I just put it there so the OR will work.
    PHP Code:
    <?php
    $conn 
    mysql_connect("localhost","user","pass");
    if (!
    $conn)
      {
      die(
    'Could not connect: ' mysql_error());
      }
    mysql_select_db("user_assignment"$conn);
    $qt=mysql_query("select * FROM $race");
    echo 
    mysql_error();
    while(
    $nt=mysql_fetch_array($qt)){
    $f "(userid = '$nt[name]') OR ";
     
    $con mysql_connect("localhost","user","pass");
    if (!
    $con)
      {
      die(
    'Could not connect: ' mysql_error());
      }
    mysql_select_db("user_assignment"$con); 
    $qt=mysql_query("select * from sign where $f (userid = '1') LIMIT 6");
    echo 
    mysql_error();
    while(
    $nt=mysql_fetch_array($qt)){
    echo 
    "<a href='/pro.php?user=$nt[user]'><img src=$nt[filena]' width='100' height='87' border='0'/></a>  ";
    }
    }
    ?>
    Now this code at the bottom works all information shows up with the bottom but I don't want to use that code, I want to use the top code, since the top one takes the names out of the $race (table really not called $race but called what ever the url says the $race value to be)table and use it to search the names in the other table (the other table has 789 names) and then post the information but the bottom one I have to put the names in the code myself and I don't want to do that, since people add more names everyday and more information in different tables.

    Someone please help this has been a struggle for me for a long time someone help, thank you.

    PHP Code:
    <?php
    $con 
    mysql_connect("localhost","user","pass");
    if (!
    $con)
      {
      die(
    'Could not connect: ' mysql_error());
      }
    mysql_select_db("user_assignment"$con); 
    $qt=mysql_query("select * from sign where (userid = 'may') OR (userid = 'ron') OR (userid = 'john') OR (userid = 'homer') OR (userid = '1') LIMIT 6");
    echo 
    mysql_error();
    while(
    $nt=mysql_fetch_array($qt)){
    echo 
    "<a href='/pro.php?user=$nt[user]'><img src=$nt[filena]' width='100' height='87' border='0'/></a>  ";
    }
    ?>
    Check out:
    Great Windmill (A Place Where You Can Have Fun!)

    You can do so much on the website, check it out!
  • navaldesign
    General & Forum Moderator

    • Oct 2005
    • 12080

    #2
    Re: Php &quot;WHERE clause

    $qt=mysql_query("select * from sign where (userid = '1') LIMIT 6");

    Replace this line and test.


    Navaldesign
    Logger Lite: Low Cost, Customizable, multifeatured Login script
    Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
    DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
    Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

    Comment

    • Antonio878
      Master Sergeant

      • Sep 2007
      • 68

      #3
      Re: Php &quot;WHERE clause

      Originally posted by navaldesign View Post
      $qt=mysql_query("select * from sign where (userid = '1') LIMIT 6");

      Replace this line and test.

      yes that does work but then it only shows 1 information when I want all of the information from each person. I don't know why but when I use the variable in the WHERE clause it doesn't work it only shows 2 informations from two people when I want all of them. The only time when it shows all of the information from all of the people in the database, is if I manually put there name in the WHERE clause and I don't want to do that.
      Check out:
      Great Windmill (A Place Where You Can Have Fun!)

      You can do so much on the website, check it out!

      Comment

      • navaldesign
        General & Forum Moderator

        • Oct 2005
        • 12080

        #4
        Re: Php &quot;WHERE clause

        You are confusing things maybe ? If in the clause you have userid = 1 , it is natural that it will display ONLY the user that has userid 1.
        If you want the script to display ALL records, then you should NOT use any WHERE clause. Your line should be:

        $qt=mysql_query("select * from sign ");
        Navaldesign
        Logger Lite: Low Cost, Customizable, multifeatured Login script
        Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
        DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
        Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

        Comment

        • Antonio878
          Master Sergeant

          • Sep 2007
          • 68

          #5
          Re: Php &quot;WHERE clause

          Originally posted by navaldesign View Post
          You are confusing things maybe ? If in the clause you have userid = 1 , it is natural that it will display ONLY the user that has userid 1.
          If you want the script to display ALL records, then you should NOT use any WHERE clause. Your line should be:

          $qt=mysql_query("select * from sign ");
          ok ill explain you see the code at the beginning
          PHP Code:
          $conn mysql_connect("localhost","user","pass");
          if (!
          $conn)
            {
            die(
          'Could not connect: ' mysql_error());
            }
          mysql_select_db("user_assignment"$conn);
          $qt=mysql_query("select * FROM $race");
          echo 
          mysql_error();
          while(
          $nt=mysql_fetch_array($qt)){
          $f "(userid = '$nt[name]') OR "
          See the $race can be changed into different names depends on who's information your previewing then I used the
          PHP Code:
          while($nt=mysql_fetch_array($qt)){ 
          to collect who the person's friends are and put the names in the $f variable. Then I use the $f variable's value and post it in the WHERE clause so it will collect the information from the "sign" database and post the information of each friend the person has.

          PHP Code:
          $con mysql_connect("localhost","user","pass");
          if (!
          $con)
            {
            die(
          'Could not connect: ' mysql_error());
            }
          mysql_select_db("user_assignment"$con); 
          $qt=mysql_query("select * from sign where $f (userid = '1') LIMIT 6");
          echo 
          mysql_error();
          while(
          $nt=mysql_fetch_array($qt)){
          echo 
          "<a href='/pro.php?user=$nt[user]'><img src=$nt[filena]' width='100' height='87' border='0'/></a>  ";
          }
          }
          ?> 
          See thats what I was trying to do and you can see the $f variable in the WHERE clause infront of the (userid = '1')

          So I hope now you understand what I am trying to do.
          Check out:
          Great Windmill (A Place Where You Can Have Fun!)

          You can do so much on the website, check it out!

          Comment

          • navaldesign
            General & Forum Moderator

            • Oct 2005
            • 12080

            #6
            Re: Php &quot;WHERE clause

            while($nt=mysql_fetch_array($qt)){
            $f = "(userid = '$nt[name]') OR ";

            will only retrieve ONE value for $nt[name] (the last occurance, or the 6th one if more than 6 exist).

            It should have been (note the ".=" )

            while($nt=mysql_fetch_array($qt)){
            $f .= "(userid = '$nt[name]') OR ";


            which would have added all the values in a unique WHERE clause.

            Last, i'm not sure if you can have it as

            $qt=mysql_query("select * from sign where $f (userid = '1') LIMIT 6");


            or it should be:


            $query = "select * from sign where ".$f." (userid = '1') LIMIT 6";
            $qt=mysql_query($query);



            Navaldesign
            Logger Lite: Low Cost, Customizable, multifeatured Login script
            Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
            DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
            Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

            Comment

            • Antonio878
              Master Sergeant

              • Sep 2007
              • 68

              #7
              Re: Php &quot;WHERE clause

              Originally posted by navaldesign View Post
              while($nt=mysql_fetch_array($qt)){
              $f = "(userid = '$nt[name]') OR ";

              will only retrieve ONE value for $nt[name] (the last occurance, or the 6th one if more than 6 exist).

              It should have been (note the ".=" )

              while($nt=mysql_fetch_array($qt)){
              $f .= "(userid = '$nt[name]') OR ";


              which would have added all the values in a unique WHERE clause.

              Last, i'm not sure if you can have it as

              $qt=mysql_query("select * from sign where $f (userid = '1') LIMIT 6");


              or it should be:


              $query = "select * from sign where ".$f." (userid = '1') LIMIT 6";
              $qt=mysql_query($query);


              Oh My Gosh!! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you!

              Seriously Thank you so much!
              Check out:
              Great Windmill (A Place Where You Can Have Fun!)

              You can do so much on the website, check it out!

              Comment

              Working...