Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Difficult to know where to start in trying to answer. How much of the above code is actual, and how much is for demo purposes in asking the question? I assume you wont be inserting data into the database on each page load. I assume you won't be hard coding your database table name with the 'jos_' prefix. When doing this for real you should use '#__' without the quotes.</p> <p>Does a database query returning an error need to kill the script and raise a server 500 error? I think detecting and intercepting the error and handling gracefully would be better.</p> <p>After your tag you have the word date and then a - ie you close an option tag you never opened. I assume you intend to somehow label the select - best to do this with an actual tag rather than populating a dummy option within the select.</p> <p>If you don't wrap your array keys in quotes you'll probably generate warnings - so do this $nt['training'] rather than $nt[training]</p> <p>You probably need to retrieve as associative array rather than a standard ordinal array.</p> <p>You then run a database query 'outside' of Joomla. You have retrieved the database object - you should use it rather than running mysql_query directly.</p> <p>Instead of this:</p> <pre><code>$queryCourses="SELECT training_id,training,trainingDate FROM training"; ?&gt; $result = mysql_query ($queryCourses); </code></pre> <p>You probably need to do something more like this</p> <p>// <a href="http://docs.joomla.org/How_to_use_the_database_classes_in_your_script#loadAssoc.28.29" rel="nofollow">http://docs.joomla.org/How_to_use_the_database_classes_in_your_script#loadAssoc.28.29</a></p> <pre><code>$queryCourses="SELECT training_id,training,trainingDate FROM training"; ?&gt; $db-&gt;setQuery($queryCourses); $db-&gt;query(); $num_rows = $db-&gt;getNumRows(); if(! $num_rows){ // return or die or something - there ar no results } while($nt = $db-&gt;loadAssoc()){ </code></pre> <p>On this line</p> <pre><code>echo "&lt;option value=$nt['id']&gt;$nt['training']&lt;/option&gt;"; </code></pre> <p>you should probably do this:</p> <pre><code>echo "&lt;option value=\"{$nt['id']}\"&gt;{$nt['training']}&lt;/option&gt;"; </code></pre> <p>clearly delineating the variables with curly braces as the whole line is wrapped in quotes and remembering to put quotes around the value parameter in case you decide to add other variables into there and include spaces etc.</p> <p>From your description you want to display the date to the user - you probably want to add an extra variable - maybe two within the ... part, perhaps something like:</p> <pre><code>echo "&lt;option value=\"{$nt['id']}\"&gt;{$nt['training']} {$nt['trainingDate']}&lt;/option&gt;"; </code></pre> <p>I'm sure there are other things that I'm missing - and I've assumed your db query is broadly correct and returns results, but there should be enough pointers there to get you on the right track.</p> <p>Finally - when building / populating a select list you can build data structures and get Joomla's jHTML class to do the heavy lifting for you. I wonder sometimes if too much abstraction creates more work than rolling your own - but hey, the option is there.</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.
    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