Thats the exactly want I want to do, however the code doesn't want to work for some reason. Here is what I have now:
PHP Code:
echo <<<HTML
....
<select name="cats">
HTML;
function printoptions($p_id,$level)
//this function print the category you send it and finds all its sub categories
//$level is how deep subcategories is from the highest parent. it is represented by a "-"
{
echo "id = $p_id"; // I added this for testing, and it echos the correct value..
//print the 'parent' category
$query2 = "SELECT title FROM {$table_prefix}_articles_cats WHERE id='2' LIMIT 1";
$result2 = mysql_query($query2);
$row2 = mysql_fetch_array($result2);
$p_title = $row2['title'];
echo "p title = $p_title"; // Again for testing, however outputs no value..
echo '<option value="'.$p_id.'">'.$level.$p_title.'</option>';
//now query to find all subcatagories of the parent
$query3 = "SELECT id FROM {$table_prefix}_articles_cats WHERE parent='$p_id' ORDER BY title ASC";
$result3 = mysql_query($query3);
while ($row3 = mysql_fetch_array($result3)){
$s_id = $row3['id'];
$level.="- "; //increase the level it is on
printoptions($s_id,$level); //now we send this category and see if it has subcategories. Each category will get checked to see if it has any lower level categories.
}
}
//find all categories without a parent
$query = "SELECT id FROM {$table_prefix}_articles_cats WHERE parent='0' ORDER BY title ASC";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result)){
$p_id = $row['id'];
printoptions($p_id,"");
}
echo <<<HTML
</select>
.....
HTML;
However below are the errors i get:
HTML Code:
<select name="cats">id = 2<br />
<b>Warning</b>: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in <b>/home/duffy92/public_html/admin/articles2.php</b> on line <b>1566</b><br />
p id = 2<option value="2"></option><br />
<b>Warning</b>: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in <b>/home/duffy92/public_html/admin/articles2.php</b> on line <b>1579</b><br />
id = 1<br />
<b>Warning</b>: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in <b>/home/duffy92/public_html/admin/articles2.php</b> on line <b>1566</b><br />
p id = 1<option value="1"></option><br />
<b>Warning</b>: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in <b>/home/duffy92/public_html/admin/articles2.php</b> on line <b>1579</b><br />
</select>
Line 1566 is: $row2 = mysql_fetch_array($result2);
Line 1579 is: while ($row3 = mysql_fetch_array($result3)){
Ive changed the table name, and the values selected from the table, but no sucess. Any help?
Bookmarks