Note that there are some explanatory texts on larger screens.

plurals
  1. POHTML Form loading displaying sql hex value via php
    primarykey
    data
    text
    <p>I'm trying to dynamically load a form that will is populated from the number of rows in a sql data base. The data returns a hex color, name, and price. I want to display the color and the name to the user within the form and on the POST, I want to send the price attached to that specific color. I've spent all day trying to figure this out.</p> <p>Any help would be greatly appreciated!</p> <p>EDIT: (here's what I have so far</p> <p>Here's an example of what I have :<a href="http://hruska-schuman.com/test2/feedback_form.php" rel="nofollow">http://hruska-schuman.com/test2/feedback_form.php</a></p> <p>Code:</p> <pre><code> $query = "SELECT `name`, img, price FROM `gutter`"; try { $stmt = $db-&gt;prepare($query); $stmt-&gt;execute(); } catch(PDOException $ex) { die("Failed to run query: " . $ex-&gt;getMessage()); } $rows = $stmt-&gt;fetchAll(); $form = '&lt;ol id="selectable" name="selectable"&gt;'; foreach($rows as $row): $prices[] = htmlentities($row['price'], ENT_QUOTES, 'UTF-8'); $form .= '&lt;li class="ui-widget-content" style="background:#'.htmlentities($row['img'], ENT_QUOTES, 'UTF-8').'"&gt;'.htmlentities($row['name'], ENT_QUOTES, 'UTF-8').' Price: '.htmlentities($row['price'], ENT_QUOTES, 'UTF-8').'&lt;/li&gt;'; endforeach; $form .=' &lt;/ol&gt;'; ?&gt; &lt;!doctype html&gt; &lt;html lang="en"&gt; &lt;head&gt; &lt;meta charset="utf-8"&gt; &lt;title&gt;Hruska Gutter Estimator&lt;/title&gt; &lt;link rel="stylesheet" href="../extras/selecttable/development-bundle/themes/base/jquery.ui.all.css"&gt; &lt;script src="../extras/selecttable/development-bundle/jquery-1.9.1.js"&gt;&lt;/script&gt; &lt;script src="../extras/selecttable/development-bundle/ui/jquery.ui.core.js"&gt;&lt;/script&gt; &lt;script src="../extras/selecttable/development-bundle/ui/jquery.ui.widget.js"&gt;&lt;/script&gt; &lt;script src="../extras/selecttable/development-bundle/ui/jquery.ui.mouse.js"&gt;&lt;/script&gt; &lt;script src="../extras/selecttable/development-bundle/ui/jquery.ui.selectable.js"&gt;&lt;/script&gt; &lt;link rel="stylesheet" href="../extras/selecttable/development-bundle/demos/demos.css"&gt; &lt;style&gt; #feedback { font-size: 1.4em; } #selectable .ui-selecting { background: #000000; } #selectable .ui-selected { background: #000000; color: white; } #selectable { list-style-type: none; margin: 0; padding: 0; width: 60%; } #selectable li { margin: 3px; padding: 0.4em; font-size: 1.4em; height: 18px; } &lt;/style&gt; &lt;SCRIPT type="text/javascript"&gt; function isNumberKey(evt) { var charCode = (evt.which) ? evt.which : event.keyCode if (charCode &gt; 31 &amp;&amp; (charCode &lt; 48 || charCode &gt; 57)) { return false; } return true; } &lt;/SCRIPT&gt; &lt;script type="text/javascript"&gt; $(function() { $( "#selectable" ).selectable({ stop: function() { var result = $( "#select-result" ).empty(); $( ".ui-selected", this ).each(function() { var index = $( "#selectable li" ).index( this ); result.append( "" + ( index + 1) ); return index; }); } }); }); &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;h1&gt;New Gutter Estimator!&lt;/h1&gt; &lt;form action="sendmail.php" method="post"&gt; &lt;table&gt; &lt;tr&gt; &lt;td&gt;Gutter Color:&lt;/td&gt; &lt;td&gt; &lt;?php echo $form; ?&gt; &lt;span id="select-result" name="result"&gt;none&lt;/span&gt; &lt;span id="select-result" name="price"&gt;&lt;?php echo $prices; ?&gt;&lt;/span&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Board Feet:&lt;/td&gt; &lt;td&gt; &lt;input type="txtChar" onkeypress="return isNumberKey(event)" name="spouts" value="" maxlength="120" /&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Number of Spouts:&lt;/td&gt; &lt;td&gt; &lt;input type="txtChar" onkeypress="return isNumberKey(event)" name="board_feet" value="" maxlength="120" /&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;E-mail to Recieve Estimate:&lt;/td&gt; &lt;td&gt; &lt;input type="text" name="email_address" value="" maxlength="120" /&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Additional Comments:&lt;/td&gt; &lt;td&gt; &lt;textarea rows="10" cols="50" name="comments"&gt;&lt;/textarea&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt;&lt;td&gt;&amp;nbsp;&lt;/td&gt; &lt;td&gt; &lt;input type="submit" value="Get Your Free Estimate!" /&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>Using JQuery UI select table: <a href="http://jqueryui.com/selectable/" rel="nofollow">http://jqueryui.com/selectable/</a></p> <p>I just don't know how to get get the selected index and post "$prices[selectedIndex]" </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload