Hallo!

I would like to create a script to search a MySQL table (data). The table has two columns (ID & PRICE). Search must be done by ID and Price has to be displayed in the page, any ideas?

Thanks in advance!

PS: I've tried to modify this script but i failed .. I will be grateful if can help me!

What exactly do you need help with?

I need help with editing that script . i dont have idea of mysql so i try here

If you have specific questions about parts of that script, paste code snippets and your questions.

I use this code to search my DB. When the search field is submitted you are directed to mydomain.com/search.php?search=search_term. I then get the search term using $_GET['search'] and query my SQL database using:

id like '%".$txtsearch."%' OR server_name like '%".$txtsearch."%' OR ip like '%".$txtsearch."%' or administrator like '%".$txtsearch."%' OR url like '%".$txtsearch."%'

Here's the search function in full (excluding how I display my results).

$txtsearch="";
            if (isset($_GET["btnsearch"])=="Search") 
            {
                        $txtsearch=$_GET['search'];
                        $count_query="SELECT * FROM servers WHERE active = '1' AND enabled = '1' AND ( id like '%".$txtsearch."%' OR server_name like '%".$txtsearch."%' OR ip like '%".$txtsearch."%' or administrator like '%".$txtsearch."%' OR url like '%".$txtsearch."%' ) ORDER BY vote_count DESC; ";

                        $select_query=" SELECT * FROM servers WHERE active = '1' AND enabled = '1' AND ( id like '%".$txtsearch."%' OR server_name like '%".$txtsearch."%' OR ip like '%".$txtsearch."%' or administrator like '%".$txtsearch."%' OR url like '%".$txtsearch."%' )  ORDER BY vote_count DESC
                                limit $eu, $limit ";
            }

I tryed to do it myself with your example and with my knowledge and that is. If i miss something or something is wrong..

<?php
    $con = mysqli_connect('host','username', 'password') or die(mysqli_error($con));
    mysqli_select_db($con, 'database') or die(mysqli_error($con));


    #query database
    $query = mysqli_query($con, "SELECT id,price FROM data ORDER BY id");


    #check for a result set
    if($query && mysqli_num_rows($query) > 0)
    {
        while($res = mysqli_fetch_assoc($query)) 
        {
            echo "{$res['id']}:The price is {$res['price']},<br />";
        }
    }
    else #if no result set, then output a message
    {
        echo 'No results.';
    }
    ?>
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.