Jump to content

phpnewbe

New Members
  • Posts

    7
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

phpnewbe's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I changed it like this: function get_subject_by_id($subject_id) { global $connection; $query = "SELECT * "; $query .= "FROM pages "; $query .= "WHERE id= ' " . $subject_id . " ' "; $query .= "LIMIT 1"; $result_set = mysql_query($query, $connection); confirm_query($result_set); if ($subject = mysql_fetch_array($result_set)) { return $subject; } else {return NULL;} } Because here <?php require_once("includes/connection.php"); ?> <?php require_once("includes/functions.php"); ?> <?php if (isset($_GET['subj'])) { $sel_subj = $_GET['subj']; $sel_page = ""; } elseif (isset($_GET['page'])) { $sel_subj = ""; $sel_page = $_GET['page']; } else { $sel_subj = ""; $sel_page = ""; } $sel_subject = get_subject_by_id($sel_subj); ?> this function puts there $sel_subj. But I still get "Unknown column 'subject_id' in 'where clause'" error. Which doesn't make sense, because $sel_subj is not empty - it always has integer subject id in it. Maybe I should try to send you the whole code if that would make it easier to track?
  2. You right it's empty. And I don't know why. This is how it is being set: <?php if (isset($_GET['subj'])) { $sel_subj = $_GET['subj']; $sel_page = ""; } elseif (isset($_GET['page'])) { $sel_subj = ""; $sel_page = $_GET['page']; } else { $sel_subj = ""; $sel_page = ""; } $sel_subject = get_subject_by_id($sel_subj); ?> $sel_sub is passed to here function get_subject_by_id($subject_id) { $query = "SELECT * "; $query .= "FROM subjects "; $query .= "WHERE id=" . $subject_id; //$query .= "LIMIT 1"; $result_set = mysql_query($query); confirm_query($result_set); //if no rows are returned fetch_array will return false. if ($subject = mysql_fetch_array($result_set)) { return $subject; } else { return NULL;} } but it cannot be empty!
  3. I keep on getting this error message on my function: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LIMIT 1' at line 1. The function itself is: function get_page_by_id($page_id) { global $connection; $query = "SELECT * "; $query .= "FROM pages "; $query .= "WHERE id=" . $page_id . " "; $query .= "LIMIT 1"; $result_set = mysql_query($query, $connection); confirm_query($result_set); if ($subject = mysql_fetch_array($result_set)) { return $subject; } else {return NULL;} } My question is : where exactly is this mistake with SQL then? If I remove "LIMIT 1" I still get the message that there's something wrong with query. Thanks in advance
  4. Then if I uncomment those line in the function it works ( I get all the "menu_name" but stop getting output for page_name. That is another function : function get_pages_for_subject($subject_id) { global $connection; $query = " SELECT * FROM pages WHERE subject_id = {$subject_id} ORDER BY position ASC"; $page_set= mysql_query($query, $connection); confirm_query($page_set); return $page_set; I get SQL read error from here but the syntax is correct here, I think.
  5. Sorry this is the whole thing: Problem is that $sel_subject gives only the fist item from "menu_name", but I need them all. And this is the function: function get_subject_by_id($subject_id) { global $connection; $query = "SELECT * FROM subjects"; //$query = "SELECT * "; //$query .= "FROM subjects "; //$query .= " WHERE id=" . $subject_id . " "; //$query .= " LIMIT 1"; $result_set = mysql_query($query, $connection); confirm_query($result_set); if ($subject = mysql_fetch_array($result_set)) { return $subject; } else {return NULL;} } function get_subject_by_id2($subject_id) { echo $subject_id; }
  6. I cannot figure out how to properly read from query into the browser. I want to read from table "subjects" in mySQLdb and have browser output "menu_name" field from there. This is the code of the function that does query: function get_subject_by_id($subject_id) { global $connection; //$query = "SELECT * FROM subjects"; $query = "SELECT * "; $query .= "FROM subjects "; $query .= "WHERE id=" . $subject_id . " "; $query .= "LIMIT 1"; $result_set = mysql_query($query, $connection); if ($subject = mysql_fetch_array($result_set)) { return $subject; } else {return NULL;} } It is called from here: <?php require_once("includes/connection.php"); ?> <?php require_once("includes/functions.php"); ?> <?php if (isset($_GET['subj'])) { $sel_subj = $_GET['subj']; $sel_page = ""; } elseif (isset($_GET['page'])) { $sel_subj = ""; $sel_page = $_GET['page']; } else { $sel_subj = ""; $sel_page = ""; } $sel_subject = get_subject_by_id($sel_subj); ?> The output goes from here: <table id="structure"> <tr> <td id="navigation"> <ul class="subjects"> <?php $subject_set = get_all_subjects(); while ($subject = mysql_fetch_array($subject_set)) { echo "<li"; if($subject["id"] == $sel_subj) { echo " class=\"selected\""; } echo "><a href=\"content.php?subj=" . urlencode($subject["id"]). "\">{$subject["menu_name"]}</a></li>"; //content.php?subj= - sends coorect id to the browser,but I get only first "menu_name" to show// Then $sel_subject supposed to echo every "subject name" here: <h2><?php echo $sel_subject['menu_name']; ?></h2> Instead I get only the first "menu_name" item put out. But I want them all to be read out of the table. And as I click on other "subjects" there is no output.( I'll greatly appreciate some help here. What am I doing wrong?
×
×
  • 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.