Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
passed information has to display as editable radio button
Old 05-27-2010, 09:29 PM passed information has to display as editable radio button
Novice Talker

Posts: 8
Trades: 0
We were given a database which contains the informations of different ratings (1-4). We have to call the informations from the database about the ratings and display them as radio buttons, and to make them editable by the manager. Below is part of my code for the ratings:

Code:
<?php
$conn1 = mysql_connect("localhost", "TWA", "test");
mysql_select_db("performancereview", $conn1)
or die ('Database not found ' . mysql_error() );

$reviewid1 = mysql_real_escape_string($_GET['reviewid']);
$sql1 = "SELECT jobknowledge FROM reviews WHERE reviewid = '$reviewid1' ";
$rs1 = mysql_query($sql1, $conn1)
or die ('Problem with query' . mysql_error());
?>

<?php while($row1 = mysql_fetch_array($sql1)) { ?> 

<div class="left1"><table class="table1"><tr><td class="width1">
<div class="left"><table class="table2">
<tr>
<td>&nbsp;</td>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
</tr>
<tr>
<td>Job Knowledge</td>
<td><input type="radio" name="jobKnowledge" value="1"/></td>
<td><input type="radio" name="jobKnowledge" value="2"/></td>
<td><input type="radio" name="jobKnowledge" value="3"/></td>
<td><input type="radio" name="jobKnowledge" value="4"/></td>
</tr>

</table></div>
</td></tr></table></div>
<table>
<?php }
mysql_close($conn1); ?>
I'm not sure how to call the values from the database and display them as the radio button.

The rating for job knowledge in the database is 1, so we have to check the 1st radio button but make it editable.

can anyone please help, thanks.
Izzy123 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 05-28-2010, 09:16 AM Re: passed information has to display as editable radio button
Skilled Talker

Posts: 76
Name: Nick Cousins
Location: Northern Ireland
Trades: 0
Hi Izzy123...

If you change your mysql_fetch_array to mysql_fetch_assoc then MySQL will return the field names making it much more useful.

Then...

$row1 should look something like:

array(['jobknowledge']=>2);

We would access this like: $row['jobknowledge'];

So to choose which radio button to select (simply) we could do:

<td><input type="radio" name="jobKnowledge" <?php if ($row['jobknowledge']=='1'){echo "checked";} ?> value="1"/></td>
<td><input type="radio" name="jobKnowledge" <?php if ($row['jobknowledge']=='2'){echo "checked";} ?> value="2"/></td>
<td><input type="radio" name="jobKnowledge" <?php if ($row['jobknowledge']=='3'){echo "checked";} ?> value="3"/></td>
<td><input type="radio" name="jobKnowledge" <?php if ($row['jobknowledge']=='4'){echo "checked";} ?> value="4"/></td>

Hope that makes some sense - try it out and let me know how you get on.

Good luck!
__________________
Join
Please login or register to view this content. Registration is FREE


Knowledge is power. Never underestimate the power of stupid people in large numbers.


Last edited by HandCoder; 05-28-2010 at 09:20 AM..
HandCoder is offline
Reply With Quote
View Public Profile Visit HandCoder's homepage!
 
Old 05-29-2010, 08:18 AM Re: passed information has to display as editable radio button
Novice Talker

Posts: 8
Trades: 0
hey it works, thanks a lot
Izzy123 is offline
Reply With Quote
View Public Profile
 
Old 05-29-2010, 08:50 AM Re: passed information has to display as editable radio button
Skilled Talker

Posts: 76
Name: Nick Cousins
Location: Northern Ireland
Trades: 0
Happy to help :-)
__________________
Join
Please login or register to view this content. Registration is FREE


Knowledge is power. Never underestimate the power of stupid people in large numbers.

HandCoder is offline
Reply With Quote
View Public Profile Visit HandCoder's homepage!
 
Old 05-29-2010, 08:56 AM Re: passed information has to display as editable radio button
Skilled Talker

Posts: 76
Name: Nick Cousins
Location: Northern Ireland
Trades: 0
If you want to slim the code a little you could do this:

PHP Code:
<?php
$jk
=1;
while (
$jk<5)
  {
    echo 
'<td><input type="radio" name="jobKnowledge" ';
    if  (
$row['jobknowledge']==$jk){echo "checked";}
    echo 
' value="'.$jk.'"/></td>';
    
$jk++;
  }
?>
This will automatically output 4 radio buttons and mark the appropriate one "checked".
__________________
Join
Please login or register to view this content. Registration is FREE


Knowledge is power. Never underestimate the power of stupid people in large numbers.

HandCoder is offline
Reply With Quote
View Public Profile Visit HandCoder's homepage!
 
Reply     « Reply to passed information has to display as editable radio button
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.98647 seconds with 12 queries