Jump to content

bass_avb

New Members
  • Posts

    6
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

bass_avb's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hey all, I have two tables menu and pages. I am trying to create a dropdown list which pre-selects the page based on id of the page. I created page_id in my menu table which corresponds to id of the page from pages table. Here is the visual of what I want: Menu Item Pages | | Home Page ==> [select Page] [Home Page] * [bio] [info] [Contacts] HTML Output: <form> <select> <option selected value"1">Home Page</option> <option value"2">Bio</option> <option value"3">Info</option> <option value"4">Contacts</option> </select> </form> This is the code I have so far: function drop_down_pages(){ global $connection; $db=mysql_select_db("content_MS", $connection); $sql=mysql_query("SELECT page_name, id FROM pages ORDER BY page_name"); $pid=mysql_fetch_array($sql); $sql2=mysql_query("SELECT page_id FROM menu ORDER BY page_id"); $mid=mysql_fetch_array($sql2); $output ="<form>"; $output.="<select>"; if($mid['page_id']==$pid['id']){ while($row=mysql_fetch_array($sql)){ $page_name=$row['page_name']; $id=$row['id']; $output.="<option selected value=\"$id\">$page_name</option>"; } } else{ while($row=mysql_fetch_array($sql)){ $page_name=$row['page_name']; $id=$row['id']; $output.="<option value=\"$id\">$page_name</option>"; } } $output.="</select>"; $output.="</form>"; return $output;} When I test the code all I get is a list of pages with the first one selected but it doesn't match. Any ideas?
  2. 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
  3. HAHAHA OMG... I have been staring at the page for like two hours and didnt catch that one. It works now but there is one problem though. I have 2 records in the table but only one of them is showing (record 2) and the following is not getting outputted $output = "<div>"; $output .= "<p>Select the page you would like to edit:</p>"; This is what page source looks like : <div id="content-wrapper"> <div id="content"> <div class="in"> <h2>This is the main content</h2> <ul><li><a href="manage_pages.php?page=2">Bio</a></li></ul></div> </div> </div> [\code] So <div> and "Select the page you would like to edit:" is not showing.
  4. Hi, I did. This is the code for manage_pages.php <?php include ("includes/header.php"); ?> <div id="content"> [b]<div class="in"> <h2>This is the main content</h2> <?php list_pages();?> </div>[/b] </div> <?php include ("includes/footer.php"); ?> BTW... I also tried to combine everything into one function but same result: <?php function list_pages(){ $DB_SERVER = "****"; $DB_USERNAME = "*****"; $DB_PASS = "****"; $connection = mysql_connect($DB_SERVER, $DB_USERNAME, $DB_PASS); if (!$connection) die ('Could not connect:' . mysql_error()); mysql_select_db("content_MS",$connection); $query = "SELECT * FROM pages ORDER BY id ASC"; $result = mysql_query($query,$connection); $output = "<div>"; $output .= "<p>Select the page you would like to edit:</p>"; while($row = mysql_fetch_array($result)) { $output ="<ul>"; $output .= "<li>"; $output .= "<a href=\"manage_pages.php?page=" . urlencode($row["id"]) ."\">{$row["page_name"]}</a></li>"; $output .="</ul>"; } $output .="</div>"; return $output; } ?>
  5. Hey all, I am learning php and my first goal is to create a simple CMS. At the moment I am stuck on not being able to pull page names and their id`s from my DB and combine them into a list of links (like so/manage_pages.php?page_id=1) so I could grab id`s later for update and delete pages. Problem is when I load the page none of the links are displayed. My php5 is set up so that I could see all of the errors but there are none displayed nor is there anything in the log. Here are the function I am using: <?php function confirm_query($result_set) { if (!$result_set) { die("Database query failed: " . mysql_error()); } } 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 list_pages(){ global $connection; $result = get_all_pages(); $output = "<div>"; $output .= "<p>Select the page you would like to edit:</p>"; while($row = mysql_fetch_array($result)) { $output .="<ul>"; $output .= "<li>"; $output .= "<a href=\"manage_pages.php?page=" . urlencode($row["id"]) ."\">{$row["page_name"]}</a></li>"; $output .="</ul>"; } $output .="</div>"; return $output; } ?> Then I simply echo list_pages function on a page: <?php include ("includes/header.php"); ?> <div id="content"> <div class="in"> <h2>This is the main content</h2> <?php list_pages();?> </div> </div> <?php include ("includes/footer.php"); ?> And below is the html code I see when I load the page: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> <head> <title>Content Manager - Manage Pages</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <link rel="stylesheet" href="css/back_css.css" media="screen" /> </head> <body> <div id="wrapper"> <div id="header"> <div class="in"> <h1>Welcome To Your Content Manager!</h1> </div> </div> <div id="content-wrapper"> <div id="content"> <div class="in"> <h2>This is the main content</h2> </div> </div> </div> <div id="left"><div class="in"> <h2>Menu</h2> <ul> <li><a href="manage_pages.php?name=Manage Pages"> Manage Pages </a></li> <li><a href="manage_menu.php?name=Manage Menu"> Manage Menu </a></li> <li><a href="manage_albums.php?name=Manage Albums"> Manage Albums </a></li> <li><a href="manage_videos.php?name=Manage Videos"> Manage Videos</a></li> <li><a href="manage_gigs.php?name=Manage Gigs"> Manage Gigs </a></li> <li><a href="manage_news.php?name=Manage News"> Manage News</a></li> </ul> </div></div> <div id="footer"><span>by AB</span></div> </div> </body> </html> Any ideas ? Thanks in advance ! --best A
×
×
  • 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.