Page 1 of 2
Populating an Input field.
Posted: Sat May 07, 2011 10:51 pm
by GenSwat
I believe it was your tutorial where you were sending data across and ending up in a text field.If so do you have the link.
It would be useful for a project I would like to start and complete.
Making a Braket system when they sign up it assigns their name from database to a text field on a differant page.
I am just not sure on the approach.
Re: Jacek
Posted: Sat May 07, 2011 11:08 pm
by jacek
GenSwat wrote:I believe it was your tutorial where you were sending data across and ending up in a text field.
I'd be happy to look for it if you explain what on Earth you mean by that
Re: Jacek
Posted: Sat May 07, 2011 11:10 pm
by EcazS
<input type="text" value="<?php echo $variable; ?>" />
???
Re: Jacek
Posted: Sat May 07, 2011 11:15 pm
by GenSwat
jacek wrote:GenSwat wrote:I believe it was your tutorial where you were sending data across and ending up in a text field.
I'd be happy to look for it if you explain what on Earth you mean by that
Maybe I should of stated You Submit/POST data from a testfield and send it to a textbox? Dun know?
But the answer is below
1.<input type="text" value="<?php echo $variable; ?>" />
Thank You EcazS
Re: Jacek
Posted: Sat May 07, 2011 11:18 pm
by jacek
GenSwat wrote:Maybe I should of stated You Submit/POST data from a testfield and send it to a textbox? Dun know?
Ah, I know what you mean now, I don’t ever remember doing that though.
I guess it doesn't matter if you have the answer.
Also I renamed this topic, can you make sure you give descriptive titles
Re: Populating an Input field.
Posted: Sat May 07, 2011 11:51 pm
by GenSwat
Sorry, I will try harder to come up with the correct names, yes populating an input field.
I will be using this method and have it send to another page and insert the usersname into each one by userid.
I am hoping this would be the easiest way.
and the usernames would be submitted to database then inserted in the input fields on next page
Re: Populating an Input field.
Posted: Sat May 07, 2011 11:53 pm
by jacek
well this is what you want to do then
.
you can just do like the example
<input type="text" name="something" value="<?php echo $_POST['something']; ?>" />
Re: Populating an Input field.
Posted: Sun May 08, 2011 12:26 am
by GenSwat
Now I could querry the unique id's of each username into each input field through a mysql db.
$query = "SELECT * FROM id where id=1";. $result = mysql_query($query);. $row = mysql_fetch_assoc($result);. $contents = $row['content'];
Re: Populating an Input field.
Posted: Sun May 08, 2011 10:50 am
by jacek
I'm not really sure what your question is there, but you could do that yes.
Re: Populating an Input field.
Posted: Sun May 08, 2011 2:03 pm
by GenSwat
OK maybe I if I break down the pages and process.
signup.php // place where users sigun up for the event and names submited to db
dbconn.php//database connect info
bracket.php // inputfields that will be filled with username based off number of signups. This will be the page also that users can come to and find out who the face in the tournament.
I will have to add an admin.php so as the winner advances db can update and move player to next slot "inputfield"
not sure on this,maybe a winner button next to name that would submit the winner and update and advance player to next round.
Re: Populating an Input field.
Posted: Sun May 08, 2011 2:11 pm
by jacek
I don't really see what you are asking
Re: Populating an Input field.
Posted: Sun May 08, 2011 2:21 pm
by GenSwat
sorry, I am still a noob so hard to talk in terms, ok I am not sure on how to write the exact query, to get the usernames to insert into the Input fields on the other page, so that a user can visit and they can see the results. so as they sign up the page will constantly be updated.(filling of each input field"
Well let me work on the script some more and submit something maybe it will make sense then.
Re: Populating an Input field.
Posted: Sun May 08, 2011 2:54 pm
by jacek
well if you do
$result = mysql_query("SELECT `name` FROM `users`");
while ($row = mysql_fetch_assoc($result)){
echo "<input type=\"text\" name=\"names[]\" value=\"{$row['name']}\" />"
}
It will output a input box for all of the users in the users table. Is that what you are trying to do ?
Re: Populating an Input field.
Posted: Sun May 08, 2011 3:31 pm
by GenSwat
yes but the input box would contain the username and there is a pattern for the input boxes as in the image in the above post
and the names have to stay in first column so as they win the advance to the next column
Re: Populating an Input field.
Posted: Fri May 13, 2011 4:08 am
by GenSwat
jacek wrote:well if you do
$result = mysql_query("SELECT `name` FROM `users`");
while ($row = mysql_fetch_assoc($result)){
echo "<input type=\"text\" name=\"names[]\" value=\"{$row['name']}\" />"
}
It will output a input box for all of the users in the users table. Is that what you are trying to do ?
Ok I used this
<?php
include('dbconnect.php');
$query = "SELECT `name` FROM `users`";
$result = mysql_query("$query");
while ($row = mysql_fetch_assoc($result)){
echo $row['name'] . "<br />";
}
?>
Results were
John Doe
Jane Doe
Mr Bill
how would I just echo one of there names?
Re: Populating an Input field.
Posted: Fri May 13, 2011 6:17 am
by Tino
You would use LIMIT 1 at the end of the query to make sure only one is displayed. If you want to have control over which one to display as well, you would do something like
SELECT `name` FROM `users` WHERE `name` = 'A username' LIMIT 1
Re: Populating an Input field.
Posted: Sat May 14, 2011 12:38 am
by GenSwat
Tino wrote:You would use LIMIT 1 at the end of the query to make sure only one is displayed. If you want to have control over which one to display as well, you would do something like
SELECT `name` FROM `users` WHERE `name` = 'A username' LIMIT 1
That works in limiting the first user in the table, but how do I assign each user in the table a variable, so I can call on them as followed.
echo player1
echo player 2
up to as many users needed.
and so on...
I played with diffrant scenerios and was able to get the num_rows to assgin
row[1] = the first name
row[2] = last name
but I can figure out just the column of users to be
user[1]= Player 1's name
user[2] = Player2 's name
thanks for the help
Re: Populating an Input field.
Posted: Sat May 14, 2011 4:19 am
by GenSwat
OK maybe I can make sense, look at this code below
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="default.css" />
<title>Untitled Document</title>
</head>
<body>
<div id="container">
<?php
include( 'dbconnect.php' );
$result= mysql_query("SELECT * FROM `users` ORDER BY ID");
echo "<table border='0'>
<tr>
<th>UserName</th>
</tr>";
while($row = mysql_fetch_array( $result ) ) {
echo "</table>";
if($row['id'] == 11){
echo $row['name'];
}
}
?>
Now that willl echo the players name with id == 11. Now the question is how would I assign each id to a unique variable.
$player1 //would be id1 in database
$player2 //would be id2 in database and so on and so on
The reason for this ,I would to be able to echo a differant player/user in a seperate table in a specific format on a webpage
Re: Populating an Input field.
Posted: Sat May 14, 2011 12:07 pm
by jacek
You would put them all into an array.
while($row = mysql_fetch_array( $result ) ) {
$players[$row['id']] = $row;
}
Re: Populating an Input field.
Posted: Sat May 14, 2011 3:18 pm
by GenSwat
jacek wrote:You would put them all into an array.
while($row = mysql_fetch_array( $result ) ) {
$players[$row['id']] = $row;
}
Now using that how would I replace Player name with a each user from database
example of Bracket
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang='en'>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=ISO-8859-1'>
<title>MY Tournament</title>
<!-- link rel='stylesheet' href='style.css' type='text/css' -->
<style type="text/css">
<!--
table {
border-collapse: collapse;
border: none;
font: small arial, helvetica, sans-serif;
}
td {
vertical-align: middle;
width: 10em;
margin: 0;
padding: 0;
}
td p {
border-bottom: solid 1px black;
margin: 0;
padding: 5px 5px 2px 5px;
}
-->
</style>
</head>
<body>
<table summary="Tournament Bracket">
<tr>
<td><p>1. Player name</p></td>
<td rowspan="2"><p>Player name</p></td>
<td rowspan="4"><p>Player name</p></td>
<td rowspan="8"><p>Player name</p></td>
<td rowspan="16"><p>Player name</p></td>
</tr>
<tr>
<td><p>16. Player name</p></td>
</tr>
<tr>
<td><p>8. Player name</p></td>
<td rowspan="2"><p>Player name</p></td>
</tr>
<tr>
<td><p>9. Player name</p></td>
</tr>
<tr>
<td><p>5. Player name</p></td>
<td rowspan="2"><p>Player name</p></td>
<td rowspan="4"><p>Player name</p></td>
</tr>
<tr>
<td><p>12. Player name</p></td>
</tr>
<tr>
<td><p>4. Player name</p></td>
<td rowspan="2"><p>Player name</p></td>
</tr>
<tr>
<td><p>13. Player name</p></td>
</tr>
<tr>
<td><p>6. Player name</p></td>
<td rowspan="2"><p>Player name</p></td>
<td rowspan="4"><p>Player name</p></td>
<td rowspan="8"><p>Player name</p></td>
</tr>
<tr>
<td><p>11. Player name</p></td>
</tr>
<tr>
<td><p>3. Player name</p></td>
<td rowspan="2"><p>Player name</p></td>
</tr>
<tr>
<td><p>14. Player name</p></td>
</tr>
<tr>
<td><p>7. Player name</p></td>
<td rowspan="2"><p>Player name</p></td>
<td rowspan="4"><p>Player name</p></td>
</tr>
<tr>
<td><p>10. Player name</p></td>
</tr>
<tr>
<td><p>2. Player name</p></td>
<td rowspan="2"><p>Player name</p></td>
</tr>
<tr>
<td><p>15. Player name</p></td>
</tr>
</table>
</body>
</html>
Re: Populating an Input field.
Posted: Sun May 15, 2011 6:14 pm
by GenSwat
I got it I kept checking php sites and php.org and figured
$players[1][1];
would echo player name 1 and [2][1] player 2 and so on Thank you all so much.
Just curious is there a way to make the [2] be random number 1-20, so the Tournament Bracket would have differnat names ,in differant orders ,every time we had a tournament?