Hi Dani. I hope that I could get some help to fix a bit code.
Thanks.

Recommended Answers

All 6 Replies

Let's have a look at the code. Please include an explanation as to

  1. what the code is supposed to do
  2. what it actually does

If you are getting any error messages please include them (and the line number of the code causing the error).

Hi, nice to meet you. Looking forward to you posting your question. Hope you find DaniWeb helpful!!

commented: Thank you so much, Dani. +0

Hi Reverend Jim and thanks for your attention.
I expect that function retrieve from database list of items which 'parent' value is as I feed to function. For example suppose argument's I feed to function is 1, then this function selects all items which 'parent' columns value is equal to 1.
Unfortunately this function doesn’t do as I wish and the error message what I got is like following:

You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for
the right syntax to use near ''kategoria' WHERE 'parent' = '1' ORDER BY 'suo_kat' ASC' at line 1

I’ll be appreciated for all your help. Have a nice time. Phirux

Please post the code. If you are creating the query on the fly then please post the resulting query.

Don’t put single quotes around your SQL columns. So it should be WHERE parent = '1'

I’ll echo Rev Jim’s statement to please post the full SQL query because the error just shows the half of it after the syntax error occurred.

<?php
include ('connect.php');
include ('head.html');

echo '<div class="categ"><p class="b">Health</p>';
function retrieve_column($parent){
    $sql = "SELECT item FROM category WHERE parent = $parent ORDER BY item ASC";
    $r = mysqli_query($dbc, $sql);
        if (!$r) {
            echo "Couldn’t make a connection to DB.";
        } else {
            while($row = mysqli_fetch_assoc($r)){
                for ($i=0; $i < mysqli_num_rows($r); $i++) {
                    echo '<a class="text" href="">' . $row['item'][$i] . '</a><br />';
                }
            }
        }
    }

$par = 1;
retrieve_column($par);
mysqli_free_r($r);
mysqli_close($dbc);
?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.