jdayes Posted February 7, 2006 Share Posted February 7, 2006 Hi I have set up a query and results page in dreamweaver using PHP and MySQL database.the is field in the table called subject. This is just a varchar field and stores different subject names seperated by commas. The data in this field is inserted from the values of checkboxes in a form. e.g. one field would containt: subject1,subject2,subject3 while another may only containt subject2,subject3on my query page. I have a list of the checkboxes each with the different subject values. When this query is submitted. the reults page should return all the relevant matches.The issue is, that if the user clicks the following checkboxes:subject1subject3I want all the rows to be returned that include either of these fields. But at the moment only rows with both subject 1 and subject 3 are returned.I cant stored the different subject types in different fields because the list of subject types is dynamically updated from another table and so addition subject types could be inserted at a later date. The checkboxes are dynamically generated from this extra table.Can anyone helpe me, I really cant find a solution on this!Code for query.php and results.php is belowKind RegardsJayAttach Code********results.php************<?php$colname_Recordset1 = "-1";if (isset($_POST['subjectname'])) { $colname_Recordset1 = (get_magic_quotes_gpc()) ? $_POST['subjectname'] : addslashes($_POST['subjectname']);}mysql_select_db($database_rcmconnect, $rcmconnect);$query_Recordset1 = sprintf("SELECT * FROM subject_insert WHERE subjectname LIKE '%%%s%%' ORDER BY subid ASC", $colname_Recordset1);$Recordset1 = mysql_query($query_Recordset1, $rcmconnect) or die(mysql_error());$row_Recordset1 = mysql_fetch_assoc($Recordset1);$totalRows_Recordset1 = mysql_num_rows($Recordset1);?><table width="80%" border="0" cellspacing="0" cellpadding="0"> <?php do { ?> <tr> <td> <?php echo $row_Recordset1['subjectname']; ?> </td> </tr> <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?></table><?phpmysql_free_result($Recordset1);?>************************************************************query.php*****************<?phpmysql_select_db($database_rcmconnect, $rcmconnect);if(is_array($_POST['subjectname']))$_POST['subjectname']=implode(",",$_POST['subjectname']);$query_Recordset1 = "SELECT subjectname FROM subjects ORDER BY subid ASC";$Recordset1 = mysql_query($query_Recordset1, $rcmconnect) or die(mysql_error());$row_Recordset1 = mysql_fetch_assoc($Recordset1);$totalRows_Recordset1 = mysql_num_rows($Recordset1);?><form action="results.php" method="post"> <table width="80%" border="0" cellspacing="0" cellpadding="0"> <?php do { ?> <tr> <td width="48%"><?php echo $row_Recordset1['subjectname']; ?></td> <td width="52%"><label> <input type="checkbox" name="subjectname" id="subjectname" value="<?php echo $row_Recordset1['subjectname']; ?>"> </label></td> </tr> <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?> <tr><td><label> <input type="submit" name="Submit" value="Submit"> </label></td> </tr> </table> </form><?phpmysql_free_result($Recordset1);?>******************************************** Quote Link to comment https://forums.phpfreaks.com/topic/3346-query-help/ 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.