Digital Eyes Posted February 15, 2010 Share Posted February 15, 2010 Hello to you all First time here in PHP Freaks and i have found lots of good things here but not quite what i need. Lets see if i can explain my problem. I am running Client Version mysql 5.1.37 on a Mac with MAMP I Have a Database of ships. The table is basic with routes, dates, port and ship which i have names Test | Test | CREATE TABLE `Test` ( `ID` int(3) NOT NULL AUTO_INCREMENT, `Date` varchar(30) NOT NULL, `Route` varchar(30) NOT NULL, `Ship` varchar(30) NOT NULL, `Port` varchar(30) NOT NULL, PRIMARY KEY (`ID`) ) ENGINE=MyISAM AUTO_INCREMENT=46 DEFAULT CHARSET=latin1 DATA DIRECTORY='./Ships/' INDEX DIRECTORY='./Ships/' | What i am trying to do is from a form with checkboxes allow uses to select a ship and see all the entries in the database for that vessel / vessels. (depending on how many checkboxes are selected. I have it working for a single selection made in the checkboxes, but am unable to get any results if i select both checkboxes. the code i have in html and php is pasted below. i am sure it i something very easy but as i have been looking at it for a few days now without success i would appreiciate a little help if possible in the right direction to be going here. so here is my form test.html <form name="form1" method="post" action="action.php"> <label> <input type="checkbox" name="Ship[]" value="Golden Dolphin"> Golden Dolphin</label> <br> <label> <input type="checkbox" name="Ship[]" value="Golden Dolphin II"> Golden Dolphin II</label> </p><br /><br /> <label> <input type="submit" name="Submit" id="Submit" value="Submit"></label> </form> and here is the code i have till now in action.php <?php require_once('Connections/mysite.php'); ?> <?php $all_value_check = implode(", ", $_POST['Ship']); mysql_select_db($database_mysite, $mysite); $query_Ship = "SELECT Date, Route, Ship, Port FROM Test Where Ship = '{$all_value_check}'"; $result = mysql_query($query_Ship, $mysite) or die(mysql_error()); $row_Ship = mysql_fetch_assoc($result); $totalRows_Ship = mysql_num_rows($result); ?> <?php do { ?> <table width="100%" border="1" align="center" bordercolor="#FF9933" cellspacing="2"> <tr> <td align="center" width="19%"><?php echo $row_Ship['Date']; ?></td> <td align="center" width="33%"><?php echo $row_Ship['Route']; ?></td> <td align="center" width="28%"><?php echo $row_Ship['Ship']; ?></td> <td align="center" width="20%"><?php echo $row_Ship['Port']; ?></td> </tr> </table> <?php } while ($row_Ship = mysql_fetch_assoc($result)); ?> <?php mysql_free_result($result); ?> I am sure it is something very simple and i will kick myself later. Thanks for any help :-0)) Quote Link to comment https://forums.phpfreaks.com/topic/192139-mysql-query-not-displaying-all-results/ Share on other sites More sharing options...
MadTechie Posted February 15, 2010 Share Posted February 15, 2010 For multiple entries change $all_value_check = implode(", ", $_POST['Ship']); mysql_select_db($database_mysite, $mysite); $query_Ship = "SELECT Date, Route, Ship, Port FROM Test Where Ship = '{$all_value_check}'"; to $all_value_check = implode("','", $_POST['Ship']); mysql_select_db($database_mysite, $mysite); $query_Ship = "SELECT Date, Route, Ship, Port FROM Test Where Ship IN ('{$all_value_check}') "; Anyone want to chat about SQL Injection ? Quote Link to comment https://forums.phpfreaks.com/topic/192139-mysql-query-not-displaying-all-results/#findComment-1012601 Share on other sites More sharing options...
Digital Eyes Posted February 15, 2010 Author Share Posted February 15, 2010 Hi MadTechie Thanks for the quick reply and solution to my problem. Works perfectly now. :-0) Back to the books i guess;-0) Quote Link to comment https://forums.phpfreaks.com/topic/192139-mysql-query-not-displaying-all-results/#findComment-1012626 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.