I am not a backend dev but a front end, yet I am trying to create a simple php search, I have followed the tutorial on here and made the changes for the deprecated bits it had. I have a database with sub rows and columns and I am trying to get some of the data from them:
The first thing is I created the html
<form action="search.php" method="GET">
<input type="text" name="query" />
<input type="submit" value="Search" />
</form>
Then the php bit:
$con = mysqli_connect("localhost", "USER", "PSW", "DBNAME") or die("Error connecting to database: ".mysqli_error());
$query = $_GET['query'];
$min_length = 3;
if(strlen($query) >= $min_length){
$query = htmlspecialchars($query);
$query = mysqli_real_escape_string($con, $query);
$raw_results = mysqli_query($con, "SELECT * FROM article
WHERE (`title` LIKE '%".$query."%') ") or die(mysqli_error($con));
if(mysqli_num_rows($raw_results) > 0){
while($results = mysqli_fetch_array($raw_results, MYSQLI_ASSOC)){
echo "<p><h3>".$results['page_id']."</h3>".$results['title']."</p><p>".$results['space']."</p>";
}
}
else{
echo "No results";
}
}
else{
echo "Minimum length is ".$min_length;
}
The above is fine and it gives me the article title and article id I have within my DB. Yet I need to get the space and the year. Attached is the DB structure:
By reading around and by looking at what my backend dev did back then, i can see this line somewhere else which should get on the right track if it ever helps.
$query = "SELECT A.id AS article_id, A.title AS title, C.name as space, A.page_id, T.year, T.month, T.id as time_id FROM article AS A INNER JOIN space AS S ON S.article_id = A.id INNER JOIN country AS C ON C.id = S.country_id INNER JOIN time AS T ON A.id = T.article_id WHERE (T.year BETWEEN ".$year_start." AND ".$year_stop.") GROUP BY A.title, C.name";


spacecolumn"<p><h3>".$results['page_id']."</h3>".$results['title']."</p><p>".$results['original_name']."</p>";i get no name for the space, no erros