Web Analytics Made Easy -
StatCounter select user from database - CodingForum

Announcement

Collapse
No announcement yet.

select user from database

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

  • select user from database

    Hey, i have a script i set up here under the column

    "Please select the correct opponent."

    how can i get it to display all the user in my database?
    can you help me with the code, i have no clue how to do it. thanks.

    http://www.dangmn.net/hp/upload.php

  • #2
    That would be coded in a similar way to my post here:


    http://www.codingforum.net/showthread.php?t=163596





    --------------------
    Leonard Whistler

    Comment


    • #3
      if you are usin mysql you could do something with:
      PHP Code:
      $query "SELECT * FROM example"
           
      $result mysql_query($query) or die(mysql_error());


      $row mysql_fetch_array($result) or die(mysql_error()); 

      Comment


      • #4
        Lol, okay some reason when i insert that script all the users in my database are display on top of the column and not in the <select> option box i have. can someone arrange the code so its right for me please lol.

        PHP Code:
        <html>
        <body>
        <link rel="stylesheet" type="text/css" href="main.css" />

        <?php

        $host
        ="localhost"// Host name
        $username="dangmnne_dangmnx"// Mysql username
        $password="xxxxxxxxxx"// Mysql password
        $db_name="dangmnne_test"// Database name

        // Connect to server and select databse.
        mysql_connect("$host""$username""$password")or die("cannot connect");
        mysql_select_db("$db_name")or die("cannot select DB");

        $query mysql_query("SELECT username FROM members");
        while(
        $row mysql_fetch_array($query))
        {
        echo 
        $row['username'];
        }
        ?>

        <div style="width:450px; height:15px; border:1px solid black; background-color: #535353; color: white; padding: 2px;">
        <strong>Loser</strong></div>

        <div style="width:444px; height:55px; border-left:1px solid black; border-right:1px solid black; border-bottom:1px solid black; background-color: #C0C0C0; color: #000; padding: 5px;">

        <p>Please select the correct opponent.</p><br />
        <form>
        <select name="degree">

        <option>
        <?php
        $query 
        "SELECT username FROM members";
             
        $result mysql_query($query) or die(mysql_error());


        $row mysql_fetch_array($result) or die(mysql_error());
        ?>

        </option>

        </select>
        </form>
        </div>

        <br />

        <div style="width:221px; height:15px; border:1px solid black; background-color: #535353; color: white; padding: 2px;">
        <strong>Replay</strong></div>

        <div style="width:215px; height:85px; border-left:1px solid black; border-right:1px solid black; border-bottom:1px solid black; background-color: #C0C0C0; color: #000; padding: 5px;">
        <p>Please select the correct replay.</p><br />

        <form action="process_upload.php" method="post" enctype="multipart/form-data">
        <input type="file" name="file" id="file" />
        <br />
        <input type="submit" name="Upload" value="Submit" />
        </form>
        </div>

        </body>
        </html>

        Comment


        • #5
          You are so close. Study the browser source code for clues on what's wrong. Some tips:
          • Check for the proper option box drop down menu syntax.
          • Put the database connection info in a separate php file and use the php include function to include it in your files.
          • Since you are using an external CSS file put all your div style info in it, instead of in line as you have it now.




          --------
          Leonard Whistler

          Comment


          • #6
            i just cant figure it out! okay i even got all the users name from my database to display in the box. but i want the lined up vertically~~ someone please PLEASE PLEASE help me with this last part~!!!!!

            http://www.dangmn.net/hp/upload.php


            PHP Code:
            <html>
            <body>
            <link rel="stylesheet" type="text/css" href="main.css" />

            <?php

            $host
            ="localhost"// Host name
            $username="dangmnne_dangmnx"// Mysql username
            $password="xxxx"// Mysql password
            $db_name="dangmnne_test"// Database name

            // Connect to server and select databse.
            mysql_connect("$host""$username""$password")or die("cannot connect");
            mysql_select_db("$db_name")or die("cannot select DB");

            ?>

            <div style="width:450px; height:15px; border:1px solid black; background-color: #535353; color: white; padding: 2px;">
            <strong>Loser</strong></div>

            <div style="width:444px; height:55px; border-left:1px solid black; border-right:1px solid black; border-bottom:1px solid black; background-color: #C0C0C0; color: #000; padding: 5px;">

            <p>Please select the correct opponent.</p><br />

            <form>
            <select name="members">
            <option>
            <?php
            $query 
            mysql_query("SELECT username FROM members");
            while(
            $row mysql_fetch_array($query))
            {
            echo 
            $row['username'];
            }
            ?>

            </option>
            </select>
            </form>
            </div>

            <br />

            <div style="width:221px; height:15px; border:1px solid black; background-color: #535353; color: white; padding: 2px;">
            <strong>Replay</strong></div>

            <div style="width:215px; height:85px; border-left:1px solid black; border-right:1px solid black; border-bottom:1px solid black; background-color: #C0C0C0; color: #000; padding: 5px;">
            <p>Please select the correct replay.</p><br />

            <form action="process_upload.php" method="post" enctype="multipart/form-data">
            <input type="file" name="file" id="file" />
            <br />
            <input type="submit" name="Upload" value="Submit" />
            </form>
            </div>

            </body>
            </html>

            Comment

            Working...
            X