Jump to content


This topic is now archived and is closed to further replies.


Form value from a DB query?

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">
<td align="center" valign="middle" width="33%">

switch ($_SESSION['breed']) {
case 'Human':
$abilities = 3;
case 'Altered':
$abilities = 2;
case 'Mutant':
$abilities = 1;
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>" .

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";



This is my first post, so I hope I didn't mess it up.

Share this post

Link to post
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:

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


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

Share this post

Link to post
Share on other sites


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.