Jump to content

MYSQL Query not displaying all results


Digital Eyes

Recommended Posts

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)) :D

 

Link to comment
Share on other sites

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 ?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.