Forum Moderators: coopster

Message Too Old, No Replies

send form to different pages according to user input

         

oxidetones

2:16 am on Aug 27, 2007 (gmt 0)

10+ Year Member



hey folks,

I have a form with multiple checkboxes that a user can choose from, to compare products. The form sends the input as parameters (GET) to the following pages URL. On that following page I have separate queries for each parameter, that pulls up the relevant data for that product. Users should choose a max of 4 products to compare. So far so good, when the user chooses 4 products, the page loads as expected.

My issue is that if a user only chooses 2 or 3 products, I get an error message on the following page, basically because the query and the resulting data being shown can't work, as 1 parameter is missing from the URL.

My questions:

Can I define that the form goes to a different page, depending on the amount of checkboxes chosen, e.g. 2 products goes to Compare2.php, 3 goes to Compare3.php etc?

Or should I somehow change the results page? If so, where would I need to start?

Thanks, Adam

eelixduppy

3:59 am on Aug 27, 2007 (gmt 0)



I would definitely try to modify the results page to accept any amount of products over 2 and under, say...4. This is a much better approach. So where do you start? Well, since you do not know how many products you have, you should be pushing the selected ones onto an array and looping through that array gathering all the information necessary to make the comparison. Familiarize yourself with arrays because you are going to need them a lot if you are going to get the results page to work correctly.

Try to mod the results page yourself, but if you get stuck post some of the relevant code and we can see where we can get it.

good luck

oxidetones

4:53 am on Aug 27, 2007 (gmt 0)

10+ Year Member



Hi eelixduppy, thanks for your response.

I already have the parameters in an array ($ID[]) and can use them accordingly. As I mentioned, there are sql queries on the following page as such:

mysql_select_db($database_BBAddict, $BBAddict);
$query_rsMod0 = "SELECT * FROM bb_data WHERE id = $ID[0]";
$rsMod0 = mysql_query($query_rsMod0, $BBAddict) or die(mysql_error());
$row_rsMod0 = mysql_fetch_assoc($rsMod0);
$totalRows_rsMod0 = mysql_num_rows($rsMod0);

This is obviously repeated 4 times (1 for each parameter). Each of these sql queries feeds a column in the table where the products can be compared. I have searched around for possibilities on how I could do this on one page, but the only possibility I have come up with is an if / else loop on each data point in the table for the 3rd and 4th parameter. This would make the page heavy loading though, as each product has around 75 data points...

Habtom

5:06 am on Aug 27, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can do it all in one query.

This is what you have:

$query_rsMod0 = "SELECT * FROM bb_data WHERE id = $ID[0]";

With a little check up for empitness:
if ($ID[0] <> "") {
$where_cond = "id = $ID[0] OR";
}else if ($ID[0] <> "") {
$where_cond .= "id = $ID[1] OR";
}else if ($ID[0] <> "") {
$where_cond .= "id = $ID[2] OR";
}else if ($ID[0] <> "") {
$where_cond .= "id = $ID[3]";
}
you can construct the query:
$query_rsMod0 = "SELECT * FROM bb_data WHERE ". $where_cond;

Habtom

oxidetones

5:10 am on Aug 27, 2007 (gmt 0)

10+ Year Member



that sort of makes sense, thanks habtom, how would I then go about populating the columns in the data table, that are each based on a separate sql query right now?

The table (in HTML) looks like this:

-----------------Prod1---Prod2---Prod3---Prod4
Feature1-----------X-------0-------0-------X
Feature2-----------X-------0-------0-------X
Feature3-----------X-------0-------0-------X
Feature4-----------0-------0-------0-------X
Feature5-----------X-------0-------X-------0
etc...

oxidetones

2:00 pm on Aug 31, 2007 (gmt 0)

10+ Year Member



nobody have an idea for me?

Thanks, A