Solved

MySql, ajax, php tree menu - extra help

Posted on 2010-11-27
3
461 Views
Last Modified: 2012-06-22
I've converted the previous script to mysqli as all my scripts are, and it works perfectly, and now I'm trying to get it to link to the correct page id number as this example:

http://dev.netbridge.co.uk/admin/example.php

Basically, my script links to a page called page_edit.php which collects the relevant page id to display the contents.

The way I have this script at the moment, it only links to the LAST page id, no matter what link you click on, and I want each link to go to a different page id (does that make sense at all??),

Here's the modified script:

 
and here's the "ajax_tree.php" that the page is referring to in case that helps:

 
and here's the edit_page.php code:

 
Would really appreciate the extra help!

Thanks,

Owen
0
Comment
Question by:owennicol
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 11

Expert Comment

by:Bruce Smith
ID: 34221415
Yes, your while loop that starts on line 8, sets the $pid on line 9. You are not storing that $pid in variable anywhere (like in an array) so the value is ALWAYS going to be the LAST value when you call it down in line 111. You need to modify your code on the following lines to something like the this:

9: // just remove line 9 where you have: $pid = $row["id"];

10: $label_array[$counter] = array("id" => $row['id'], "parent" => $row['parent_id'], "linklabel" => $row['linklabel']);

111: $tree_data[$counter] = array(url => "edit_page.php?pid=".$label_array[$counter]["id"], parent => $parent_id, name => $label_array[$counter]["linklabel"]);
           
0
 
LVL 11

Accepted Solution

by:
Bruce Smith earned 500 total points
ID: 34221440
What you have is like saying the following:

 
$counter = 0;
while($counter < 10):
   $pid = $counter;
   $counter++;
endwhile;

echo('The Counter Variable = '.$counter);

Open in new window


That code will ALWAYS echo "The Counter Variable = 9". Same thing with your $pid variable. It will always equal the last id in your database when you call it down on line 111. Hope this explains the fix.
0
 

Author Closing Comment

by:owennicol
ID: 34221660
Thank you so much, that's perfect.

Thank you also for explaining it so well.
0

Featured Post

The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question