Jump to content

[SOLVED] Problem with results from mysql table


sm0ke

Recommended Posts

Hi

 

I have a problem with a calculator script i am creating.

 

The script relies on user input, and as such I will not now which field in the table i need to pull in order to display the correct results.  EG: User chooses a surface 600mm wide with a front only downturn, they have the choice to select either front only or both as well as 13 different widths.

 

I then want to take the user input and select the correct database field.  my script is constructed as below:

 

$colour = $_POST['colour']; //colour selected
$band = $_POST['band']; //price band (choice of 4)
$down = $_POST['down'];  //front or both
$wide = $_POST['wide1']; //width selected (choice of 13)

db_login();


   $sql = "SELECT $down_$wide FROM band_$band";
     $result = mysql_query($sql) or die ("Error in query: $query " . mysql_error());
// if records present
if (mysql_num_rows($result) > 0)
{
   
    while($row = mysql_fetch_object($result))

{

$cost = $row->$down.'_'.$wide;
echo $cost;
}

}

 

using the above i usually only get the value of $wide echoed to the screen and not the value of the field $down_$wide.  However if I manually insert the values as below it works correctly:

 

$colour = $_POST['colour']; //colour selected
$band = $_POST['band']; //price band (choice of 4)
$down = $_POST['down'];  //front or both
$wide = $_POST['wide1']; //width selected (choice of 13)

db_login();


   $sql = "SELECT front_600 FROM band_$band";
     $result = mysql_query($sql) or die ("Error in query: $query " . mysql_error());
// if records present
if (mysql_num_rows($result) > 0)
{
   
    while($row = mysql_fetch_object($result))

{

$cost = $row->front_600;
echo $cost;
}

}

 

I've also attempted to use if statements so if ($down == 'front') then write the query afterwards using: $row->front_$wide.  But still the script only sees the value 600 (width) and not the value held in the database.

 

I figure I must be making a mistake in my syntax or in the structure of the database but cant seem to find an answer.

 

Cheers...  Please let me knopw if you need further info.

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.