Forum Moderators: coopster
I need to create a table based on parameters from a form on the previous page. The form sends up to 15 variables that are read out of the url into an array ($func). These variables refer to functions that a product may or may not have. This page should show which products have the functions chosen.
Normally when I create such a table in DW, its always based off the DB directly with SQL, with a filter on the URL parameter. I can't work out how to do the same when there are multiple parameters in the URL, or alternatively, pulling the parameters from the array.
Can someone point me in the right direction please?
Thanks, Adam
CREATE TABLE ". $_REQUEST['table_name'] ."
(". $_REQUEST['column_1'] ." ". $_REQUEST['data_type_1'] .",
". $_REQUEST['column_2'] ." ". $_REQUEST['data_type_2'] .")
I hope that is what you are looking for. Obviously the statement is not tested, you need to do that :)
When I said create tables, I meant in the browser, not on the db. What I am trying to do is create a table that will show products. The products to be shown are defined by the functionality chosen on the previous page (FuncIDx). As an example, a user may choose "Media Player" and "GPS" as he wants to see all products with those functionalities. Each of those has a unique FuncID, which is in an array on the following page. The question I have is how can I call the list of products that has a DB entry in the column that corresponds to the FuncIDs?
Thanks, Adam
From your first post:
I can't work out how to do the same when there are multiple parameters in the URL, or alternatively, pulling the parameters from the array.
if you wanted to access the array, you can see how it is structured by printing it as:
print_r($func);
and then use foreach or another loop to query something out of the database while accessing the values in the function one by one.
Habtom
this is the bit I need a little more clarification on
>> I can't work out how to do the same when there are multiple parameters in the URL, or alternatively, pulling the parameters from the array.
a bit of code to illustrate what the differences are in the code when you have more than one param might make the error pop out
MultiFunc.php?FuncID%5B%5D=FuncID05&FuncID%5B%5D=FuncID11&FuncID%5B%5D=FuncID44&submit=Go
Although this isnt pretty, its correct, the user chose three functionalities (FuncID's), 05, 11 and 44, which in turn refers to Camera, GPS and microSD card.
I've already checked that this works with the following code:
<?php foreach ( $_GET["FuncID"] as $func )
{
$find = array("FuncID01", "FuncID05", "FuncID06", "FuncID70", "FuncID10", "FuncID11", "FuncID18", "FuncID21", "FuncID22", "FuncID26", "FuncID27", "FuncID39", "FuncID44", "FuncID46", "FuncID47");
$replace = array("Wireless email", "Camera", "BlackBerry Maps", "Media player", "MMS", "GPS", "Trackball", "Trackwheel", "3.5mm jack", "Built-in speakerphone", "Bluetooth technology", "MP3 ringtones", "microSD card", "RIM wireless modem", "Tethered modem capability");
$func = str_replace($find, $replace, $func);
echo $func, "<br />";
}
?>
I am using Dreamweaver, which allows me to define a recordset based on one URL variable, and its getting products with all three (in this case) variables that I cant work out.
Thanks, and let me know if you need more info
What this page should be doing is listing products that have these functionalities. In a separate table where the product details are stored, there are columns named after each and every FuncID. Ideally, I want to show the following:
There are two products which have: Camera, GPS and microSD card: Product 1, Product 2
<form action="MultiFunc.php" method="get" name="m">
<?php
do {
?>
<input type="checkbox" name="FuncID[]" value="<?php echo $row_rsMenu['FuncID']?>"> <?php echo $row_rsMenu['name']?> <br />
<?php
} while ($row_rsMenu = mysql_fetch_assoc($rsMenu));
$rows = mysql_num_rows($rsMenu);
if($rows > 0) {
mysql_data_seek($rsMenu, 0);
$row_rsMenu = mysql_fetch_assoc($rsMenu);
}
?>
<input name="submit" type="submit" value="Go" />
</form>
and this is how DW makes a recordset looking for 1 URL parameter (also called FuncID):
$colname_rsMultiFunc = "-1";
if (isset($_GET['FuncID'])) {
$colname_rsSingFunc = $_GET['FuncID'];
}
mysql_select_db($database_BBAddict, $BBAddict);
$query_rsMultiFunc = "SELECT id, Type, img, Name FROM bb_data WHERE $colname_rsMultiFunc = 'x' ORDER BY Type DESC";
$rsMultiFunc = mysql_query($query_rsMultiFunc, $BBAddict) or die(mysql_error());
$row_rsMultiFunc = mysql_fetch_assoc($rsMultiFunc);
$totalRows_rsMultiFunc = mysql_num_rows($rsMultiFunc);
?>
The DB table in question is as follows:
id ¦ Type ¦ Name ¦ Series ¦ img ¦ FuncID01 ¦ FuncID02 ¦ etc, thru FuncID74
The individual rows are then the products themselves, and will have an "x" in the relevant FuncID columns if they possess that functionality.
Thanks again, Adam
you need to add an OR
select fieldname from tablename where col1='x' or col2='x' or col3='x';
that's how the query should work to get anything with those things checked to return. This means that a chunk of code needs to be changed.
you could do this
$whereclause = '';
$counter = 0;
foreach ($_GET['FuncID'] as $func) {
if ($counter!= 0) $whereclause .= ' OR ';
$whereclause .= $func . "='x'";
$counter++;
}
mysql_select_db($database_BBAddict, $BBAddict);
$query_rsMultiFunc = "SELECT id, Type, img, Name FROM bb_data WHERE $whereclause ORDER BY Type DESC";
$rsMultiFunc = mysql_query($query_rsMultiFunc, $BBAddict) or die(mysql_error());
$row_rsMultiFunc = mysql_fetch_assoc($rsMultiFunc);
$totalRows_rsMultiFunc = mysql_num_rows($rsMultiFunc);
might work, it's late and I am just shooting from the hip
Anyway, I inserted your query in place of the one I had in there. It doesnt show up in DW as a record set, so I cant validate it in DW. Online, whenusing the form that pulls up that page I get this:
You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '='x' OR ='x' ORDER BY Type DESC' at line 1
which is weird coz line 1 is justr the db connection....
Thanks again for your help on this
try adding this
...
$query_rsMultiFunc = "SELECT id, Type, img, Name FROM bb_data WHERE $whereclause ORDER BY Type DESC";
echo '<p>the query is: ',$query_rsMultiFunc;
die();
$rsMultiFunc = mysql_query($query_rsMultiFunc, $BBAddict) or die(mysql_error());
$row_rsMultiFunc = mysql_fetch_assoc($rsMultiFunc);
$totalRows_rsMultiFunc = mysql_num_rows($rsMultiFunc);
and then paste what it echos
the comma is legit
[php.net...]
I prefer no to have to concatenate my strings before echo can spit them out so I use commas.
learning more about the code DW is writing for you will help you in the long run oxidetones but using it while you are learning is just fine.