Home » Php » javascript – How to add search results in my website to cart page

javascript – How to add search results in my website to cart page

Posted by: admin February 25, 2020 Leave a comment

Questions:

I am facing this problem creating a cart page for my website, i have a search engine that displays records and i want to create a add to cart system for it before choosing the payment type..Am new to this ,so any help offered is deeply appreciated.

<?php
$button = $_GET ['submit'];
$search = $_GET ['search'];

if (!$button)
    echo "you didn't submit a keyword";
else {
    if (strlen($search) <= 1)
        echo "Search term too short";
    else {
        echo "You searched for <b> $search </b> <hr size='1' > </ br > ";
        $conn = mysqli_connect("localhost", "root", "", 'register');
        $search_exploded = explode(" ", $search);
        $x = 0;
        foreach ($search_exploded as $search_each) {
            $x++;
            $construct = "";
            if ($x == 1)

                $construct .= "keyword LIKE '%$search_each%' OR  job_type  LIKE '%$search_each%' OR  profession  LIKE '%$search_each%' ";
            else
                $construct .= "AND keyword LIKE '%$search_each%' OR  job_type  LIKE '%$search_each%' OR  profession  LIKE '%$search_each%' ";

        }
        $construct = " SELECT * FROM users WHERE $construct ";
        $run = $conn->query($construct);
        $foundnum = $run->num_rows;
        if ($foundnum == 0)
            echo "Sorry, there are no matching result for <b> $search </b>. </br> </br> 1. Try more keywords. for example: If you want to search 'For a person in the Banking Department' then use general keyword like 'Banking','Business','Finance' or if the person needed resides in the Information  technology Department, then use general keyword like 'I.T' ,'Information, technology','Informatics' etc. <br> </br> 2. Try different words with similar  meaning </br><br> 3. Please check your spelling";
        else {
            echo "$foundnum results found !<p>";
            $per_page = 10;
            $start = isset($_GET['start']) ? $_GET['start'] : '';
            $max_pages = ceil($foundnum / $per_page);
            if (!$start)
                $start = 0;
            $getquery = $conn->query("$construct LIMIT $start, $per_page");
            while ($runrows = $getquery->fetch_object()):

                echo "<h5>CV<b>{$runrows->id}</b></h5><br>";
                echo "<b>Gender</b>: {$runrows->gender}<br><br>";
                echo "<b>About</b> : {$runrows->about}<br><br>";
                echo "<b>Nationality</b>: {$runrows->nationality}<br><br>";
                echo "<b>Marital status</b>: {$runrows->marital_status}<br><br>";
                echo "<b>Languages spoken</b>: {$runrows->lang_spoken}<br><br>";
                echo "<b>Job Wanted</b> :{$runrows->job_type}<br><br>";
                echo "<b>Profession</b> :{$runrows->profession}<br><br>";
                echo "<b>Qualifications </b>: {$runrows->qualifications1}<br><br>";
                echo "<button type='button' class='btn btn-info btn-sm more-info' data-id='{$runrows->id}'>View & Request Cv</button> ";
                echo "<button type='button' class='btn btn-info btn-sm more-info' data-id='{$runrows->id}'>Add to cart</button>"; 

Also Attached is an image of the search results.

screenshot of the search results

How to&Answers:

You could add to cart with an anchor tag

echo "<a href='?id=$runrows->id'>Add to cart</a>";

This will add id parameter to the cart page which you can retrieve with $_GET