9 Replies - 748 Views - Last Post: 11 April 2009 - 05:51 PM Rate Topic: -----

#1 dangmnx  Icon User is offline

  • D.I.C Regular

Reputation: -1
  • View blog
  • Posts: 428
  • Joined: 10-April 09

how to display my database user!

Posted 10 April 2009 - 04:00 PM

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
Is This A Good Question/Topic? 0
  • +

Replies To: how to display my database user!

#2 FrozenSnake  Icon User is offline

  • En man från Sverige!

Reputation: 122
  • View blog
  • Posts: 997
  • Joined: 30-July 08

Re: how to display my database user!

Posted 10 April 2009 - 04:04 PM

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

Something like that will display the usernames from the table users.
Fix it to fit your table and columns
Was This Post Helpful? 0
  • +
  • -

#3 dangmnx  Icon User is offline

  • D.I.C Regular

Reputation: -1
  • View blog
  • Posts: 428
  • Joined: 10-April 09

Re: how to display my database user!

Posted 10 April 2009 - 06:40 PM

okay, so i got all the users in my database to display on that page, but i want them to display in the <input> option box, how can i do this?

here is the link: http://www.dangmn.net/hp/upload.php

here is what my code looks like as of now.

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

<?php

$host="localhost"; // Host name
$username="dangmnne_dangmnx"; // Mysql username
$password="password"; // 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>Datbase user here</option>
<option>Datbase user here</option>
<option>Datbase user here</option>
<option>Datbase user here</option>
<option>Datbase user here</option>
<option>Datbase user here</option>
<option>Datbase user here</option>
<option>Datbase user here</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>



can someone sort that part out for me, thank you again.

This post has been edited by dangmnx: 10 April 2009 - 06:42 PM

Was This Post Helpful? 0
  • +
  • -

#4 FrozenSnake  Icon User is offline

  • En man från Sverige!

Reputation: 122
  • View blog
  • Posts: 997
  • Joined: 30-July 08

Re: how to display my database user!

Posted 10 April 2009 - 07:32 PM

thats not to hard
<select name="degree">
<?php
$query = mysql_query("SELECT username FROM users");
while($row = mysql_fetch_array($query))
{
echo "<option>".$row['username']."</option>";
}
?>
</select>

Was This Post Helpful? 1
  • +
  • -

#5 dangmnx  Icon User is offline

  • D.I.C Regular

Reputation: -1
  • View blog
  • Posts: 428
  • Joined: 10-April 09

Re: how to display my database user!

Posted 11 April 2009 - 08:04 AM

Thank you so much that works great, if you can help me with the last part i will appreciate it.

okay, now that i have my upload form, and my user database done,

is it possible for me to have the two of them display after i click the submit button.

ex: select user name > find the file you want to upload, then click submit

result: LOSER <username> selected and file.

Here are my code for it, i just need it to show as i describe, thanks!

Process_upload
<?php

$db = mysql_connect('localhost', 'dangmnne_dangmnx', 'xxxx'); //fill in host, hostname, hostpass with your own

if (!$db)
  {
  die('Could not connect: ' . mysql_error());
  }


$db_selected = mysql_select_db('dangmnne_test', $db); //fill in DBname with your own

if (!db_selected)
{

die("cant connect");

}

	if ($_FILES["file"]["error"] > 0)
	{
	echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
	}
  else
	{
		move_uploaded_file($_FILES["file"]["tmp_name"], "/home/dangmnne/public_html/hp/upload/" . $_FILES["file"]["name"]);

		$replay = "" . $_FILES["file"]["name"];
		$replay2 = "<a href=\"http://www.dangmn.net/hp/upload/" .$replay. "\"><img src = \"http://www.dangmn.net/hp/image.jpg\" style=\"border-style: none\"/></a>"; //replace "yoursite" with your own site

		$query = "INSERT INTO test (replay)
VALUES ('".$replay2."')";

$result = mysql_query($query) or die(mysql_error());

mysql_close($db);
		

} 
?>

<p>upload was sucessful click<a href="report.php"> here </a>to return</p>




upload.php
<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">

<?php
$query = mysql_query("SELECT username FROM members");
while($row = mysql_fetch_array($query))
{
echo "<option>".$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>


Display_reps this is where i want it to be displayed,
<?php

$db = mysql_connect('localhost', 'dangmnne_dangmnx', 'xxxx'); //fill in host, hostname, hostpass with your own

if (!$db)
  {
  die('Could not connect: ' . mysql_error());
  }


$db_selected = mysql_select_db('dangmnne_test', $db); //fill in DBname with your own

if (!db_selected)
{

die("cant connect");

}

$result = mysql_query("SELECT replay FROM test");

echo "<table ALIGN='center' border='1'>
<tr>
<th><FONT COLOR='#000'>Replay</th>
</tr>";


while($row = mysql_fetch_array($result))
  {
  
  echo "<tr>";
  echo "<td ALIGN='CENTER'><FONT COLOR='#000'>" . $row['replay'] . "</td>";
  echo "</tr>";
   }
  
echo "</table>";

mysql_close($db);

?>

Was This Post Helpful? 0
  • +
  • -

#6 SpaceMan  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 10
  • View blog
  • Posts: 507
  • Joined: 20-February 03

Re: how to display my database user!

Posted 11 April 2009 - 08:58 AM

sounds like you want another table.

change.
<?php

$query = mysql_query("SELECT userid,username FROM users");
while($row = mysql_fetch_array($query))
{
echo "<option value=".$row['username'].">".$row['username']."</option>";
}

?>


add another table, for replay lookups
after posted, insert the user id of the poster, and the one selected. and any other info, like the file name uplaoded.
then can do a join, userid's to get the names..

This post has been edited by SpaceMan: 11 April 2009 - 08:59 AM

Was This Post Helpful? 0
  • +
  • -

#7 dangmnx  Icon User is offline

  • D.I.C Regular

Reputation: -1
  • View blog
  • Posts: 428
  • Joined: 10-April 09

Re: how to display my database user!

Posted 11 April 2009 - 10:24 AM

so i add another table in my phpadmin called replay lookup?

then i add in the fields, id, file name upload,??
Was This Post Helpful? 0
  • +
  • -

#8 SpaceMan  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 10
  • View blog
  • Posts: 507
  • Joined: 20-February 03

Re: how to display my database user!

Posted 11 April 2009 - 11:40 AM

View Postdangmnx, on 11 Apr, 2009 - 09:24 AM, said:

so i add another table in my phpadmin called replay lookup?

then i add in the fields, id, file name upload,??



is how i would do it, so users don't mess with the user table.
is call relational tables. (spelling?)
look up "inner join" on mysql.com for some examples.

basicly is,

select username from lookup
inner join users using(userid)
where lookup.replay = something?

maybe to make it easeir...

lookup has 2 userids named what you like to, user1,user2

select * from lookup
where lookup.replay = something?

while(row = fetch){
select username from users where user1
select username from users where user2

display all the information you need..


}
Was This Post Helpful? 0
  • +
  • -

#9 dangmnx  Icon User is offline

  • D.I.C Regular

Reputation: -1
  • View blog
  • Posts: 428
  • Joined: 10-April 09

Re: how to display my database user!

Posted 11 April 2009 - 05:47 PM

I'm totatly lost on this, is it possible to make it any clearer? thank you.
Was This Post Helpful? 0
  • +
  • -

#10 SpaceMan  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 10
  • View blog
  • Posts: 507
  • Joined: 20-February 03

Re: how to display my database user!

Posted 11 April 2009 - 05:51 PM

i just realized you have it already, i was fully reading your posted codes...

have fun
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1