Andrew Nevins
(@anevins)
WCLDN 2018 Contributor | Volunteer support
Because the get_results function returns an array
Thread Starter
cuk
(@cuk)
Thanks, but I bumped into another problem. The previous piece of code was written in a page template together with an HTML form. I didn’t know which URL to put into the action attribute, so I made a new PHP file called database_list.php (in the child theme folder):
<?php
if (isset ($_GET['upis'])&&!empty($_GET['upis'])){
$upis=$_GET['upis'];
$mocnesi=$wpdb->get_var("SELECT engleski, prijevod FROM rjecnik WHERE id = $upis");
echo $mocnesi;
}
?>
And I moved the form code into the main page:
<form action="database_list.php" method="get">
Upisite rijec!
Trazena rijec: <input type="number" name="upis">
<input type="submit" value="Trazi">
</form>
I don’t know how to return the $mocnesi value found by the query to html to display. Any help?
Andrew Nevins
(@anevins)
WCLDN 2018 Contributor | Volunteer support
Have you tried looping through it using a “foreach” PHP loop?
http://php.net/manual/en/control-structures.foreach.php
Thread Starter
cuk
(@cuk)
I had problems with picking the right array type. Works with associative. Thanks!