Jump to content

How do I get array elements to populate textboxes?


octacon

Recommended Posts

Hope someone can help me out or steer me in the right direction.

 

I have here a comma delimited text file being read to an array (at least I think I do) and i want the array elements to populate 3 textboxes on the form when a user clicks on open button. How do I go about doing this. Also I need to be able to move backward and forward through the array. I am not even sure if the way I am going about it is correct so I would appreciate any pointers. I have supplied my code so far...please let me know what you guys think i should do.

 

Thanks!

 

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Players</title>
</head>

<body>
<h1>Players</h1>

First Name:  <input type="text" name="txtFirstName" size="12" value="$CurPlayer">

<p>Last Name:  <input type="text" name="txtLastName" size="12">
</p>
<p>Salary:  <input type="text" name="txtSalary" size="10">
</p>

<input type="button" name="btnOpen" value="Open">
<input type="button" name="btnBack" value="<">
<input type="button" name="btnForward" value=">">
<input type="button" name="btnClose" value="Close">

<?php

$Players= fopen("B1Players.txt", "r");
$Count = 1;
$CurData = fgetcsv($Players, ",");
while(!feof($Players)){
$CurPlayer = explode(", ", $CurData);
$FirstName = $CurPlayer[0];
$CurData = fgets($Players);
++$Count;
}
fclose($Players);
?>

</body>

</html>

Link to comment
Share on other sites

Well, you're going to need some javascript to handle the buttons to move things around.

 

But before anyone could help you, we'd need to know a little more about the structure of the text file. You mention moving forwards and backwards. Im assuming this is through the data - in which case, how is is stored? Does the text file contain a long list of values, all comma separated? Or is there 3 values on each line?

 

I would suggest having PHP read the file into an array in javascript. You would then be able to move backward and forward though the data nicely.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.