Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The first step is to do a find/replace for 'catagories' to change to 'categories' to make sure that your code is speaking the same language as your database tables and -- a happy bonus -- that it is in English!</p> <p>If I understand the question: you have a list of the distinct titles of categories but no IDs for these. You have no guarantee that each title corresponds to exactly one ID; indeed, if using 'DISTINCT' in your query is to have any effect on the rows returned, then there are at last two IDs corresponding to a single title.</p> <p>This is quite unusual so you may want to review why (i) you have several eponymous (same-named) categories and (ii) this being the case, why they should not be returned for selection in your form.</p> <p>If it turns out that you do need to provide a list of distinct category titles and for the form submission to do something with these, there must be IDs, then the choice of which ID to use per title is ambiguous.</p> <p>Assuming that it does not matter which ID is used, so long as it matches the appropriate title, you can do the following:</p> <pre><code>&lt;?php foreach ($rows as $row) { $query = "SELECT id FROM #__categories WHERE title = " . $row-&gt;title . " AND published = '1' LIMIT 1 "; $db-&gt;setQuery($query); $row-&gt;id = $db-&gt;loadResult(); ?&gt; &lt;option &lt;?php if ($row-&gt;id == $catagories) { echo " selected=\"selected\""; } ?&gt;value="&lt;?php echo $row-&gt;id;?&gt;" &gt; &lt;?php echo $row-&gt;title;?&gt; &lt;/option&gt; &lt;?php }?&gt; </code></pre> <p>For a more efficient solution, you could look into using <a href="http://www.tizag.com/sqlTutorial/sqlunion.php" rel="nofollow">UNION</a> in your original query to provide an ID for each of the rows returned.</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.
    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