PHP - Filter Results In A Table.
My db is called localDB, and the table in that db is called MonthlySales. I want to display the table in a table in php. But to be able to filter the table by the column year, so if 2000 is selected only the values with 2000 are shown. Is there also a better way to populate the drop down menu?
My script looks like: Code: [Select] <form action='<?php echo $_SERVER['PHP_SELF']; ?>' method='post' name='form_filter' > <select name="value"> <option value="all">All</option> <option value="2000">2000</option> <option value="2001">2001</option> </select> <input type='submit' value = 'Filter'> </form> <?php $link = mysql_connect('localhost', 'root', 'root'); if (!$link) { die('Could not connect: ' . mysql_error()); } $db_selected = mysql_select_db('localDB', $link); if (!$db_selected) { die (mysql_error()); } // process form when posted if(isset($_POST['value'])) { if($_POST['value'] == '2000') { $query = "SELECT * FROM MonthlySales WHERE Year='2000'"; } elseif($_POST['value'] == '2001') { $query = "SELECT * FROM MonthlySales WHERE Year='2001'"; } else { $query = "SELECT * FROM MonthlySales"; } $sql = mysql_query($query); while ($row = mysql_fetch_array($query)) { $Id = $row["Id"]; $ProductCode = $row["ProductCode"]; $Month = $row["Month"]; $Year = $row["Year"]; $SalesVolume = $row["SalesVolume"]; echo "<tr>"; echo "<td>" . $row['Id'] . "</td>"; echo "<td>" . $row['ProductCode'] . "</td>"; echo "<td>" . $row['Month'] . "</td>"; echo "<td>" . $row['Year'] . "</td>"; echo "<td>" . $row['SalesVoulme'] . "</td>"; echo "</tr>"; } mysql_close($con); } ?> Similar TutorialsHey guys I am having a bit of a hard time understanding how I can fetch data from my SQL table using AJAX and jQuery, I am sorry if this isn't the right place to post this however I usually get great support here.
I am trying to recreate this filter on the right of the page: http://www.autotrade...arch/used/cars/
So basically I have this code to display the whole MySQL table into a list:
<?php while($row = $results->fetch(PDO::FETCH_ASSOC)) { echo ' <div class="listing-container"> <h3 class="model-listing-title clearfix">'.$row["Make"].' '.$row["Model"].' '.$row["Variant"].'</h3> <h3 class="price-listing">£'.number_format($row['Price']).'</h3> </div> <div class="listing-container-spec"> <img src="'.(explode(',', $row["PictureRefs"])[0]).'" class="stock-img-finder"/> <div class="ul-listing-container"> <ul class="overwrite-btstrp-ul"> <li class="diesel-svg list-svg">'.$row["FuelType"].'</li> <li class="saloon-svg list-svg">'.$row["Bodytype"].'</li> <li class="gear-svg list-svg">'.$row["Transmission"].'</li> <li class="color-svg list-svg">'.$row["Colour"].'</li> </ul> </div> <ul class="overwrite-btstrp-ul other-specs-ul h4-style"> <li>Mileage: '.number_format($row["Mileage"]).'</li> <li>Engine size: '.$row["EngineSize"].'cc</li> </ul> <button href="#" class="btn h4-style checked-btn hover-listing-btn"><span class="glyphicon glyphicon-ok"></span> History checked </button> <button href="#" class="btn h4-style more-details-btn hover-listing-btn tst-mre-btn"><span class="glyphicon glyphicon-list"></span> More details </button> <button href="#" class="btn h4-style test-drive-btn hover-listing-btn tst-mre-btn"><span class="test-drive-glyph"></span> Test drive </button> <h4 class="h4-style listing-photos-count"><span class="glyphicon glyphicon-camera"></span> 5 More photos</h4> </div> '; } ?>As you can see I am using a while loop to display the whole contents of the table into lists, this includes vehicle data. I also have this bit of HTML that I will be using as a form to filter the results: <form class="car-finder-container dflt-container"> <h2 class="h2-finder">Car finder</h2> <ul class="toggle-view"> <li class="li-toggle"> <h4 class="h4-finder-toggle">Make<span class="glyphicon glyphicon-plus glyph-plus-toggle"></span></h4> <div class="panel"> <select class="form-control select-box"> <option value="make-any">Make (Any)</option> <option value="two">Two</option> <option value="three">Three</option> <option value="four">Four</option> <option value="five">Five</option> </select> <select class="form-control last-select select-box"> <option value="model-any">Model (Any)</option> <option value="two">Two</option> <option value="three">Three</option> <option value="four">Four</option> <option value="five">Five</option> </select> </div> </li> <li class="li-toggle"> <h4 class="h4-finder-toggle">Body type<span class="glyphicon glyphicon-plus glyph-plus-toggle"></span></h4> <div class="panel"> <input id="four-by-four-checkbox" class="float-checkbox" type="checkbox"/> <label for="four-by-four-checkbox" class="label-checkbox">4x4</label> <input id="convertible-checkbox" class="float-checkbox" type="checkbox"/> <label for="convertible-checkbox" class="label-checkbox">Convertible</label> <input id="coupe-checkbox" class="float-checkbox" type="checkbox"/> <label for="coupe-checkbox" class="label-checkbox">Coupe</label> </div> </li> <li class="li-toggle"> <h4 class="h4-finder-toggle">Transmission<span class="glyphicon glyphicon-plus glyph-plus-toggle"></span></h4> <div class="panel"> <input id="automatic-checkbox" class="float-checkbox" type="checkbox"/> <label for="automatic-checkbox" class="label-checkbox">Automatic</label> <input id="manual-checkbox" class="float-checkbox" type="checkbox"/> <label for="manual-checkbox" class="label-checkbox">Manual</label> <input id="semi-auto-checkbox" class="float-checkbox" type="checkbox"/> <label for="semi-auto-checkbox" class="label-checkbox">Semi automatic</label> </div> </li> </ul> <button href="#" class="btn btn-block car-search-button btn-lg btn-success"><span class="glyphicon car-search-g glyphicon-search"></span> Search cars </button> <h4 class="h4-finder"><a href="#">Try our Smart Search </a><span class="glyphicon info-car-search-g glyphicon-info-sign"></span></h4> </form>I have noticed that JS and Ajax give a great user experience when it comes to filtering search results, in this HTML template I have added some select elements and check boxes and I am now really stuck. Does anybody know how I can make exceptions to what SQL results are returned to the front end or know of any tutorials? Thanks hi, I have a search page with a checkbox $departuk that returns the value "true" if checked. I want to return search results if this returns true and the flag 'Y' is available if ($departuk == "true"){ if ($data[$i]['departuk'] == 'Y'){ $result = $obj->result; } else{ echo "do some thing else"; } else{ echo"there was a problem"; } any pointers / advice is appreciated thanks Here is my HTML code: Code: [Select] <html> <head> <title>Simple Search Form</title> </head> <body> <form name="searchform" method="get" action="/search.php"> Select Gender: <select name="gender"> <option value="Male">Male</option> <option value="Female">Female</option> </select> Select City: <select name="gender"> <option value="all">All Cities</option> <option value="newyork">New York</option> <option value="toronto">Toronto</option> <option value="london">London</option> <option value="paris">Paris</option> </select> <form> </body> </html> Here is my PHP code: <?php // get the data from the search form # get the gender (male or female) $gender = $_GET['gender']; # get the city $city = $_GET['city']; // connect to mysql and select db mysql_connect('localhost', 'root', 'pass') or die(mysql_error()); mysql_select_db($test_db); // send query $query = mysql_query("SELECT * FROM `visitors_location` WHERE gender='$gender' AND city='$city'"); $count = mysql_num_rows($query); // display data while ( $show = mysql_fetch_assoc($query) ) { echo $gender . " " . $city; } ?> My script basically shows # of males or females in a specific city. How can I show all males in all cities? In other words, let's say I want to show # of Females from all those 4 cities combined. I don't know how to do that. Can someone please help me? Hi there I have a DB of design work all the work is categorise as Brand Identity, print or online Some are a mix so project 1 is categorised as brand identity and online Project 2 is print and online Im trying to filter my results by using checkbox so when brand identity and online are checked and the filter button is clicked there val is sent to the display page, i am passing the val ok as i get this in the url bar (index1.php?cid=bi&cid2=online) but is not displaying only entry's with cat brand identity and online. its not displaying any thing but error msg In my DB I have 3 columns cid, cid1, cid2. cid= bi cid1= print cid2= online I have 2 problems if anyone can help please. 1, I get no results on the display page(index1.php) when no filter is slected ie show all i think this part needs a IF empty run this query if not empty ie filters have been passed to the page run this query ####################### i get this error There was a problem with the SQL query: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '''' at line 1 ####################### 2, I cant get the filters to filter so no display again (cant seam to get the sql select command to work right and fetch the results i need i just get the above error Thank you for any help im still noobish but getting there slowly very slowly lol Anymore info needed let me know nav code (iv used method get to see what is being passed to index1.php the display page) Code: [Select] <form id="form1" name="filter" method="get" action="index1.php"> <ul> <li><a href="/work/"title="Show All"<?php if ($_SESSION['section'] == 'all') { echo "class=\"selected\""; }?>>Show All</a></li> <li>Brand Identity <input name="cid" type="checkbox" value="bi" /></li> <li> Print <input name="cid1" type="checkbox" value="print" /></li> <li>Online<input name="cid2" type="checkbox" value="online" /></li> </ul> <input type="submit" name="" id="filter" value="Filter" /> </form> display page code Code: [Select] <?php error_reporting(E_ALL); include ("includes/db_config.php"); mysql_connect($db_hostname,$db_username,$db_password); @mysql_select_db($db_database) or die( "Unable to select database"); $cid= $_GET['cid']; $cid1= $_GET['cid1']; $cid2 = $_GET['cid2']; $query="SELECT * from `$db_table` WHERE `cid`='".$cid."' or `cid1`='".$cid1."' or `cid2`'".$cid2."'"; $result = mysql_query($query) or die("There was a problem with the SQL query: " . mysql_error()); if($result && mysql_num_rows($result) > 0) { $i = 0; $max_columns = 4; while($row = mysql_fetch_array($result)) { extract($row); if($i == 0) echo "<tr>"; if($pro_name != "" && $pro_name != null) echo "<td class=\"results\"><a href=\"details.php?id=$row[id]\"><img src=\"/work/thumbnails/$row[thumbnail]\" alt=\"$row[thumbnail]\" height=\"155\" width=\"155\" /><br><h2>$row[pro_name]<br></a></h2><p>$row[short_details]</p></td>"; if(++$i == $max_columns) { echo "</tr>"; $i=0; } } } if($i > 0){ for($j=$i; $j<$max_columns;$j++) echo "<td> </td>"; echo '</tr>';} ?></table></td> </tr> </table> hello. i have a search box that will display some results. I also have a drop down list with values "1" and "2". the values for each results are stored into database in a "req" field. Code: [Select] <select name="req" id="req"> <option value="1">yes</option> <option value="2">no</option> </select> $sql = 'SELECT * FROM topic WHERE (Title LIKE '."'%$search1%') AND req='1' what am i missing. thanks Hi there i have 3 tables joined together and am outputting the results ok. Heres what the results look like: Fleet Name: Home One Detected: No Ship Name: Slave 1 Bobafett Hull: 3 / 2 Fleet Name: Home Two Detected: Yes Ship Name: Imperial Star Destroyer Hull: 2 / 4 Fleet Name: Home Two Detected: Yes Ship Name: Executer Hull: 10 / 10 The 3 tables join together by the following: Planet = parsed url parameter Fleets = fleets on the current planet Ships = current ships in the fleets Its all working fine except for one thing, the Fleet Name is repeated for each occurance of a ship. I want to make it so that Fleet Name only occurs once for each fleet so it would look something like: Fleet Name: Home One Detected: No Ship Name: Slave 1 Bobafett Hull: 3 / 2 Fleet Name: Home Two Ship Name: Imperial Star Destroyer Detected: Yes Hull: 2 / 4 Ship Name: Executer Detected: Yes Hull: 10 / 10 Is this possible??? Heres the code in full: Code: [Select] <?php require_once('Connections/swb.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $colname_Planet = "-1"; if (isset($_GET['recordID'])) { $colname_Planet = (get_magic_quotes_gpc()) ? $_GET['recordID'] : addslashes($_GET['recordID']); } mysql_select_db($database_swb, $swb); $query_Planet = sprintf("SELECT * FROM planet WHERE PlanetName = %s", GetSQLValueString($colname_Planet, "text")); $Planet = mysql_query($query_Planet, $swb) or die(mysql_error()); $row_Planet = mysql_fetch_assoc($Planet); $totalRows_Planet = mysql_num_rows($Planet); $colname_Fleet = "-1"; if (isset($_GET['recordID'])) { $colname_Fleet = (get_magic_quotes_gpc()) ? $_GET['recordID'] : addslashes($_GET['recordID']); } mysql_select_db($database_swb, $swb); $query_Fleet = sprintf("SELECT p.PlanetName, p.PlayerName, f.FleetName, f.Detected, s.ShipName, s.HealthA, s.HealthB FROM Planet p LEFT JOIN Fleet f ON (p.PlanetName = f.PlanetName) LEFT JOIN Ships s ON (f.FleetName = s.FleetName) WHERE p.PlanetName = '$colname_Planet'"); $Fleet = mysql_query($query_Fleet, $swb) or die(mysql_error()); $row_Fleet = mysql_fetch_assoc($Fleet); $totalRows_Fleet = mysql_num_rows($Fleet); ?> <head> <title>Untitled Document</title> <style type="text/css"> <!-- body { background-color: #FFFFFF; } --> </style></head> <body> <table width="60%" border="0"> <tr> <td width="10%">Planet:</td> <td width="14%"><?php echo $row_Planet['PlanetName']; ?></td> <td width="7%" rowspan="8"> </td> <td colspan="2" rowspan="8"> <?php while ($row_Fleet = mysql_fetch_assoc($Fleet)) { echo '<table width="400" border="0"><tr><td width="200">'; echo 'Fleet Name: '; echo'</td><td>'; echo $row_Fleet['FleetName']; echo'</td></tr><tr><td>'; echo 'Detected: '; echo'</td><td>'; if ($row_Fleet['Detected'] == '1'){ echo 'Yes';} else echo 'No'; echo'</td></tr><tr><td>'; echo 'Ship Name: '; echo'</td>'; echo'<td>'; echo $row_Fleet['ShipName']; echo'</td></tr><tr><td>'; echo 'Hull: '; echo'</td><td>'; echo $row_Fleet['HealthA']; echo ' / '; echo $row_Fleet['HealthB']; echo '</td></tr><tr><td></td></tr>'; echo'</table>'; } ?> <tr> <td>Faction:</td> <td><?php echo $row_Planet['PlayerName']; ?></td> </tr> <tr> <td>Infastructure</td> <td> </td> </tr> <tr> <td>Class 1: </td> <td><?php echo $row_Planet['Class1']; ?></td> <tr> <td>Class 2: </td> <td><?php echo $row_Planet['Class2']; ?></td> </tr> <tr> <td>Class 3: </td> <td><?php echo $row_Planet['Class3']; ?></td> </tr> <tr> <td>Class 4: </td> <td><?php echo $row_Planet['Class4']; ?></td> </tr> <tr> <td> </td> <td> </td> </tr> <tr> <td> <a href="index.php target="main2.php"">Back</a></td> <td> </td> <td> </td> <td width="43%"> </td> <td width="26%"> </td> </tr> </table> </body> </html> <?php mysql_free_result($Planet); mysql_free_result($Fleet); ?> Thanks Hi, I'm currently learning PHP through tutorials and I am working on a webpage that filters statistics (crime records) from an SQL table and filters them by an option of years that the user has picked from a dropdown box. $desiredyear = $_POST['year'] is the year picked from the drop down box on a different page. I did not encounter any problems simply displaying the entire table until I tried to filter the crimes by year. I keep getting this error message. Warning: sqlsrv_fetch_array() expects parameter 1 to be resource, boolean given in C:\RDEUsers\NET\400792\1.php on line 40 Here is the error line. Code: [Select] while($row = sqlsrv_fetch_array($results, SQLSRV_FETCH_ASSOC)) And here is my code so far Code: [Select] <?php $server = 'SQL2008'; $connectionInfo = array( "Database"=>"rde_400792"); $conn = sqlsrv_connect($server,$connectionInfo); $desiredyear = $_POST['year']; $describeQuery='select year, force, homicide from crime where year = $desiredyear '; $results = sqlsrv_query($conn, $describeQuery); echo '<table border="1" BORDERCOLOR=Black>'; echo '<tr><th bgcolor = "LightBlue">Year</th><th bgcolor = "LightBlue" >Force</th><th bgcolor = "LightBlue">Homicide</th></tr>'; while($row = sqlsrv_fetch_array($results, SQLSRV_FETCH_ASSOC)) { echo '<tr>'; echo '<td >' .$row['year'].'</td>'; echo '<td>' .$row['force'].'</td>'; echo '<td>' .$row['homicide'].'</td>'; echo '</tr>'; } echo '</table>'; sqlsrv_close($conn); Please can somebody help me fix this? It's driving me mad and I've exhausted my limited knowledge on the subject. I just don't understand what I'm doing wrong. I am in the middle of a project on my own website and want to add a filter on it, the results are displayed in a HTML table and are pulled in from a mysql database using php and want to add a text filter on the site. I want the filter to work by clicking on a status text link such as open, pending or closed and it filters the results that match that on the same page for that relevant text value. I was not sure if it's more a php question or if can be done with ajax/javascript This topic has been blindfolded and driven across the boarder to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=344623.0 (That was a pun, not a typo.) I'm ready for the next step on my site, which is learning how to filter results down with a second search. The scenario is: A viewer searches for a plant by 4 variables to describe the leaf. After submit, they go to the results page, with 200 paginated results. (This is where I've gotten to) Now, on that same page, they choose to further narrow their results by searching those 200 results for plants that have purple flowers. Maybe they get 40 results and can use another variable to narrow further - and so on. What's the best way to set this up? I've been looking into temporary tables, but it seems to be a challenge because the table deletes the moment they leave that page or close the connection? Sessions seem like another possibility, but I read there's security issues. What's the best way to set this up? Just re-query the database with the entire set of variables from both the first and second searches? is it quicker to build some type of permanent table with a timestamp that I can use to delete it after the user has gone away? I am trying to create a dynamic table that gets generated based upon users selection of last name (via a select menu) as well as the ability to filter all the table contents between two ages. Additionally, I would like the ability to select all last names between two ages as well. Each item I would hope to have a onchange command. Thanks in advance for any help on the above items. Here is the main php code <?php $con = mysql_connect('localhost', 'root', ''); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("test", $con); $lastname_result = mysql_query("SELECT lastname FROM user GROUP BY lastname"); $result = mysql_query("SELECT * FROM user"); ?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <link href="../themes/style.css" rel="stylesheet" type="text/css" media="print, projection, screen" /></link> <link href="../common.css" rel="stylesheet" type="text/css"></link> </head> <body> <table width="100%" border="0" cellspacing="0" cellpadding="5" class="main"> <tr> <td width="160" valign="top"></td> <td width="732" valign="top"> <table width="90%" border="0" align="center"> <form action="test3.php" method="post"> <select name="area" onchange="submit"> <option value="">Select an lastname</option> <option value=""></option> <?php while(list($lastname)=mysql_fetch_array($lastname_result)) { echo "<option value='$lastname'>$lastname</option>"; }?> </select> <label for="startage">From</label> <input type="text" id="from" name="from"/> <label for="endage">to</label> <input type="text" id="to" name="to"/> <input type="submit" name="Submit" value="Refresh" /> </form> </table> <table id="tablesorter" class="tablesorter" border="0" cellpadding="0" cellspacing="1"> <thead> <tr> <th>First Name</th> <th>Last Name</th> <th>Age</th> <th>Hometown</th> <th>Job</th> </tr> </thead> <tbody> <?php while($row=mysql_fetch_assoc($result)){ ?> <tr> <td><?php echo $row['firstname']; ?></td> <td><?php echo $row['lastname']; ?></td> <td><?php echo $row['age']; ?></td> <td><?php echo $row['hometown']; ?></td> <td><?php echo $row['job']; ?></td> </tr> <?php } // End while loop. ?> </tbody> </table> <p> </p> <p> </p> <p align="right"> </p></td> <td width="196" valign="top"> </td> </tr> </table> </body> </html> and here is the sql code to generate a test database. Code: [Select] CREATE DATABASE /*!32312 IF NOT EXISTS*/`test` /*!40100 DEFAULT CHARACTER SET latin1 */; DROP TABLE IF EXISTS `user`; CREATE TABLE `user` ( `id` int(11) NOT NULL AUTO_INCREMENT, `firstname` varchar(20) NOT NULL, `lastname` varchar(20) NOT NULL, `age` int(3) NOT NULL, `hometown` varchar(25) NOT NULL, `job` varchar(25) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM AUTO_INCREMENT=7 DEFAULT CHARSET=latin1; /*Data for the table `user` */ insert into `user`(`id`,`firstname`,`lastname`,`age`,`hometown`,`job`) values (1,'Peter','Griffin',41,'Quahog','Brewery'), (2,'Lois','Griffin',40,'Newport','Piano Teacher'), (3,'Joseph','Swanson',39,'Quahog','Police Officer'), (4,'Glenn','Quagmire',41,'Quahog','Pilot'), (5,'Megan','Griffin',16,'Quahog','Student'), (6,'Stewie','Griffin',2,'Quahog','Dictator'); I am trying to create a dynamic table that gets generated based upon users birthday, then selection of last name (via a select menu), then first name (via a select menu), Each selection would subsequently filter out items not chosen. i.e. if the last name of Griffin were selected, only those with the last name Griffin would be present when selecting the first name. I have been able to generate the birthday and then last name selection, but I am unclear of how to add the first name into the mix (and any other subsequent filters thereafter) Here is what I as so far. Any help would be appreciated. database sql code: Code: [Select] CREATE TABLE `user` ( `id` int(11) NOT NULL AUTO_INCREMENT, `firstname` varchar(20) NOT NULL, `lastname` enum('Griffin','Griffin6','Quagmire','Swanson') NOT NULL, `age` int(11) NOT NULL, `hometown` varchar(25) NOT NULL, `job` varchar(25) NOT NULL, `birthdate` date NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM AUTO_INCREMENT=7 DEFAULT CHARSET=latin1; /*Data for the table `user` */ insert into `user`(`id`,`firstname`,`lastname`,`age`,`hometown`,`job`,`birthdate`) values (1,'Peter','Griffin',41,'Quahog','Brewery','1960-01-01'), (2,'Lois','Griffin',40,'Newport','Piano Teacher','1961-08-11'), (3,'Joseph','Swanson',39,'Quahog','Police Officer','1962-07-23'), (4,'Glenn','Quagmire',41,'Quahog','Pilot','1960-02-28'), (5,'Megan','Griffin',16,'Quahog','Student','1984-04-24'), (6,'Stewie','Griffin',2,'Quahog','Dictator','2008-03-03'); index.php: <?php include('config.php'); //Include the database connections in it's own file, for easy integration in multiple pages. $lastname_result = mysql_query("SELECT lastname FROM user GROUP BY lastname"); $result = mysql_query("SELECT * FROM user"); ?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <link href="start/jquery-ui-1.8.4.custom.css" rel="stylesheet" type="text/css"/></link> <link href="../themes/style.css" rel="stylesheet" type="text/css" media="print, projection, screen" /></link> <link href="../common.css" rel="stylesheet" type="text/css"></link> <script type="text/javascript" src="jquery-1.4.2.min.js"></script> <script type="text/javascript" src="jquery.tablesorter.js"></script> <script type="text/javascript" src="jquery-ui-1.8.4.custom.min.js"></script> <script type="text/javascript"> $(document).ready(function() { $("#myTable").tablesorter({widgets: ['zebra']}); $("#options").tablesorter({sortList: [[0,0]], headers: { 3:{sorter: false}, 4:{sorter: false}}}); } ); function reSort(par) { $("#tableBody").empty(); var vfrom = document.getElementById('from').value; var vto = document.getElementById('to').value; $.get('table.list.php?from='+vfrom+'&to='+vto+'&lastname='+par,function(html) { // append the "ajax'd" data to the table body $("#tableBody").append(html); // let the plugin know that we made a update $("#myTable").trigger("update"); // set sorting column and direction, this will sort on the first and third column var sorting = [[0,0]]; // sort on the first column $("#myTable").trigger("sorton",[sorting]); }); } </script> </head> <body> <table width="100%" border="0" cellspacing="0" cellpadding="5" class="main"> <tr> <td width="160" valign="top"></td> <td width="732" valign="top"> <table width="90%" border="0" align="center"> <form method="post"> <label for="from">From</label> <input type="text" id="from" name="from"/> <label for="to">to</label> <input type="text" id="to" name="to"/> <?php //added javascript function call to function located in "ajax.js" ?> <select id="selectbox" name="area" onchange="reSort(this.value);"> <?php //added javascript function call to function located in "ajax.js", and changed the id for content change via javascript. ?> <option value="">Select an lastname</option> <option value=""></option> <?php while(list($lastname)=mysql_fetch_array($lastname_result)) { echo "<option value='$lastname'>$lastname</option>"; } ?> </select> </form> </table> <table id="myTable" class="tablesorter" border="0" cellpadding="5" cellspacing="1"> <thead> <tr> <th>First Name</th> <th>Last Name</th> <th>Age</th> <th>Birthday</th> <th>Hometown</th> <th>Job</th> </tr> </thead> <tbody id="tableBody"> <?php //added id to the tbody so we could change the content via javascript ?> </tbody> </table> <p> </p> <p> </p> <p align="right"> </p> </td> <td width="196" valign="top"> </td> </tr> </table> </body> </html> table.list.php: <?php include('config.php'); //database connection. if(!isset($_GET['lastname'])) { //if the proper get parameter is not there, redirect to google. header('Location: http://google.com'); exit(); } $lastname = preg_replace('~[^A-Za-z]+~','',$_GET['lastname']); //strip out anything but alpha for the name. $lastname = trim($lastname); //trim the name from all whitespace. if($lastname != '') { //check against an empty string. could have just used "empty()". $where = ' WHERE lastname = \'' . $lastname . '\''; //write the where clause. } else { //if lastname is empty, the where clause will be to, and it will return all names. $where = NULL; unset($lastname); } $from = (isset($_GET['from'])) ? date('Y-m-d',strtotime($_GET['from'])) : NULL; $to = (isset($_GET['to'])) ? date('Y-m-d',strtotime($_GET['to'])) : NULL; if($from != NULL && $to != NULL) { $where .= (isset($lastname)) ? ' AND ' : ' WHERE '; $where .= " birthdate BETWEEN '$from' AND '$to'"; } elseif($from != NULL) { $where .= (isset($lastname)) ? ' AND ' : ' WHERE '; $where .= " birthdate >= '$from'"; } elseif($to != NULL) { $where .= (isset($lastname)) ? ' AND ' : ' WHERE '; $where .= " birthdate <= '$to'"; } $query = "SELECT * FROM user $where"; $result = mysql_query($query); //get the database result. while($row=mysql_fetch_assoc($result)){ //loop and display data. ?> <tr> <td><?php echo $row['firstname']; ?></td> <td><?php echo $row['lastname']; ?></td> <td><?php echo $row['age']; ?></td> <td><?php echo $row['birthdate']; ?></td> <td><?php echo $row['hometown']; ?></td> <td><?php echo $row['job']; ?></td> </tr> <?php } // End while loop. ?> when I do a "SELECT * FROM system_disks WHERE system_id = 'aNumber'" and their is more than one result with that system_id, I get more than one result obviously. I essentially need two results in one row. I've took a screen shot of what it is doing and what I need it to do. The blurred row is a different system_id This is what the while ($row = mysql_fetch_array($query)) is currently doing: This is what I would like it to do: Sorry if this is a dumb question, I've been coding the past 48 hours and my brain is fried I have three tables: events, orderdetails & orders. First I query orderdetails to find all the records that match the EventID: $query1 = SELECT * FROM orderdetails WHERE EventID = $_SESSION['EventID']; This returns 4 records. These 4 records have a field called DetailOrderID which is the foreign key for orders.OrderID. Next I need to query the results of the first query to find all the records in the orders table that match up. For example: SELECT * from orders where $query1.DetailOrderID = orders.OrderID. How would I go about doing this? I'm head down the temporary table solution but wanted to through this one out for discussion before I invest too much time. Hi guys, I am working with an old script at the moment, there is one page which just will not populate the table results. I have tried running multiple debugging commands but the only one it flags is the line displaying Quote last; saying it's not a used function. If I comment out this line, no errors are produced but the results do not enter the table. Can anyone shed some light on this please, I've spent hours and hours and banging my head against a brick wall would probably be more constructive right now. Many thanks indeed for any help or advice. <?php mysql_connect("localhost", "$db_user","$db_upwd") or die ("Error - Could not connect: " . mysql_error()); mysql_select_db("$database"); $query="select host,count(*) from badc_mis_prog group by host"; $result = mysql_query($query) or die ("Error - Query: $query" . mysql_error()); $count=0; $hosts=array(); while ($row = mysql_fetch_array($result, MYSQL_NUM)) { $html_hlname=$row[0]; $html_hlname=preg_replace("/</","<",$html_hlname); $html_hlname=preg_replace("/>/",">",$html_hlname); array_push($hosts, $html_hlname,$row[1],0); $count++; } $query="select host,count(*) from badc_mis_prog where reported=1 group by host"; $result = mysql_query($query) or die ("Error - Query: $query" . mysql_error()); while ($row = mysql_fetch_array($result, MYSQL_NUM)) { $html_hlname=$row[0]; $html_hlname=preg_replace("/</","<",$html_hlname); $html_hlname=preg_replace("/>/",">",$html_hlname); for ($i=0; $i<($count*3); $i+=3) { if ($hosts[$i] == $html_hlname) { $hosts[($i+2)]=$row[1]; last; } } } for ($i=0 ; $i<(($count-1)*3); $i+=3){ for ($j=$i+3 ; $j<($count*3); $j+=3){ if ($hosts[($i+1)] < $hosts[($j+1)]){ $temp=array(); $temp[0]=$hosts[$i]; $temp[1]=$hosts[($i+1)]; $temp[2]=$hosts[($i+2)]; $hosts[$i]=$hosts[$j]; $hosts[($i+1)]=$hosts[($j+1)]; $hosts[($i+2)]=$hosts[($j+2)]; $hosts[$j]=$temp[0]; $hosts[($j+1)]=$temp[1]; $hosts[($j+2)]=$temp[2]; } } } print "<br><br><br><center><table border=\"1\">\n"; print "<tr><td>Host Name</td><td>Hosted</td><td>Reported</td><td>Ratio H/R</td></tr>\n"; for ($i=0; $i<($count*3); $i+=3) { if ($hosts[($i+1)]<15){ break;} printf ("<tr><td> %s </td><td> %d </td><td> %d </td><td>%.1f %%</td></tr>\n",$hosts[$i],$hosts[($i+1)],$hosts[($i+2)],(($hosts[($i+2)]/$hosts[($i+1)])*100)); } print "</table></center>\n"; ?> i think this is more of a HTML problem, but it is in my PHP code so i will ask anyway! if i have the search code: if (count($error) < 1) { $searchSQL = "SELECT id, placing, racedate, horseid FROM race WHERE "; // grab the search types. $types = array(); $types[] = isset($_GET['placing'])?"`placing` LIKE '%{$searchTermDB}%'":''; $types[] = isset($_GET['racedate'])?"`racedate` LIKE '%{$searchTermDB}%'":''; $types[] = isset($_GET['horseid'])?"`horseid` LIKE '%{$searchTermDB}%'":''; $types = array_filter($types, "removeEmpty"); // removes any item that was empty (not checked) if (count($types) < 1) $types[] = "`placing` LIKE '%{$searchTermDB}%'"; // use the body as a default search if none are checked $andOr = isset($_GET['matchall'])?'AND':'OR'; $searchSQL .= implode(" {$andOr} ", $types) . " GROUP BY `horseid` ORDER BY `racedate`"; // order by title. $searchResult = mysql_query($searchSQL) or trigger_error("There was an error.<br/>" . mysql_error() . "<br />SQL Was: {$searchSQL}"); if (mysql_num_rows($searchResult) < 1) { $error[] = "The search term provided {$searchTerms} yielded no results."; }else { $results = array(); // the result array $i = 1; echo '<table border="1"><tr><th>Num</th><th>Placing</th><th>Race Date</th><th>Horse ID</th></tr>'; while ($row = mysql_fetch_assoc($searchResult)) { echo "<tr><td>$i</td> <td>{$row['placing']}</td> <td><a href=\"viewrace.php?date=" . urlencode($row['racedate']) . "\">{$row['racedate']}</a></td> <td>{$row['horseid']}</td></tr>"; $i++; } echo '</table>'; how do i get the 'horseid' to appear at the header of the table rather than in a column? thank you for all the brilliant help this site provides!! Hi I have the following code: Code: [Select] $result = mysql_query("SELECT * FROM xbox_games order by gameid"); $row = mysql_fetch_assoc($result); $id = $row["gameid"]; $title = $row["gametitle"]; $cover = $row["cover"]; <?php echo $title;?> Which displays only the first result from my database. How can i change this to display all the results either as a list, or in a table? Thanks Hi, I'm quite new to this and I'm trying to get this to line up in a table with 3 columns (unlimited rows) I have searched and tried but I'm not having any luck. Can any one help? Thank you Code: [Select] <?php echo '<div class="resultados_sub_cat">'; foreach($this->subcats as $key => $subcat) { $subcat->link = JRoute::_('index.php?option=classcliff&view=list&catid='.$subcat->id."&Itemid=".$this->Itemid); if ($key != 0) echo ' - '; echo '<a href="'.$subcat->link.'">'.$subcat->name.'</a>'; } ?> Ive gotten some results user selcts check box on first page The php page will say which brackets it falls between example price is between 100-300 say I dont seem to be able to populate a table with the data in the database:S Code: [Select] $row_number= 0; while ($row = mysql_fetch_array($result3)) { If (($row["price"] = $price_low) && ($row["price"] <= $price_high)) //price If (($row["storage"] = $storage_low) && ($row["storage"] <= $storage_high)) //storage if (($row["Processor "] = $processor_low) && ($row["Processor"] <= $processor_high)) //Processor { $row_number++; ?> <tr> <td align="center"><?php print $row["Computer_Price"]; ?> </td> <td align="center"><?php print $row["Computer_Storage"]; ?> </td> <td align="center"><?php print $row["Computer_ProcessorSpeed"]; ?> </td> </tr> </table> Thats wat im usign atm the price_low and price_high are what sets the low and high price for the search Does anybody know how to show the below php results in a table format? <?php if(isset($_POST['submit'])){ if(isset($_GET['go'])){ $fname = $_POST['fname']; $lname = $_POST['lname']; $skill = $_POST['skill']; //connect to the database $db=mysql_connect ("127.0.0.1", "root", "") or die ('I cannot connect to the database because: ' . mysql_error()); //select the database to use $mydb=mysql_select_db("resource matrix"); //query the database table $sql="SELECT DISTINCT First_Name, Last_Name, l.Resource_ID FROM ((resource l inner join resource_skill ln on l.Resource_ID = ln.Resource_ID) inner join skill n on ln.Skill_ID = n.Skill_ID) WHERE First_Name LIKE '$fname' OR Last_Name LIKE '$lname' OR Skill_Name LIKE '$skill'"; //run the query against the mysql query function $result=mysql_query($sql); //create while loop and loop through result set while($row=mysql_fetch_array($result)){ $First_Name =$row['First_Name']; $Last_Name=$row['Last_Name']; $Resource_ID=$row['Resource_ID']; //display the result of the array echo "<ul>\n"; echo "<li>" . "<a href=\"a.php?id=$Resource_ID\">" .$First_Name . " " . $Last_Name . "</a></li>\n"; echo "</ul>"; } } else{ echo "<p>Please enter a search query</p>"; } } |