Jump to content

Form value from a DB query?


freshrod

Recommended Posts

This is for a game I'm trying to make. The players select a job that is based on their breed. The jobs are in the DB.

I don't know how to get the radio input's value to be the same as the job (or jobName, as it's called in the DB) for that row, so I can then assign it to a SESSION.

This is what I have so far:

<form id="jobs" name="jobs" action="char_menu.php" method="post">
<tr>
<td align="center" valign="middle" width="33%">
<?php

switch ($_SESSION['breed']) {
case 'Human':
$abilities = 3;
break;
case 'Altered':
$abilities = 2;
break;
case 'Mutant':
$abilities = 1;
break;
default:
echo "ERROR!!!";
}

function displayJobs ($result) {
print "<h3>Avalible Jobs for " . $_SESSION['breed'] . "</h3>\n";
print "\n<table>\n<tr>\n" .
"\n\t<th>Job Title</th>" .
"\n\t<th>Job Pay</th>" .
"\n\t<th>Job Description</th>" .
"\n\t<th>Select One</th>" .
"\n</tr>";

while ($row = @ mysql_fetch_row($result)) {
print "\n<tr>";

foreach ($row as $data)
print "\n\t<td><center> {$data} </center></td>";
print "\n\t<td><input type=\"radio\" name=\"job\" value=\"???\"></td>";
print "\n</tr>";
}
print "\n</table>\n";
}

$query = "SELECT jobName, jobPay, jobDescription FROM jobs WHERE numAbil <= {$abilities} ORDER BY jobName ASC";

displayJobs($result);

?>

This is my first post, so I hope I didn't mess it up.
Link to comment
Share on other sites

Sorry for the double post, but I wanted to rescue my initial post from archive hell (or is it archive purgatory?), and I also thought of something that might increase the chances someone might have an idea about how to help me.

I know that DB querys are returned as arrays in php, right? But I really don't understand arrays very well. So is there a way to assign a value to a certain field from the table (in this case the jobName field) and then use that for the value in the radio button form?

Something like:

$job=$data[0];
$jobName=$data[1]; etc...

then:

<input type="radio" name="job" value="$data[1]">

I don't know...like I said I don't understand arrays very well yet.

Thanks for any help.
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.