Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Nov 2008
    Posts
    175
    Thanks
    4
    Thanked 6 Times in 6 Posts

    Calling variables

    I want to call this to my website but it doesn't display what I want it to,

    Code:
    <h5>Edit Subject: <?php echo $sel_subject['menu_name']; ?></h5>
    If I change the $sel_subject to $sel_page it works, but both are using the exact same names in the database and have exactly the same code in my functions.php

    Can anyone help?

    functions.php
    Code:
    function get_subject_by_id($subject_id) {
    		global $connection;
    		$query = "SELECT * ";
    		$query .= "FROM subjects ";
    		$query .= "WHERE id=" . $subject_id ." ";
    		$query .= "LIMIT 1";
    		$result_set = mysql_query($query, $connection);
    		confirm_query($result_set);
    		// REMEMBER:
    		// if no rows are returned, fetch_array will return false
    		if ($subject = mysql_fetch_array($result_set)) {
    			return $subject;
    		} else {
    			return NULL;
    		}
    	}
    	
    	function get_page_by_id($page_id) {
    		global $connection;
    		$query = "SELECT * ";
    		$query .= "FROM pages ";
    		$query .= "WHERE subject_id=" . $page_id ." ";
    		$query .= "LIMIT 1";
    		$result_set = mysql_query($query, $connection);
    		confirm_query($result_set);
    		// REMEMBER:
    		// if no rows are returned, fetch_array will return false
    		if ($page = mysql_fetch_array($result_set)) {
    			return $page;
    		} else {
    			return NULL;
    		}
    	}
    	
    	function find_selected_page () {
    		global $sel_subject;
    		global $sel_page;
    		if (isset($_GET['subj'])) {
    			$sel_subject = get_subject_by_id($_GET['subject']);
    			$sel_page = NULL;
    		} elseif (isset($_GET['page'])) {
    			$sel_subject = NULL;
    			$sel_page = get_page_by_id($_GET['page']);
    		} else {
    			$sel_subject = NULL;
    			$sel_page = NULL;
    		}
    	}
    
    	
    	function navigation($sel_subject = null, $sel_page = null) {  
    		$subject_set = get_all_subjects();
    		// 5. Use returned data
    		while ($subject = mysql_fetch_array($subject_set)) { 
    			
    		echo "<div class=\"menu-name\">";  echo "<a href=\"edit_subject.php?page=" . urlencode($subject["id"]) .
    			"\">{$subject["menu_name"]}</a>";  echo"</div>";
    		echo "<div class=\"buying-text\">";  echo "{$subject["content"]}";  echo"</div>";
    		
    		echo "<div class=\"image\">"; echo"</div>";
    		
    		}
    	}
    Thanks,
    Josh

  • #2
    Regular Coder
    Join Date
    Apr 2005
    Location
    Ohio
    Posts
    254
    Thanks
    1
    Thanked 63 Times in 63 Posts
    What do you mean by "doesn't display what I want it to"?
    Is it:
    i) returning some data but not the data you want or
    ii) not returning anything at all?

  • #3
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    Quote Originally Posted by j05hr View Post
    I want to call this to my website but it doesn't display what I want it to,
    I was about to complain that your statement doesn't make any sense, and it still doesn't, but I think I see your problem. In find_selected_page():

    PHP Code:
    if (isset($_GET['subj'])) {
        
    $sel_subject get_subject_by_id($_GET['subject']); 
    You're using a different array index in the GET vars.
    Are you a Help Vampire?

  • #4
    Regular Coder
    Join Date
    Nov 2008
    Posts
    175
    Thanks
    4
    Thanked 6 Times in 6 Posts
    Sorry that wasn't a very good explanation, I meant it doesn't display the content from the database. I solved it now, the problem was in the function navigation the url was edit_subject.php?page when it should be edit_subject.php?subj


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •