ilikephp Posted May 10, 2010 Share Posted May 10, 2010 Hello, I have 2 forms: one that displays all my sql records and the other one search for a specific record. I want for example: if I search for "x' all the "x" be displayed and a link (in the other form) is displayed next to it in order to modify it. (I am using binding in dreamweaver) Can someone help me plz? displays all the records: <?php require_once('../../Connections/Con.php'); ?> <?php mysql_query("SET NAMES 'UTF8'"); $maxRows_Recordset1 = 10; $pageNum_Recordset1 = 0; if (isset($_GET['pageNum_Recordset1'])) { $pageNum_Recordset1 = $_GET['pageNum_Recordset1']; } $startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1; mysql_select_db($database_Con, $Con); $query_Recordset1 = "SELECT * FROM bap"; $query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1); $Recordset1 = mysql_query($query_limit_Recordset1, $bapCon) or die(mysql_error()); $row_Recordset1 = mysql_fetch_assoc($Recordset1); if (isset($_GET['totalRows_Recordset1'])) { $totalRows_Recordset1 = $_GET['totalRows_Recordset1']; } else { $all_Recordset1 = mysql_query($query_Recordset1); $totalRows_Recordset1 = mysql_num_rows($all_Recordset1); } $totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1; ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title> </title> </head> <body> <table width="800" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td><?php do { ?> <table width="800" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="249" height="104"><?php echo $row_Recordset1['child_name_12']; ?></td> <td width="246"><a href="editrecord.php?b_form_number_33=<?php echo $row_Recordset1['b_form_number_33']; ?>">edit</a></td> <td width="305"><a href="Certificate.php?b_form_number_33=<?php echo $row_Recordset1['b_form_number_33']; ?>">cert</a></td> </tr> </table> <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?></td> </tr> </table> </body> </html> <?php mysql_free_result($Recordset1); ?> Displays the record searched for only: <?php require_once('../../Connections/Con.php'); ?> <?php mysql_select_db($database_bapCon, $bapCon); $query_Recordset1 = "SELECT * FROM bap"; $Recordset1 = mysql_query($query_Recordset1, $bapCon) or die(mysql_error()); $row_Recordset1 = mysql_fetch_assoc($Recordset1); $totalRows_Recordset1 = mysql_num_rows($Recordset1); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <style type="text/css"> <!-- body { background-image: url(../images/Background44.gif); background-repeat: no-repeat; background-color: #FFFF66; } --> </style></head> <body> <h2>Search</h2> <form name="search" method="post" action=""> Seach for: <input type="text" name="find" /> in <Select NAME="field"> <Option VALUE="child_name_12">Last Name</option> <Option VALUE="lname">Last Name</option> <Option VALUE="info">Profile</option> </Select> <input type="hidden" name="searching" value="yes" /> <input type="submit" name="search" value="Search" /> </form> </body> </html> <?php mysql_free_result($Recordset1); //This is only displayed if they have submitted the form if ($_POST['searching'] =="yes") { echo "<h2>Results</h2><p>"; //If they did not enter a search term we give them an error if ($_POST['find'] == "") { echo "<p>You forgot to enter a search term"; exit; } // Otherwise we connect to our Database mysql_connect("localhost", "****", "****") or die(mysql_error()); mysql_select_db("par ") or die(mysql_error()); // Convert names to UTF8 mysql_query("SET NAMES 'UTF8'"); // We preform a bit of filtering $find = strtoupper(strip_tags(trim($_POST['find']))); //Now we search for our search term, in the field the user specified $data = mysql_query("SELECT * FROM bap WHERE upper({$_POST['field']}) LIKE'%$find%'"); //And we display the results while($result = mysql_fetch_array( $data )) { echo $result['child_name_12']; echo " "; echo $result['father_family_17']; echo " "; echo "<br>"; echo "<br>"; } //This counts the number or results - and if there wasn't any it gives them a little message explaining that $anymatches=mysql_num_rows($data); if ($anymatches == 0) { echo "Sorry, but we can not find an entry to match your query<br><br>"; } //And we remind them what they searched for echo "<b>Searched For:</b> " .$find; } ?> Link to comment https://forums.phpfreaks.com/topic/201288-merge-2-forms-together/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.