Forums
This topic is locked
Using array values in an existing Recordset
28 Jan 2005 09:22:24 L M posted:
Hi there,For the last 2 days I've been trying to work out how to take values from an array, and use them to filter an existing recordset using Dreamweaver MX 2004, but I have to admit defeat and ask for help because I just can't seem to do it.
I have simple example that I am using for testing which contains 2 files - search.php and results.php. The search.php passes an array (created from the multiple selection in a list box) to results.php on submit. I can loop through the array and echo each value. So far so good.
However, in my search.php, I have already created a detailed recordset and a corresponding repeat region (to display users' search results). What I want to do is pass each value from the array to the existing recordset so that it creates a new row in my repeat region, then loop through again until the array is empty, then display the results.
What I have thus far is as follows:
<pre id=code><font face=courier size=2 id=code> <?php
mysql_select_db($database_NADB_oneandone, $NADB_oneandone);
$query_town = "SELECT * FROM TOWN";
$town = mysql_query($query_town, $NADB_oneandone) or die(mysql_error());
$row_town = mysql_fetch_assoc($town);
$totalRows_town = mysql_num_rows($town);
foreach ($town_id as $num=>$current) {
$SQLquery = "$query_town WHERE TOWN.ID = '$current'";
$SQLresult = mysql_query ($SQLquery) or die ("Mysql query :" . mysql_error());
$varlist = mysql_fetch_array ($SQLresult);
echo $varlist['ID'] . "=>" . $varlist['TOWNORSUBURB'] . "<br />";
}
?></font id=code></pre id=code>
That prints out a beautiful list for me:
297=>Sheffield Beach
271=>Randburg
40=>Bryanston
282=>Rosebank
187=>Magaliesburg
I then created another DM recordset, called Town2. I created a dynamic table from this, and modified the recordset in the code so that the select query = the foreach query:
<pre id=code><font face=courier size=2 id=code> mysql_select_db($database_NADB_oneandone, $NADB_oneandone);
$query_town2 = $SQLquery;
$query_limit_town2 = sprintf("%s LIMIT %d, %d", $query_town2, $startRow_town2, $maxRows_town2);
$town2 = mysql_query($query_limit_town2, $NADB_oneandone) or die(mysql_error());
$row_town2 = mysql_fetch_assoc($town2);
if (isset($_GET['totalRows_town2'])) {
$totalRows_town2 = $_GET['totalRows_town2'];
} else {
$all_town2 = mysql_query($query_town2);
$totalRows_town2 = mysql_num_rows($all_town2);
}
$totalPages_town2 = ceil($totalRows_town2/$maxRows_town2)-1;
?></font id=code></pre id=code>
I end up with a table that shows on the last record - 187 | Magaliesburg.
Please can someone help me to figure out what I need to change in order for the repeat region to return all results? I feel quite deflated atm, so any advice would be gratefully received!
I'm using PHP 4.0.1, Dreamweaver MX 2004 7.0.1 and MySQL 4.
Very best wishes,
LM.