freshrod Posted April 19, 2006 Share Posted April 19, 2006 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%"><?phpswitch ($_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. Quote Link to comment https://forums.phpfreaks.com/topic/7816-form-value-from-a-db-query/ Share on other sites More sharing options...
freshrod Posted April 20, 2006 Author Share Posted April 20, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/7816-form-value-from-a-db-query/#findComment-28989 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.