Jump to content


Form value from a DB query?

  • Please log in to reply
1 reply to this topic

#1 freshrod

  • Members
  • PipPip
  • Member
  • 25 posts

Posted 19 April 2006 - 05:48 AM

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.
Nothing is foolproof to a talented fool.

#2 freshrod

  • Members
  • PipPip
  • Member
  • 25 posts

Posted 20 April 2006 - 02:49 PM

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.
Nothing is foolproof to a talented fool.

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users