proctk Posted July 17, 2007 Share Posted July 17, 2007 I have a form which can a variable number of rows. each row will have a radio button. I want a radio button to be selected if matching values are found in two tables the common value $photos['image_name'] from table image files and $album['album_cover'] from table albumNames Script not written to get this value thank you for any help site code <form name="make_changes" method="post" action="<?php $PHP_SELF; ?>"> <?php //Get & group photos $query_get_photos = ("select * from image_files WHERE user_id = '$user_id' AND album = '$album'"); $get_photos= mysql_query($query_get_album)or die("SQL Error: $query_get_album<br>" . mysql_error()); while ($photos=mysql_fetch_array($get_photos)) {?> <table class="columntable" style="border:3px solid #EBEBEB;"> <tr> <td rowspan="4">Caption:</td> <td rowspan="4"><textarea name="details[<?php echo $photos['image_id'];?>]" cols="30" rows="5" id="details[]"><?php echo $photos['details']; ?></textarea></td> <td style="padding-top:5px;"><div class="thumbNew"> <div align="center"><a class="info" href="../user_images/<?php echo $photos['image_name'];?>"> <img src="../user_images/<?php echo $photos['image_name'];?>" height="90" width="145" alt="<?php echo $photos['image_name'];?>" /></a> </p> </div> </div> </td> </tr> <tr> <td class="tableTopBorder"><input name="radiobutton" type="radio" value="radiobutton" /> This is the album cover.</td> </tr> <tr> <td class="tableTopBorder"><input name="delete[<?php echo $photos['image_id'];?>]" type="checkbox" id="delete[<?php echo $photos['image_id'];?>]" value=" checkbox" /> Delete this Photo </td> </tr> <tr> <td class="tableBottomBorder" style="padding-bottom:5px;">Move to: <select name="album[<?php echo $photos['image_id'];?>]" id="albums[]"> <option selected="selected"></option> <?php $query_get_names = "select * from image_files WHERE user_id = '$user_id' GROUP BY `album`"; if ($result = mysql_query($query_get_names)) { if (mysql_num_rows($result)) { while($names = mysql_fetch_assoc($result)) { echo "<option 'width:75px' "; if($names['album'] == $_GET['album']){ echo " selected='selected'"; } echo"value='{$names['album']}'>{$names['album']}</option>\n"; } } } else { echo "SQL Error: $query_get_albums<br>" . mysql_error(); } ?> </select> </td> </tr> </table> Link to comment https://forums.phpfreaks.com/topic/60301-select-radio-button/ Share on other sites More sharing options...
proctk Posted July 17, 2007 Author Share Posted July 17, 2007 here is what the radio button looks like. now I need to figure out how to select the radio button that matches the value of another query. I can create the query and assign the value to be tested to a variable but I don't know how to test that value against the value in the radio button <td class="tableTopBorder"><input name="album_cover" type="radio" value="<?php echo $photos['image_name'];?>" /> This is the album cover.</td> Link to comment https://forums.phpfreaks.com/topic/60301-select-radio-button/#findComment-299970 Share on other sites More sharing options...
proctk Posted July 17, 2007 Author Share Posted July 17, 2007 here is what I have this far, its not working any help is excellent <form name="make_changes" method="post" action="<?php $PHP_SELF; ?>"> <?php //Get & group photos ///Get Albums $query_get_albumCovers = ("select * from albumNames WHERE user_id = '$user_id' AND album = '$album'"); $get_albumCovers= mysql_query($query_get_albumCovers)or die("SQL Error: $query_get_albumCovers<br>" . mysql_error()); while ($albumCovers=mysql_fetch_array($get_albumCovers)) { if($photos['image_name'] == $albumCovers['album_cover']){ $checked = "checked"; }else{ $checked = ""; } //Get Photos $query_get_photos = ("select * from image_files WHERE user_id = '$user_id' AND album = '$album'"); $get_photos= mysql_query($query_get_album)or die("SQL Error: $query_get_album<br>" . mysql_error()); while ($photos=mysql_fetch_array($get_photos)) {?> <table class="columntable" style="border:3px solid #EBEBEB;"> <tr> <td rowspan="4">Caption:</td> <td rowspan="4"><textarea name="details[<?php echo $photos['image_id'];?>]" cols="30" rows="5" id="details[]"><?php echo $photos['details']; ?></textarea></td> <td style="padding-top:5px;"><div class="thumbNew"> <div align="center"><a class="info" href="../user_images/<?php echo $photos['image_name'];?>"> <img src="../user_images/<?php echo $photos['image_name'];?>" height="90" width="145" alt="<?php echo $photos['image_name'];?>" /></a> </p> </div> </div> </td> </tr> <tr> <td class="tableTopBorder"><input name="album_cover" type="radio" value="<?php echo $photos['image_name'];?>" checked="<?php echo $checked;?>" /> This is the album cover.</td> </tr> <tr> <td class="tableMiddleBorder"><input name="delete[<?php echo $photos['image_id'];?>]" type="checkbox" id="delete[<?php echo $photos['image_id'];?>]" value=" checkbox" /> Delete this Photo </td> </tr> <tr> <td class="tableBottomBorder" style="padding-bottom:5px;">Move to: <select name="album[<?php echo $photos['image_id'];?>]" id="albums[]"> <option selected="selected"></option> <?php $query_get_names = "select * from image_files WHERE user_id = '$user_id' GROUP BY `album`"; if ($result = mysql_query($query_get_names)) { if (mysql_num_rows($result)) { while($names = mysql_fetch_assoc($result)) { echo "<option 'width:75px' "; if($names['album'] == $_GET['album']){ echo " selected='selected'"; } echo"value='{$names['album']}'>{$names['album']}</option>\n"; } } } else { echo "SQL Error: $query_get_albums<br>" . mysql_error(); } ?> </select> </td> </tr> </table> <?php } }?> Link to comment https://forums.phpfreaks.com/topic/60301-select-radio-button/#findComment-299985 Share on other sites More sharing options...
proctk Posted July 17, 2007 Author Share Posted July 17, 2007 This should not be so complicating. for the query the that I'm running the two value are equal. the problem is it setting all values as checked. how do I limit to only the <?php $albumCovers=mysql_fetch_array($get_albumCovers); if($photos['image_name'] = $albumCovers['album_cover']){ $checked = "checked"; }?> <td class="tableTopBorder"><input name="album_cover" type="radio" value="<?php echo $photos['image_name'];?>" checked="<?php echo $checked;?>" /> This is the album cover.</td> Link to comment https://forums.phpfreaks.com/topic/60301-select-radio-button/#findComment-300008 Share on other sites More sharing options...
proctk Posted July 17, 2007 Author Share Posted July 17, 2007 I think this needs to be done with a foreach, I'm struggling on how to get this to work any help is excellent Link to comment https://forums.phpfreaks.com/topic/60301-select-radio-button/#findComment-300022 Share on other sites More sharing options...
jd2007 Posted July 17, 2007 Share Posted July 17, 2007 i don't get it...do u get error messages ? the first error i got was u missed a closing brace before ?>...the second error was because u did not connect to the database...u should connect to the database before sending a query like this: $db=mysql_connect(host, username, password) or die(mysql_error()); mysql_select_db(database); the mysql_connect function takes three parameters: 1. the host- usually if u have stored mysql databases in your computer, this parameter will be "localhost" 2. the username - this will be ur username, i think most commonly used username is "root"..i'm not sure though 3. the password-if u have a password, this parameter will be your password... the mysql_select_db selects a mysql database and the parameter is the name of the database.... connect to the database, if u don't know how to do it, post here, or send a message to me, i am always online...then see wheter it works or not, if it still doesn't work post here, or send a message to me... Link to comment https://forums.phpfreaks.com/topic/60301-select-radio-button/#findComment-300037 Share on other sites More sharing options...
proctk Posted July 17, 2007 Author Share Posted July 17, 2007 this is works but its not returning checked for the value with the matches. any ideas why echo $albumCovers['album_cover']; foreach(array($photos['image_name']) as $value){ echo $value; echo '<td class="tableTopBorder"><input name="album_cover" type="radio" value="'.'$photos[\'image_name\']"'; if($value == $albumCovers['album_cover']){ echo 'checked="checked" />'; ?> <?php }?> This is the album cover.</td> <? }?> Link to comment https://forums.phpfreaks.com/topic/60301-select-radio-button/#findComment-300039 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.