/    Sign up×
Community /Pin to ProfileBookmark

A little school help

A have a simple task here.
Its easy to complete but there`s some snares.
Please give me some advice how to create it and what to drew attention.
Thanks to everyone ! ?

Here is the tast with the picture inside
[url]http://www.mediafire.com/?7xj656uh9vdb31s[/url]

to post a comment
PHP

10 Comments(s)

Copy linkTweet thisAlerts:
@NoEffinWayMar 02.2012 — I would use AJAX for this task, will make the page smoother. What are you stuck on, I will be better able to help.
Copy linkTweet thisAlerts:
@behkoauthorMar 02.2012 — Its almost ready.. But i`m wondering one thing.

How to create the menu ?

When its clicked on the Root2 to show only the sub items,not everone in the db

Should I use jquery ?! Because I really never used it :o
Copy linkTweet thisAlerts:
@NoEffinWayMar 02.2012 — Are you pulling this info from a database? And what is the PHP you are using now? (Please edit out and sensitive info). And Possibly, but I need more info before I can say yes or no. @_@
Copy linkTweet thisAlerts:
@spufiMar 02.2012 — If this is for school, then you need to find a solution based on what technologies you are suppose to know for that class. If you aren't suppose to know jQuery, then even if you get it working you won't get it right since you found an answer that doesn't line up with what it should be.
Copy linkTweet thisAlerts:
@NoEffinWayMar 02.2012 — If this is for school, then you need to find a solution based on what technologies you are suppose to know for that class. If you aren't suppose to know jQuery, then even if you get it working you won't get it right since you found an answer that doesn't line up with what it should be.[/QUOTE]

Good point, I haven't been in school for like 6 years so I didn't think about it. ?
Copy linkTweet thisAlerts:
@behkoauthorMar 02.2012 — Here I am so far:

http://vencislav.byethost13.com/index.php




The function

function menu()

{

db_init();

if($_POST['new']==1)

{

$name=addslashes(trim($_
POST['title']));

$color=addslashes(trim($_POST['color']));

$id=(int)$_POST['edit_id'];
if($id>0)
{
mysql_query('UPDATE sub
SET name_sub="'.$name.'",color="'.$color.'"
WHERE id_sub="'.$id.'" ');
}
else
{
mysql_query('INSERT INTO sub (name_sub,color)
VALUES ("'.$name.'","'.$color.'")');
}

}

$rs=mysql_query('SELECT * FROM Main');
while($row=mysql_fetch_assoc($rs))
{
echo $row['name'].'<br />';
}

$rs=mysql_query('SELECT * FROM sub');
echo '<p>';
while($row=mysql_fetch_assoc($rs))
{
echo '<a href="index.php?mode=edit&id_sub='.$row['id_sub'].'" style="color:'.($row['color']).' ">'.$row['name_sub'].'</a><br />';
}
echo '</p>';

if($_GET['mode']=="edit" && $_GET['id_sub']>0)
{
$id=(int)$_GET['id_sub'];
$rs=mysql_query('SELECT * FROM sub WHERE id_sub='.$id);
$ed_info=mysql_fetch_assoc($rs);
}


echo '<form method="post" action="index.php">
Title:<input type="text" name="title" value="'.$ed_info['name_sub'].'"/><br />
Color:<select name="color">
<option>black</option>
<option>red</option>
<option>green</option>
<option>blue</option>
<option>yellow</option>
<option>cyan</option>
<option>magenta</option>
<option>silver</option>
<option>white</option>
</select>
<input type="submit" value="submit"/>
<input type="hidden" name="new" value="1">';

if($_GET['mode']=="edit")
{
echo '<input type="hidden" name="edit_id" value="'.$_GET['id_sub'].'">';
}


}[/QUOTE]



I have a few questions to you.

How can I add the new items to the Root1 Root2 Root3

How can I list them like in the task.

When I click Root1 to see only the items which are related to root1.


In my DB there are 2 tables

Table main

id_root name color

Auto in Root1 black

Auto in Root2 black

Auto in Root3 black

Table sub

id_sub name_sub color parent

Auto in test magenta 0

Auto in dobre blue 0

Auto in welcome! green 0

I need to make them connected to the parent:root1,2,3 or themself

I really dont think I need 2 tables,right ?! ?
Copy linkTweet thisAlerts:
@NoEffinWayMar 02.2012 — Do do the trees properly, without Javascript/jQuery, you are going to want to use the GET method to get the sub cats. For example:
[code=php]if(isset($_GET['root'])){
$rootid = $_GET['root'];
$tree = mysql_query("SELECT * FROM $db.$table WHERE sub_id = '$rootid'");
$sub = '';
while($fulltree = mysql_fetch_array($tree)){
$sub .= '<a href="?root='.$rootid.'&sub='.$fulltree['id'].'">'.$fulltree['name'].'</a>';
}}[/code]


Try seeing if you can modify that to fit your needs. I would write it for you but then you will never learn. XD
Copy linkTweet thisAlerts:
@spufiMar 02.2012 — If I understand this correctly...
<i>
</i>Table root
id, name, color

Table submenu
id, rootid, name, color.

1. Select for each root item.
2. Loop through the resulting array.
a. Display each root item.
b. Select from submenu where root.id = rootid.
c. Loop through resulting array
i. Display each submenu item.
Copy linkTweet thisAlerts:
@behkoauthorMar 03.2012 — I was in a mistake.

There is no root...

I need only one table.

It should look like this:

Item1

Item2

--Item3(child of Item2)

Item4

--Item5(child of Item4)

--Item6(child of Item4)

----Item7(child of Item6)

----Item8(child of Item6)

------Item9(child of Item8)

and so on....

Theres no problem to write the parent ID in the DB when create new item.<br/>
The question is how to draw the tree.<br/>
Should I use a recursion?<br/>
I must start the recursion and calling it every time when there is some deeper Item on the tree.<br/>
I can
t figure it out how it should be made ?
Copy linkTweet thisAlerts:
@NogDogMar 03.2012 — Some reading material for the weekend, after which you can decide which technique is right for this implementation: http://mikehillyer.com/articles/managing-hierarchical-data-in-mysql/
×

Success!

Help @behko spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...