kvarnerexpress
Feb 2 2006, 03:13 PM
Hi, What I am trying to achieve is when you have a form drop down menu, it displays all the categories from the directory, with all the indentations. Something like when you submit your site to a directory. Now I've got it almost working, but I can figure out how to indent it. The code below, I've used a spacer gif, but obviously that won't work! I've had a go at this, as you can see, but that does do the indentations, unless I'm doing something wrong here. Any help appreciated - thanks. PHP Code: CODE function maketree($rootcatid,$level) { $sql="select catid,cat_name from tbl_name where parentid=$rootcatid order by cat_name";
$result=mysql_query($sql);
while (list($DBcatid,$DBcatname)=mysql_fetch_row($result)) { $width=($level+1)*24; if ($width==48) $display=" "; if ($width==72) $display=" "; if ($DBcatid==1) { $display.="<option value=$DBcatid>"; } else { $display.="<option value=$DBcatid>"; } $display.="$DBcatname</option>"; echo $display; maketree($DBcatid,$level+1); } } ?>
<table cellpadding="2" cellspacing="2" border="0" width="width="100%""> <tr> <td><select name="">
<? maketree(0,0);?>
</select></td> </tr> </table>
Reply
Spectre
Feb 3 2006, 07:54 AM
As far as indentation goes, it seems to work fine for me under Opera, FireFox, and Internet Explorer. I hope you don't mind, but I've 'cleaned up' your function slightly. Note that it is quickly written and untested, and sctructured it in the way which I normally write PHP code, which may be a bit annoying for others. Obviously, you're free to simply discard it. CODE <?php
function maketree( $rootcatid, $level ) {
if( !is_numeric($rootcatid) || !is_numeric($level) ) { return; }
$sql = 'SELECT catid, cat_name FROM tbl_name WHERE parentid = ' . $rootcatid . ' ORDER BY cat_name';
$result = @mysql_query($sql);
if( !$result || @mysql_num_rows($result) < 1 ) { return; }
$level++;
while( $sql_data = @mysql_fetch_assoc($result) ){ $db_catid = $sql_data['catid']; $db_catname = $sql_data['cat_name']; $display = ''; for( $i=0;$i<($level*2);$i++ ) { $display .= ' '; } $display .= '<option value="' . $db_catid . '">' . $db_catname . '</option>'; echo "$display\n"; maketree($db_catid,$level); } @mysql_free_result($result); }
?>
Reply
silentwind
Feb 3 2006, 10:23 AM
QUOTE(Spectre @ Feb 3 2006, 03:54 PM)  As far as indentation goes, it seems to work fine for me under Opera, FireFox, and Internet Explorer. I hope you don't mind, but I've 'cleaned up' your function slightly. Note that it is quickly written and untested, and sctructured it in the way which I normally write PHP code, which may be a bit annoying for others. Obviously, you're free to simply discard it. CODE <?php
function maketree( $rootcatid, $level ) {
if( !is_numeric($rootcatid) || !is_numeric($level) ) { return; }
$sql = 'SELECT catid, cat_name FROM tbl_name WHERE parentid = ' . $rootcatid . ' ORDER BY cat_name';
$result = @mysql_query($sql);
if( !$result || @mysql_num_rows($result) < 1 ) { return; }
$level++;
while( $sql_data = @mysql_fetch_assoc($result) ){ $db_catid = $sql_data['catid']; $db_catname = $sql_data['cat_name']; $display = ''; for( $i=0;$i<($level*2);$i++ ) { $display .= ' '; } $display .= '<option value="' . $db_catid . '">' . $db_catname . '</option>'; echo "$display\n"; maketree($db_catid,$level); } @mysql_free_result($result); }
?> You put it in a wrong order dude. Jut change che script from : $display .= '<option value="' . $db_catid . '">' . $db_catname . '</option>'; echo "$display\n"; to : $diaplay = '<option value="' . $db_catid . '"> . $display' . $db_catname . '</option>'; echo "$display\n"; And that should fix your problem.
Reply
Spectre
Feb 4 2006, 03:01 PM
Hmm, I didn't even pick up on that. Nice spotting. I just assumed the spaces where being added along with the option's text (as I noted, I didn't test anything).
Reply
Recent Queries:--
drop down menu php dynamic - 5.81 hr back. (1)
-
drop down seelect image display - 12.51 hr back. (1)
-
drop down select image display - 15.08 hr back. (1)
-
php dynamic drop down list - 26.70 hr back. (1)
-
javascript index value dynamic drop list - 28.38 hr back. (1)
-
dynamic switching select option php - 36.29 hr back. (1)
-
php dynamic selection list - 37.28 hr back. (1)
-
dynamic list php - 44.09 hr back. (1)
-
php html drop down do post back on select change - 46.15 hr back. (1)
-
sample code to generate dynamic dropdown lists from a sql database - 46.73 hr back. (1)
-
dynamic drop down list php - 48.77 hr back. (1)
-
problem with display of drop down list in firefox - 51.21 hr back. (1)
-
dynamic dropdown sql - 51.29 hr back. (1)
-
php dynamic drop list showing tables - 54.56 hr back. (1)
Similar Topics
Keywords : dynamic, drop, list
- Getting An Array Value Of A Dynamic Variable
(9)
Trap17 Board Status Dynamic Image
(13) I was really board a few days ago and decided to make a trap17 board status image for my sig
/tongue.gif" style="vertical-align:middle" emoid=":P" border="0" alt="tongue.gif" /> That is the
current beta. I'm still working on it so that it might display the most recent post or
somthing, i'm not sure. After I finish it ill give out the source code but if you want one
right now you can pm me and ill set one up to get the info on your account ^.^ So I was wondering
how you members liked it? You'll probably think that its a waist of time, but alas as I sai....
Can I Make Dynamic Menu In Php
is it posible to make dynamic menu in php without javascript (7) As there are many java script by which we can have event based interaction like,message on mouse
over etc,that we can create dynamic menu in javascripts to make navigation bar ,but is it possible
in php to have this acomplished without javascripts,i am new to php,is it possible?. Thanks....
More Dynamic ?id=browsing With Php (associative Array)
Just create array and watch php code do the rest (1) The thing that has been bugging me for a while was that switch statement that we use to create ID
browsing (some use If-Ifelse but results are the same for both). I wanted to figure out a way to use
more dynamic switch statement so that i only need to update my links array in order to create links
for template. With use of foreach, array_keys, and in_array functions finally i managed to do so.
Also i'm planing on changing foreach with array_walk but i'll do that later. Now for the
code.. First we create an associative array something like this CODE $gl....
Dynamic Php Pages
Nice tutorial (5) This is a really good tutorial on making php pages that normally appear as
www.domainname.com/links.php appear as www.domainname.com/index.php?page=links
http://nuwen.com/tutorials/php-dynamic-pages ....
Dynamic Image / Signature Generator
a simple code to change text on an image (12) In search of dynamically changing quote, saying or all other types of text on an image I came across
a code that I have modified to fit my initial usage. This procedure requires two files and short
knowledge of PHP. If you are familiar with Trap17's sig rotation code you will understand this
procedure very fast. Code 1: dynamic_sig.php (you can rename this to index.php and you'll see
at the end why) Code 2: a simple text file named anything (I will call it name.txt ) Code 1
CODE <?php header("Content-type: image/png"); ....
Dynamic Included Menus
path specification (8) I am looking for a way to make a dynamic menu using php and include, basicly I want to make a file
that contains html formating source and links and include it somewhere in all my pages, the problem
is that links are taken literaly and refered to as to where the html is running from. So is there a
way I can make a file and include it in my pages, then it will determin where the page is running
from, and generate the links with an approperate amount of ../../'s so if my index is at root,
but every section has it's own folder, I want to be able to include this fil....
Php Dynamic News Updating Using Mysql
changing a sites news using MySQL and PHP (3) Hey everyone. It appears to me that everyone really know what they are doing in this forum and im a
pretty new to this PHP and MySQL combo. I know some PHP but not MySQL....I am trying to make a new
website but i want to be able to go to a certain update page and change the news on the main index.
For example: - The main page show news updates of the last 10 post. - I go to the update page
and then fill in the form and it will add this post to the top of the list and still only print the
top 10. I have no clue how to do this with MySQL. At the moment i am doing it u....
Calling A Variable From A Dynamic List In A Sql Statement
(2) I would be greatful if anyone could help me out, I have been stuck on this for a while. The problem
is that I have a drop down menu which I get the contents of from a database. Then when I press the
get details button I want to use the value selected in my drop down menu and pass it into an SQL
statement to recieve all te relevent info. Everything works if I specify a known variable, but the
problem seems to be passing a variable in which is part of the array. Below is the code for the drop
down menu and the Sql statement i'm trying to execute. drop down menu: ....
Looking for dynamic, drop, list
|
|
Searching Video's for dynamic, drop, list
|
advertisement
|
|