Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Retrieve value from tep_get fonction


patator

Recommended Posts

Hello

 

I'm trying to retrieve the value of two pull down boxes and incorporate them into a sql in order to retrieve a value from a table.

Here is the page :

http://www.clubfitting.net/tech_meas_length.php

 

Both drop down menu are obtained in the same way :

<?php  echo tep_get_length_list('length') . ' ';?>

 

in general.php

//Height of the player
function tep_get_length($length_id='') 
{
$length_array = array();
if (tep_not_null($length_id)) 
{
$length = tep_db_query("select height from " . TABLE_LENGTH . 
" where length_id = '" . (int)$length_id . "'");
$length = tep_db_fetch_array($length);
$length_array = array('height' => $length_values['height']);
} 
else 
{
$length = tep_db_query("select height from " . TABLE_LENGTH . 
" where length_id <> 999 group by height order by height");
while ($length_values = tep_db_fetch_array($length)) 
{
$length_array[] = array('length_id' => $length_values['length_id'],
'height' => $length_values['height']);
}
}
return $length_array;
}

 

in html_output.php

// Creates a pull-down list of shaft length

function tep_get_length_list($name, $selected = '', $parameters = '') {
//$length_array = array(array('id' => '999', 'text' => PULL_DOWN_DEFAULT));
$length = tep_get_length();

for ($i=0, $n=sizeof($length); $i<$n; $i++) {
$length_array[] = array('id' => $length[$i]['length_id'], 'text' => $length[$i]['height']);
}

return tep_draw_pull_down_menu($name, $length_array, $parameters);
}

 

 

What I would like to obtain, when the calculate button is pushed, is the result of the following query:

$shaft = tep_db_query("select length_id,shaft_length from " . TABLE_LENGTH ." where height= '" . $height . "' and wrist= '" . $wrist . "'");

$height is the value entered in the first box

$wrist is the value entered in the second box

 

The problem is that I don't know how to retrieve the values selected by the user.

 

Could somebody help?

 

Thanks

Patrice

Link to comment
Share on other sites

if you use the tep_draw_form function you may have something like this in your page

 

tep_draw_form('myform', tep_href_link(FILENAME_DEFAULT, '', 'NONSSL', false), 'get'),
tep_draw_pull_down_menu('myform_id', $myform_array, $myform_array[0]['id'], 'onChange="FormChange(myform.myform_id.form);" size="' . 1 . '" style="width: 100%"') . tep_hide_session_id();

 

Then for jscript you could add something like

<script language="javascript" type="text/javascript"><!--
 function FormChange(param)
 {
    do calculations here
 }
//--></script>

 

Once the user changes value in the combobox FormChange is called passing the parameter value to the jscript function. The value itself is through the HTTP_GET_VARS array ie myform_id setting

Link to comment
Share on other sites

Thanks again for your answer

 

I added the following to my code

 

<?

$length_array = tep_get_length();
echo tep_draw_form('myform', tep_href_link(FILENAME_FITTING_LENGTH, '', 'NONSSL', false), 'get');
echo tep_draw_pull_down_menu('myform_id', $length_array, $length_array[1]['height'], 'onChange="FormChange(myform.myform_id.form);" size="' . 1 . '" style="width: 100%"') . tep_hide_session_id();
?>
?>

 

Having in general.php

 

function tep_get_length($length_id='') 
{
$length_array = array();
if (tep_not_null($length_id)) 
{
$length = tep_db_query("select height from " . TABLE_LENGTH . 
" where length_id = '" . (int)$length_id . "'");
$length = tep_db_fetch_array($length);
$length_array = array('height' => $length_values['height']);
} 
else 
{
$length = tep_db_query("select height from " . TABLE_LENGTH . 
" where length_id <> 999 group by height order by height");
while ($length_values = tep_db_fetch_array($length)) 
{
$length_array[] = array('length_id' => $length_values['length_id'],
'height' => $length_values['height']);
}
}
return $length_array;
}

 

The problem is that the tep_draw_pull_down_menu doesn't populate the drop down menu which remains empty.

 

Any idea ?

 

Patrice :'(

Link to comment
Share on other sites

Fine I changed the code as follow

 

$length = tep_get_length();

for ($i=0, $n=sizeof($length); $i<$n; $i++) {
$length_array[] = array('id' => $length[$i]['length_id'], 'text' => $length[$i]['height']);
}

 

echo tep_draw_form('myform', tep_href_link(FILENAME_FITTING_LENGTH, '', 'NONSSL', false), 'get');
echo tep_draw_pull_down_menu('myform_id', $length_array, $length_array[0]['height'], 'onChange="FormChange(myform.myform_id.form);" size="' . 1 . '" style="width: 100%"') . tep_hide_session_id();

 

