Forum Moderators: coopster

Message Too Old, No Replies

need to search by more than one id in same colomn

I am using a from to pass via a GET multiple id to be looked up in the one

         

davidrtantive15

11:00 pm on Mar 5, 2008 (gmt 0)

10+ Year Member



I am new to php and am having trouble getting this to work.
I have two DB's
1. names
2. results

I am running a text search that returns all the data from names that mathces. I then want to use check boxes on that result page to pass all the name matches to results database and display the results. I think something like this has been mentioned on here before.

Here is some code for you all!

Results of first text based search

<?php
//Connection statement
require_once('Connections/SalesResults.php');

// begin Recordset
$colname__vendorlist = '-1';
if (isset($_GET['dam_id'])) {
$colname__vendorlist = $_GET['dam_id'];
}
$query_vendorlist = sprintf("SELECT DISTINCT (sales_results.dam_id) FROM sales_results WHERE (sales_results.dam_id) ILIKE '%%%s%%'", $colname__vendorlist);
$vendorlist = $SalesResults->SelectLimit($query_vendorlist) or die($SalesResults->ErrorMsg());
$totalRows_vendorlist = $vendorlist->RecordCount();
// end Recordset
//PHP ADODB document - made with PHAkt 3.7.1?>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>

<form name="form1" method="get" action="vendor_test.php">
<table border="0" cellpadding="1" cellspacing="1">
<tr>
<td>dam_id</td>
</tr>
<?php
while (!$vendorlist->EOF) {
?>
<tr>
<td><input type="checkbox" name="dam_id" value="<?php echo $vendorlist->Fields('dam_id'); ?>">
<?php echo $vendorlist->Fields('display_name'); ?></td>
</tr>
<?php
$vendorlist->MoveNext();
}
?>
</table>

<br>
<br>
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>
<?php
$vendorlist->Close();
?>

So you can see I am then passing these variuous dam_ids to the next results page which looks like this.

<?php
//Connection statement

require_once('Connections/SalesResults.php');

//I read that this will extract the various ids from the URL string I just need to know how to put them into my SQL statement which is further below. I should also mention that at this page the URL on the second results page looks a bit like this. vendor_test.php?dam_id=1001&dam_id=1002&dam_id=1003 etc.

<?php if(strpos($_SERVER['REQUEST_URI'], '?') !== false){
list($file, $query) = explode('?', $_SERVER['REQUEST_URI']);
$pairs = explode('&', $query);
foreach($pairs as $p){
$name = $val = '';
list($name, $val) = explode('=', $p);
if($name=='dam_id'){
$dam_id[] = $val;
}
}
}
echo '<pre>'; array($dam_id); echo '</pre>';

?>

It is a very long SQL involving joins which is all working just fine.

// begin Recordset main displayed results
$colname5__dam_results = '1000000000';
if (isset($_GET['pricehigh'])) {
$colname5__dam_results = $_GET['pricehigh'];
}

$colname4__dam_results = '0';
if (isset($_GET['pricelow'])) {
$colname4__dam_results = $_GET['pricelow'];
}

$colname3__dam_results = '%';
if (isset($_GET['type'])) {
$colname3__dam_results = $_GET['type'];
}

$colname2__dam_results = '%';
if (isset($_GET['sale_year'])) {
$colname2__dam_results = $_GET['sale_year'];
}

$colname__dam_results = '-1';
if (isset($_GET['dam_id'])) {
$colname__dam_results = $_GET['dam_id'];
}
$query_dam_results = sprintf("SELECT buyers.buyer_name, results_data.dam_id, results_data.sale_id, results_data.sale_year, results_data.type, results_data.colour, results_data.sex, results_data.lot_name, buyers.buyer_id, sires.sire_name, dams.dam_name, results_data.price, vendors.vendor_name FROM results_data INNER JOIN buyers ON results_data.buyer_id = buyers.buyer_id INNER JOIN sires ON results_data.sire_id = sires.sire_id INNER JOIN dams ON results_data.dam_id = dams.dam_id INNER JOIN vendors ON results_data.vendor_id = vendors.vendor_id WHERE (dams.dam_id IN ('%s')) AND sale_year ILIKE '%s' AND type ILIKE '%s' AND (price) >= '%s' AND (price) <= '%s'", $colname__dam_results,$colname2__dam_results,$colname3__dam_results,$colname4__dam_results,$colname5__dam_results);
$dam_results = $SalesResults->SelectLimit($query_dam_results) or die($SalesResults->ErrorMsg());
$totalRows_dam_results = $dam_results->RecordCount();
// end Recordset

YES I used Dreamweaver built in macros to give me a head start in PHP so if the solution could be worked around what ive got it would be great.

davidrtantive15

11:13 pm on Mar 5, 2008 (gmt 0)

10+ Year Member



sorry right at the top it should be two tables not DB's