'Why is my query not returning the values I asked for?
I am attempting to display the information from my mysql on my page but I am only getting the query itself in return.
<?php
session_start();
//Title info
$page_title="Curriculum Search";
//require connection to page
require('db_connect.php');
//MySQL queries to get list of courses, course desc, and professors
$q="SELECT course_id FROM courses";
$r=mysqli_query($dbc,$q);
echo $q;
?>
I later want to populate a dropdown menu with my information but I just want to make sure that it is working before I move forward.
I have tried:
echo $r
echo '$q'
and
echo '$r'
Solution 1:[1]
what your code is missing is this
<?php
session_start();
//Title info
$page_title="Curriculum Search";
//require connection to page
require('db_connect.php');
//MySQL queries to get list of courses, course desc, and professors
$q="SELECT course_id FROM courses";
$r=mysqli_query($dbc,$q);
while ($row = $r->fetch_assoc()) {
echo $row["course_id"];
}
?>
I do recommend that you read the documentation that was posted on the comment section tho, is not good to just copy paste code without understanding what you are doing. This is something so simple that theres no reason for you to be struggling with this.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
