Populating an Input field.

Post here is you are having problems with any of the tutorials.
User avatar
GenSwat
Posts: 74
Joined: Sat May 07, 2011 3:37 pm

Populating an Input field.

Post 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.
One of my Favorites
Image
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Jacek

Post 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 :lol:
Image
User avatar
EcazS
Posts: 789
Joined: Fri May 06, 2011 5:29 pm

Re: Jacek

Post by EcazS »

[syntax=php]<input type="text" value="<?php echo $variable; ?>" />[/syntax]
???
User avatar
GenSwat
Posts: 74
Joined: Sat May 07, 2011 3:37 pm

Re: Jacek

Post 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 :lol:



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

[syntax=php]1.<input type="text" value="<?php echo $variable; ?>" />
[/syntax]

Thank You EcazS
One of my Favorites
Image
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Jacek

Post 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 :D
Image
User avatar
GenSwat
Posts: 74
Joined: Sat May 07, 2011 3:37 pm

Re: Populating an Input field.

Post 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.


Image

and the usernames would be submitted to database then inserted in the input fields on next page
One of my Favorites
Image
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Populating an Input field.

Post by jacek »

well this is what you want to do then ;).

you can just do like the example

[syntax=xhtml]<input type="text" name="something" value="<?php echo $_POST['something']; ?>" />[/syntax]
Image
User avatar
GenSwat
Posts: 74
Joined: Sat May 07, 2011 3:37 pm

Re: Populating an Input field.

Post by GenSwat »

Now I could querry the unique id's of each username into each input field through a mysql db.
[syntax=php]
$query = "SELECT * FROM id where id=1";. $result = mysql_query($query);. $row = mysql_fetch_assoc($result);. $contents = $row['content'];[/syntax]
One of my Favorites
Image
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Populating an Input field.

Post by jacek »

I'm not really sure what your question is there, but you could do that yes.
Image
User avatar
GenSwat
Posts: 74
Joined: Sat May 07, 2011 3:37 pm

Re: Populating an Input field.

Post 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.
One of my Favorites
Image
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Populating an Input field.

Post by jacek »

I don't really see what you are asking :?
Image
User avatar
GenSwat
Posts: 74
Joined: Sat May 07, 2011 3:37 pm

Re: Populating an Input field.

Post 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.
One of my Favorites
Image
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Populating an Input field.

Post by jacek »

well if you do

[syntax=php]$result = mysql_query("SELECT `name` FROM `users`");

while ($row = mysql_fetch_assoc($result)){
echo "<input type=\"text\" name=\"names[]\" value=\"{$row['name']}\" />"
}[/syntax]

It will output a input box for all of the users in the users table. Is that what you are trying to do ?
Image
User avatar
GenSwat
Posts: 74
Joined: Sat May 07, 2011 3:37 pm

Re: Populating an Input field.

Post 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
One of my Favorites
Image
User avatar
GenSwat
Posts: 74
Joined: Sat May 07, 2011 3:37 pm

Re: Populating an Input field.

Post by GenSwat »

jacek wrote:well if you do

[syntax=php]$result = mysql_query("SELECT `name` FROM `users`");

while ($row = mysql_fetch_assoc($result)){
echo "<input type=\"text\" name=\"names[]\" value=\"{$row['name']}\" />"
}[/syntax]

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 [syntax=php]<?php

include('dbconnect.php');

$query = "SELECT `name` FROM `users`";
$result = mysql_query("$query");

while ($row = mysql_fetch_assoc($result)){

echo $row['name'] . "<br />";
}
?>[/syntax]

Results were

John Doe
Jane Doe
Mr Bill

how would I just echo one of there names?
One of my Favorites
Image
Tino
Posts: 360
Joined: Thu May 05, 2011 8:55 pm
Location: The Netherlands

Re: Populating an Input field.

Post 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

[syntax=sql]SELECT `name` FROM `users` WHERE `name` = 'A username' LIMIT 1[/syntax]
Please check out my CodeCanyon items.
User avatar
GenSwat
Posts: 74
Joined: Sat May 07, 2011 3:37 pm

Re: Populating an Input field.

Post 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

[syntax=sql]SELECT `name` FROM `users` WHERE `name` = 'A username' LIMIT 1[/syntax]


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
One of my Favorites
Image
User avatar
GenSwat
Posts: 74
Joined: Sat May 07, 2011 3:37 pm

Re: Populating an Input field.

Post by GenSwat »

OK maybe I can make sense, look at this code below


[syntax=php]<!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'];
}

}
?> [/syntax]


Now that willl echo the players name with id == 11. Now the question is how would I assign each id to a unique variable.
[syntax=php]$player1 //would be id1 in database
$player2 //would be id2 in database and so on and so on[/syntax]
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
One of my Favorites
Image
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Populating an Input field.

Post by jacek »

You would put them all into an array.

[syntax=php] while($row = mysql_fetch_array( $result ) ) {
$players[$row['id']] = $row;
}[/syntax]
Image
User avatar
GenSwat
Posts: 74
Joined: Sat May 07, 2011 3:37 pm

Re: Populating an Input field.

Post by GenSwat »

jacek wrote:You would put them all into an array.

[syntax=php] while($row = mysql_fetch_array( $result ) ) {
$players[$row['id']] = $row;
}[/syntax]


Now using that how would I replace Player name with a each user from database

example of Bracket

[syntax=xhtml]<!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>[/syntax]
One of my Favorites
Image
User avatar
GenSwat
Posts: 74
Joined: Sat May 07, 2011 3:37 pm

Re: Populating an Input field.

Post by GenSwat »

I got it I kept checking php sites and php.org and figured
[syntax=php]$players[1][1]; [/syntax]
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?
One of my Favorites
Image
Post Reply