Web Analytics Made Easy -
StatCounter Completely stuck - CodingForum

Announcement

Collapse
No announcement yet.

Completely stuck

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Completely stuck

    I'm trying to get users details based on what the name of the directory is, I'm using $dir as the variable. I've been trying to do this for ages (about an hour or two) and haven't gotten anywhere.

    I have no idea how to do the select query from the database to choose the right member, based on the directory ($dir).

    The table is named members and I'm wanting to get the username, bio and country from the database. I've tried everyway I can think of, but I get no results or errors.

    I know this might be confusing, thanks if you can help.

  • #2
    Can you post some code showing your problem? Are you using php? Perl? ASP?
    Create accessible online surveys -::- Koobten.com - compare netbook prices and reviews -::- Affordable, reliable hosting for less than $20 per year
    Zend Certified Engineer

    Comment


    • #3
      PHP Code:
      @mysql_connect($dbhost,$dbuname,$dbpass) OR die("Could not connect to the database please make sure the sign in info is correct");
                                          @
      mysql_select_db($dbname) OR die("That database does not appear to exist or you do not have permissions to manipulate it");
                                          
      $sql "SELECT username,country,bio from members";
                                          
      $result mysql_query($sql);

                                          echo 
      "$username    ";
                                          echo 
      "<br>";
                                          echo 
      "$country";
                                          echo 
      "<br>";
                                          echo 
      "$bio"
      I'm new to this so I have no idea on how to do it. Using php

      Comment


      • #4
        Try this...

        Code:
        @mysql_connect($dbhost,$dbuname,$dbpass) OR die("Could not connect to the database please make sure the sign in info is correct");
                                            @mysql_select_db($dbname) OR die("That database does not appear to exist or you do not have permissions to manipulate it");
                                            $sql = "SELECT username,country,bio from members";
                                            $result = mysql_query($sql);
                                            $data = mysql_fetch_assoc($result);//new line here.
                                            echo "$data['username']    ";
                                            echo "<br>";
                                            echo "$data['country']";
                                            echo "<br>";
                                            echo "$data['bio']";
        That shoud do it.
        Create accessible online surveys -::- Koobten.com - compare netbook prices and reviews -::- Affordable, reliable hosting for less than $20 per year
        Zend Certified Engineer

        Comment


        • #5
          That throws an error:

          Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in c:\phpdev\www\public\chatterspics\users\nighty\index.php on line 67


          Line 67 is

          echo "$data['username']";

          Also, would this select the right member from the directory name?

          example

          www.chatterspics.com/users/testalias

          testalias is the name of the user I want the details showing of.

          To get the directory name, I'm using:

          PHP Code:
          $url explode("/",$PHP_SELF);
          $filename $url[sizeof($url)-1];
          $dir $url[sizeof($url)-2];

          echo 
          "$dir"
          How can I use that in a select query to get the right users details?

          I tried

          select username,country, bio from members where $dis='username'

          but that never gave a result either.

          Comment


          • #6
            I've fixed it after I took some time from the PC.

            PHP Code:
            $result mysql_query("SELECT username,bio, country from members WHERE username='$dir'");
                                                if (
            $row mysql_fetch_array($result)) {

                                                do {
                                                  echo 
            $row["username"];
                                                  echo 
            "<br>";
                                                  echo 
            $row["country"];
                                                  echo 
            "<br>";
                                                  echo 
            $row["bio"];
                                                } while(
            $row mysql_fetch_array($result));

                                                } else {
                                                echo 
            "Sorry, no records were found!";} 

            Comment


            • #7
              you can also do this

              PHP Code:
              $result mysql_query("SELECT username,bio, country from members WHERE username='$dir'");
              list(
              $username,$bio,$country) = mysql_fetch_array($result);
              if(
              mysql_num_rows($result)>0)
              {
              echo 
              "$username<br>$country<br>$bio";
              }
              else
              {
              echo 
              "Sorry, no records were found!";

              Jee
              Jeewhizz - MySQL Moderator
              http://www.sitehq.co.uk
              PHP and MySQL Hosting

              Comment

              Working...
              X