Jump to content

Join mysql data


bass_avb

Recommended Posts

Hey guys,

 

I have two tables :

pages

-id

-page_name

-page_text

-page visibility

 

menu

-id

-page_id

-page_name

-menu_name

-menu_position

-menu_visibility

 

I want to be able to link page_id and page_name in both tables so pages can be liked to specific menu items. So if i create a new page  I could link it to any menu item by choosing it from a drop down in the form and after I click SAVE it will update page_id and page_name in my menu table for later use.

 

Below are functions I got so far:

<?php
function get_all_pages() {
        global $connection;
                mysql_select_db("content_MS", $connection);
        $query = "SELECT *
                          FROM pages
                  ORDER BY id ASC";
        $result_set = mysql_query($query, $connection);
        confirm_query($result_set);
        return $result_set;

}

function drop_down_pages(){
global $connection;
$result = get_all_pages();
$output = "<div>";
$output .="<select>";
while($row = mysql_fetch_array($result))
  {
  $output .= "<option>";
  $output .= "<a href=\"edit/edit_page.php?id="
  . urlencode($row["id"]) . '&page_name='. urlencode($row["page_name"]) ."\">
  {$row["id"]} - {$row["page_name"]}</a></option>";
  }
  $output .="</select>";
  $output .="</div>";
  return $output;
}

function get_all_menu_items() {
        global $connection;
                mysql_select_db("content_MS", $connection);
        $query = "SELECT *
                          FROM menu
                  ORDER BY id ASC";
        $result_set = mysql_query($query, $connection);
        confirm_query($result_set);
        return $result_set;

}

function list_menu_items(){

global $connection;
$result = get_all_menu_items();
$output = "<div>";
while($row = mysql_fetch_array($result))
  {
  $output .="<ul>";
  $output .= "<li>";
  $output .= "<a href=\"edit/edit_menu.php?id=" . urlencode($row["id"]) . '&menu_name='. urlencode($row["menu_name"]) ."\">{$row["menu_name"]}</a></li>";
  $output .="</ul>";
  $output .= drop_down_pages();
  $output .="<br>";
  }
  $output .="</div>";
  return $output;
}
?>

 

Then I echo list_menu_items(). Here are some things I cant get to work:

 

1) Drop down list does not auto-select the current page linked to the menu item.

2) How do I update this once problem 1 is resolved?

 

Thanks in advance!

 

--best

 

AB

Link to comment
https://forums.phpfreaks.com/topic/178544-join-mysql-data/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.