1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[SQL] MySQL query returns more than expected [closed]

Discussão em 'Outras Linguagens' iniciado por Stack, Setembro 17, 2025.

  1. Stack

    Stack Membro Participativo

    I have a hardware database that has laptop types. A query runs through the known laptops types in a database and plots the amount of each laptop type on a web page.

    However, Laptops like 'Lenovo T14' and 'Lenovo T14_AC' are both plotted in the Lenovo T14 line... So it is not seen as a unique name. It does create a 'Lenovo T14_AC' as well, and that will show of course only, the real T14_AC's.

    I am probably missing the correct syntax for this query, but my English is not well enough to look for the exact issue. Here is the piece of code I use to plot the overview.

    // Computer type overview

    // Table header:
    echo '<p><font size="5"><b>Hardware Overview</b></font>
    <div class="d1">
    <table id="hwheaders" align="left" cellspacing="3" cellpadding="3" width="100%">
    <tr><th align="left"><b>Hardware Type</b></th><th align="left"><b>Number at customers</b></th><td align="left"><b>View List</b></th></tr>
    <tr><th align="left"><b>Hardware Type</b></th><th align="left"><b>Number at customers</b></th><td align="left"><b>View List</b></th></tr>
    <tr><th align="left"><b>Hardware Type</b></th><th align="left"><b>Number at customers</b></th><td align="left"><b>View List</b></th></tr>
    </table>
    </div>
    <div class="d1"><table align="left" cellspacing="3" cellpadding="3" width="100%">';

    $bg = '#eeeeee'; // Set the initial background color.

    while ($hwrow = mysqli_fetch_row($rhwtype))
    {
    $bg = ($bg=='#eeeeee' ? '#ffffff' : '#eeeeee'); // Switch the background color.
    echo '<tr bgcolor="' . $bg . '">';

    foreach ($hwrow as $item)
    {
    // plotting known hardware types
    echo '<td><small>' . htmlspecialchars($item) . '<td>';

    $qhwcount="select * from userdata where current_hardware='$item'";
    // counting the amount of each hardware type amongst users
    $rhwcount=mysqli_query($dbc,$qhwcount);
    echo mysqli_num_rows($rhwcount) . '</td>
    <td align="left"><small><input type="button" class="formbutton" onclick=window.location.href="search_client.php?keyname=' .$hwsearchstring = str_replace(' ','%20', $item) . '" value="View List" /></small></td>';

    }

    echo '</tr>';
    }


    Does anybody know which query syntax I should use to get the exact matches, and not the ones containing a part of the search term?

    Thanks!

    Regards Mike

    Continue reading...

Compartilhe esta Página