busnut Posted February 23, 2009 Share Posted February 23, 2009 G'day all, leading on from my project that i'm currently working on with my enthusiast website, i've recently created a 'history' field to record changes when they occur thanks to a fellow board member with concat feature. Now that it works brilliantly, I now need help if this is possible to display information based on the users input of the date. So how the history file records the information is it displays "MMM YYYY: information of change\n" for each bus So as time passes, the history for each bus will be several lines or more like this: Jan 2009: Delivered Feb 2009: Transferred Mar 2009: Withdrawn So what i'm looking for is somebody searches changes made to say 'Feb 2009', and I want the script to find any buses with history to 'Feb 2009', and only display that line of text of changes listed for that month for that bus for every bus in the database, rather than just showing a list of numbers and changes made over a period of time for that bus. So is this possible, because I am honest, I have absolutely no clue as to how to get the php/mysql to display the row of inforamtion. I can get it to show the bus #'s, but thats as far as i've gotten which is this code below. So pretty much I want it to show if i searched for Feb 2009: bus1 - Feb 2009: Delivered bus3 - Feb 2009: Delivered bus4 - Feb 2009: Delivered Any help will be greatly appreciated like usual! <b>Bus History</b><hr> <form name="search" method="GET" action="" style="text-align: center;"> Display changes for what date (mmm yyyy): <input type="text" name="find" /> <input type="hidden" name="searching" value="yes" /> <input type="submit" name="search" value="Search" /> </form> <? include("dbconnectionfile"); //This is only displayed if they have submitted the form if ($searching =="yes") { //If they did not enter a search term we give them an error if ($find == "") { echo "<p>You forgot to enter a search term"; exit; } // Otherwise we connect to our Database mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$dbase")or die("cannot select DB"); // We preform a bit of filtering $find = strtoupper($find); $find = strip_tags($find); $find = trim ($find); //Now we search for our search term, in the field the user specified $data = mysql_query("SELECT * FROM buses WHERE history LIKE'%$find%' ORDER BY busno + 0 ASC, active DESC") or die (mysql_error()); $rows = mysql_num_rows($data); echo $rows . " record/s found"; echo " <table border='1' cellspacing='1' cellpadding='0' width=100% style='border-collapse: collapse' bordercolor='#C0C0C0'> <tr> <th>Bus</th> <th>Chassis / Body</th> </tr> "; //And we display the results while($result = mysql_fetch_array( $data )) { if ($result['active'] == "Y") $bgc="#FFFFFF"; else $bgc="#FFCCBB"; echo "<tr><td bgcolor='$bgc'>"; echo $result['busno']; echo "</td><td bgcolor='$bgc'>"; echo $result['chassisbody']; echo "</td></tr>"; } echo "</table>"; //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>"; } } ?> Link to comment https://forums.phpfreaks.com/topic/146482-display-selected-information/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.