And now the combo box is correctly populated and I manage to interact with the JS

 

Thanks

Patrice

Link to comment
Share on other sites

looks like your passing multi-dimensional array The function assumes one element array. I believe you need few more mods either return the length, height in 2 separate arrays or modify it when it comes back from your tep_get_length function.

 

Besides you have 2 different combos you need to populate so another tep_draw_pull_down_menu and draw_form set is needed

 

cool you got while I was typing :lol:

Link to comment
Share on other sites

Great as you can see but I can't get the value in the js script

I want to withdraw the value of length_id but I'm facing some difficulties.

Here is what I do in the js :

 

<script language="javascript" type="text/javascript"><!--
function FormChange(param)
{
 
alert(document.myform.length_id.form.value);
}
//--></script>

 

It says "undefined"

 

What am I doing wrong ?

 

(I want to use the values of the combos in a query which will be:

$shaft = tep_db_query("select length_id,shaft_length from " . TABLE_LENGTH ." where height= '" . $height . "' and wrist= '" . $wrist . "'");

)

 

Thanks

Patrice

Link to comment
Share on other sites

I think you need to put something like this:

alert( param.elements[0].value);

the elements contains the values. Also there are plenty of sites that give online help for the jscript fields; let me know I could PM you a couple of them.

Link to comment
Share on other sites

I found my error (the array was not correctly populated, right at the begining).

 

Would you know what's the best solution to run my query using the 2 variables and disply the result of my query at the bottom of my page ?

 

The query is

$shaft = tep_db_query("select length_id,shaft_length from " . TABLE_LENGTH ." where height= '" . $height . "' and wrist= '" . $wrist . "'");

 

. $height . and . $wrist . are the elements selected in the drop down menu.

 

Thanks

Patrice

Link to comment
Share on other sites

ok it will be one of the root files (ie in the catalog directory you eventually going to pring the test values) so lets say it was product_info.php If you go near the end there is a separator statement. You could setup a couple of rows (or a nice little table with your css classes) and place them (Dont forget to place the actual results in a table cell)

<td><table border="0" width="100%" cellspacing="0" cellpadding="2">
?<tr>
? ? <td width="50%"><?php echo $some_height_variable_and_maybe_an_image; ?></td>
? ? <td width="50%"><?php echo $some_wrist_variable_and_maybe_an_image; ?></td>
?</tr>
</table></td>

Now to be really safe you could add an if statement before doing the echo as you do not want to display values unless they are valid or something.

 

If on the other hand you need to create a new page for the results check how the advanced_search files work.

 

finally for the query

$shaft = tep_db_query("select length_id,shaft_length, shaft_wrist from " . TABLE_LENGTH ." where shaft_length= '" . $height . "' and shaft_wrist= '" . $wrist . "'");

just put the correct fields from your sql table I just placed them there as an example as they need to match (ie "selected fields" with "compared fields")

 

forgot you need to finally do a tep_db_fetch_array to get the results from your sql query.

Link to comment
Share on other sites

Thanks again for your help.

 

My question was not clear enough...sorry

I know how to run the query and where to place it

 

<? 

//calcul de la longueur du shaft

$shaft = tep_db_query("select length_id,shaft_length from " . TABLE_LENGTH ." where height= '" . $height_value . "' and wrist= '" . $wrist_value . "'");
$total = mysql_num_rows($shaft);

if($total) {
   
       echo '<tr>';
       echo '<td colspan="3" class="fitting_result">'. fitting_shaft .'';
        
   while($row = mysql_fetch_array($shaft)) {
       echo ''.$row['shaft_length'].'</td>';
           }
   echo '</tr>'."\n";
echo '<tr>';
       echo '<td colspan="3" class="fitting_result2">'. fitting_shaft_default .'</td></tr>'."\n";

}
else echo '<td colspan="3" class="fitting_result2">NO RECORD</td></tr>'."\n";
?>

 

What I would like to know is how to run from the js function the query, so that I can show the result for the selected values. (in a popup or in the current html page after reloading it)

 

Have a look at the page I'm working on : http://www.clubfitting.net/tech_meas_length.php

 

Thanks again for your help

Pat

Link to comment
Share on other sites

you dont run your sql query in js. Only the php accesses the dbase before displaying the html output (including your js script). So once the jscript runs it can load a new popup window say. (which is a new php page fully loaded with your php queries which will show the results) the selections from the combos will be the posted arguments. (get or post) The get or post commands are passed with the tep_draw_form function

 

Is that what you wanted to know?

Link to comment
Share on other sites

Yes Sir, this is what I wanted to know.

"The get or post commands are passed with the tep_draw_form function"

 

So I carry on, I'm adding a button which will post the form and reload the page to display the result

 

Patrice

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...