Note that there are some explanatory texts on larger screens.

plurals
  1. POsql queries results from parents
    primarykey
    data
    text
    <p>need some help completing my code what it does is searches in the tables of my DB for all the sections pointing to the parent_sections=2 and then prints the results in a select tag i would like some help with the sql query to check if the parent_sections=2 has child's and if so to print them with a optgroup style anyway please check the images below they explain what i need.</p> <p>PHP &amp; SQL CODE:</p> <pre><code>&lt;?php include('../application_top.php'); function get_title_sections($id){ $sections_query = tep_db_query("select title_sections_detail from sections_detail where id_sections = '" . (int)$id . "' and id_lang='0' order by title_sections_detail"); $result=''; while ($sections = tep_db_fetch_array($sections_query)) { $result=$sections['title_sections_detail']; } return $result; } ?&gt; &lt;form&gt; &lt;select name="sections"&gt; &lt;option selected="selected" value=""&gt;Please choose an option&lt;/option&gt; &lt;?php $sections_sql=tep_db_query("select p.id_sections, d.title_sections_detail as title from sections p, sections_detail d where p.id_sections=d.id_sections and d.id_lang='0' and p.status_sections='1' and p.parent_sections='2' order by d.title_sections_detail asc"); while ($sections = tep_db_fetch_array($sections_sql)) { $id_sec=$sections['id_sections']; $title_sec=get_title_sections($id_sec); ?&gt; &lt;option value="&lt;?php echo $id_sec ?&gt;" &gt;&lt;?php echo $title_sec ?&gt;&lt;/option&gt; &lt;?php }?&gt; &lt;/select&gt; &lt;/form&gt; </code></pre> <p>SQL table sections: <img src="https://i.stack.imgur.com/g3HjD.jpg" alt="TABLE sections"></p> <p>SQL table sections_detail: <img src="https://i.stack.imgur.com/4oyYZ.jpg" alt="TABLE sections_detail"></p> <p>RESULT:</p> <p><img src="https://i.stack.imgur.com/OqNqc.jpg" alt="RESULT"></p> <p>RESULT I NEED:</p> <p><img src="https://i.stack.imgur.com/V1ICb.jpg" alt="RESULT I NEED"></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