Hi, wondering if anyone can help me. I'm trying to display data from a table in my database. the data depends on the inputs from the form.
Steps:
Form inputs (select drop down menus) are saved to a table in my database called quote. this works fine. The next step is to display code from another table.
I have entered the follow code into the onSubmit code after sending email field. This looks at a different database and filters it depending on the input fields of the form.
At the moment this section does not return any results.
The code below have three (in theory) identical statements. however the only sql query that works is the last one - $sql_2. this does not have the field from the form in it, so does not vary depending on the imput of the form. it has the text the field would say to test it. why are $sql_0 and $sql_1 not working?
I have echo'd the three statements and they are identical when printed to the screen.
This is the output:
Material:EVA
output_0:
output_1:
output_2:EVA
At the moment the run order is:
Order of Autogenerated block 3 [+] [-]
Order of OnSubmit block 2 [+] [-]
Order of Plugins block 1 [+] [-]
Thanks for any help
Steps:
Form inputs (select drop down menus) are saved to a table in my database called quote. this works fine. The next step is to display code from another table.
I have entered the follow code into the onSubmit code after sending email field. This looks at a different database and filters it depending on the input fields of the form.
At the moment this section does not return any results.
The code below have three (in theory) identical statements. however the only sql query that works is the last one - $sql_2. this does not have the field from the form in it, so does not vary depending on the imput of the form. it has the text the field would say to test it. why are $sql_0 and $sql_1 not working?
I have echo'd the three statements and they are identical when printed to the screen.
<p>Material:{material}</br>
<?php
$f1="{material}";
$database =& JFactory::getDBO();
$sql_0 = "SELECT * FROM jos_approx_prices WHERE material='{material}'";
$sql_1 = "SELECT * FROM jos_approx_prices WHERE material='" . $f1 . "'";
$sql_2 = "SELECT * FROM jos_approx_prices WHERE material='EVA'";
$result_0 = mysql_query($sql_0);
$result_1 = mysql_query($sql_1);
$result_2 = mysql_query($sql_2);
$output_0 = mysql_result($result_0,0);
$output_1 = mysql_result($result_1,0);
$output_2 = mysql_result($result_2,0);
echo "output_0:" . $output_0;
echo "</br> output_1:" . $output_1;
echo "</br> output_2:" . $output_2;
?>
This is the output:
Material:EVA
output_0:
output_1:
output_2:EVA
At the moment the run order is:
Order of Autogenerated block 3 [+] [-]
Order of OnSubmit block 2 [+] [-]
Order of Plugins block 1 [+] [-]
Thanks for any help
Hi klaxen,
You can't use the {input_name} syntax in the PHP - it isn't evaluated until later. Please try
Bob
You can't use the {input_name} syntax in the PHP - it isn't evaluated until later. Please try
<p>Material:{material}</br>
<?php
$material = JRequest::getString('material', '', 'post');;
$db =& JFactory::getDBO();
$query = "
SELECT *
FROM `#__approx_prices`
WHERE `material` = '".$db->quote($material)."' ;
";
$db->setQuery($query);
$data = $db->loadAssoc(); // if you expect only a single row
//$data = $db->loadAssocList(); // if you expect more than one row
echo'<div>$data: '.print_r($data, true).'</div>';
?>
Bob
Hi Bob, you're a star.
There were a few typos in your code so here is the code i used to get it working. I just had to request the field's post data.
And it worked.
Thanks
There were a few typos in your code so here is the code i used to get it working. I just had to request the field's post data.
<?php
$material = JRequest::getString('material', '', 'post');
$query = "SELECT * FROM `jos_approx_prices` WHERE `material` = '" . $material . "'";
$result_0 = mysql_query($query);
$output_0 = mysql_result($result_0,0);
echo "output_0:" . $output_0;
?>
And it worked.
Thanks
I tried the last set of code and I'm getting an error in Line 5:
Warning: Wrong parameter count for mysql_result() in /home/name/public_html/name/components/com_chronocontact/libraries/customcode.php(51) : eval()'d code on line 5
output_0:
I'm trying to do the same thing with a form to print out results based on a drop-down selection. However I have two drop-downs I need to use.
I tried bob's code and it doesn't give me an error, it just does not pull anything from DB.
HELP. Thanks
$output_0 = mysql_result($result_0,0);
Warning: Wrong parameter count for mysql_result() in /home/name/public_html/name/components/com_chronocontact/libraries/customcode.php(51) : eval()'d code on line 5
output_0:
I'm trying to do the same thing with a form to print out results based on a drop-down selection. However I have two drop-downs I need to use.
I tried bob's code and it doesn't give me an error, it just does not pull anything from DB.
HELP. Thanks
This topic is locked and no more replies can be posted.