-2

I have a php Mysql interaction and i wish to trigger the Mysql Search through an ONCLICK event.

iv thought about using a JS function or JQ and parsing the ID of selected through JS function but then im unsure as how i would re-execute the php to re-search the database with the new JS Veriable...

The code below is accurate and is what im working with...

How would i re execute the php with the new ID.. Much appreciated..

<div class="contentheader">
    <header> Welcome Please Choose a Catagory</strong></header>
</div>

<div id='smallpagination' class='smallpagination'>
    <?php

    //search according to chosen search critera NOT LIMITED//
    include("conect.php");

    $startit = 0;

    $startfrom = rand(0, 20);

    $displayto = $startfrom + 10;
    $search = "";

    $startedfrom = $startfrom;

    $sql = "SELECT * FROM testdata 
      WHERE title LIKE '%%$search%%'
      LIMIT $startfrom , $displayto";

    // check how many results //
    $result = $conn->query($sql);
    $row_cnt = $result->num_rows;

    while ($row = mysqli_fetch_assoc($result)) {
        $videos = $row['videos'];

        $v_id = $row['id']; //<!---important is Video ID and needed for video click selection---->

        $id = $row['id'];

        $Name = $row['Name'];
        if (empty($Name)) {
            $Name = 'Annonymous';
        }

        $image = $row['image'];

        $info = $row['info'];
        if (empty($info)) {
            $info = 'Contact Listee (if Provided) , No Item Information Given';
        }

        $phone = $row['phone'];
        if (empty($phone)) {
            $phone = 'See Listing';
        }

        $title = $row['title'];
        $locate = $row['locate'];
        if (empty($locate)) {
            $locate = 'Not Provided';
        }

        $postcoded = $row['postcode'];
        if (empty($postcoded)) {
            $postcoded = '???';
        }

        $price = $row['price'];
        if (empty($price)) {
            $price = '?';
        }

        if ($price == '0') {
            $price = '?';
        }

        $date = $row['stamp'];
        if (empty($date)) {
            $date = '';
        }

        if ($startit < 1) {
            $gotid = $row['id'];
            $startit = $startit + 1;
        };

        $vidd = $row['id'] - 0.01;
        $pidd = $row['id'] - 0.02;
        $type = $row['type'];
        $showinglocate = $row['id'] - 0.03;
        $showingphone = $row['id'] - 0.04;
        $displaytype = "minlist";

        //Thumbnails sized listings
        if ($displaytype == "minlist") {

            echo "
            <div class='floaterminhomepage'>
            <div class='innerfloaterminhomepage' >";

            if (!empty($videos)) {

                echo "
                    <video id='$v_id' style='position:absolute;  top:0%; left:0%; width:100%; height:100%; background-size: cover; object-fit:fill;' preload='metadata' onclick='showdata({$v_id});'>

                    <source src='vid/{$row['videos']}.mp4' type='video/mp4'>
                    <source src='vid/{$row['videos']}.mp4' type='video/ogg'>
                    <source src='vid/{$row['videos']}.mp4' type='video/webm'>
                    </video >";
            }

            if (empty($videos)) {
                echo "<img id='$vidd' src='pageimages/blank.png' style='position:absolute; top:0%; left:0%;  width:100%; height:100%;'>";
            }

            echo "
            </div> 
            </div> 
            ";
        }
    };


    ?>

</div> <!---smallpagination--->


<script>
  ------ > SHOWDATA
  RETRIEVE
  ID
  SCRIPT
  HERE < -----
</script>

Then re-execute the folling php

----HOW WOULD I GO ABOUT THIS RE_EXECUTION.

<?php

$displayto = $startfrom;

$sql = "SELECT * FROM testdata
WHERE id={$gotid};
";

// check how many results //
$result = $conn->query($sql);
$row_cnt = $result->num_rows;
while ($row = mysqli_fetch_assoc($result)) {
    $videos = $row['videos'];
    $v_id = $row['id']; //<!---important is Video ID and needed for video click selection---->
    $Name = $row['Name'];
    if (empty($Name)) {
        $Name = 'Annonymous';
    }

    $image = $row['image'];
    $info = $row['info'];
    if (empty($info)) {
        $info = 'Contact Listee (if Provided) , No Item Information Given';
    }

    $phone = $row['phone'];
    if (empty($phone)) {
        $phone = 'See Listing';
    }

    $title = $row['title'];

    $locate = $row['locate'];
    if (empty($locate)) {
        $locate = 'Not Provided';
    }

    $postcoded = $row['postcode'];
    if (empty($postcoded)) {
        $postcoded = '???';
    }

    $price = $row['price'];
    if (empty($price)) {
        $price = '?';
    }
    if ($price == '0') {
        $price = '?';
    }

    $date = $row['stamp'];
    if (empty($date)) {
        $date = '';
    }

    $type = $row['type'];
};


echo "<div id='smallpagdata' class='smallpagdata'>

ID={$v_id}<br>
NAME={$Name}<br>
TITLE={$title}<br>
INFO={$info}<br>
PHONE={$phone}<br>
LOCATION={$locate}<br>
PRICE={$price}<br>
Listed={$date}<br> 

</div>";

?>
olibiaz
  • 2,551
  • 4
  • 29
  • 31
Shane Dee
  • 1
  • 4
  • TL;DR , Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. – Zakaria Acharki Dec 18 '17 at 19:03
  • Look into AJAX calls and requests. – aynber Dec 18 '17 at 19:04
  • if i change to Ajax i have tyo re-write the PHP eitherway , and then i still need to re-execute it. Its trhe re-running im having trouble with... Eithere PHP or JS... But i get what your saying. Create a JS version of the mysql and display. But id rather keep it as php as im not familure with JS. How do i tell that php script to re-run itself . Il look into AJAX eitherway and thanks – Shane Dee Dec 18 '17 at 19:06
  • It is really old school, but you could have a form that goes to the same page that has a hidden input of all the data you need and a submit with a value like true, then you could capture that post data and have something like if($submit) { script to re-execute } – tbedner Dec 18 '17 at 19:24

1 Answers1

1

Does "NO POST" mean "no GET" as well? Otherwise you could put your retrieval script in a different file and call that with jQuery.get or XMLHttpRequest.

  • Im open to options, But i just thought there would be simple way of activating that same PHP script with an onclick event.. Like a JS function call that retrieve the value and then passes it to the php upon the php then runs itself again. – Shane Dee Dec 18 '17 at 19:12
  • Since PHP is a server-side language, it gets executed on the server. In contrast to JavaScript, which gets executed in the users browser. This means the only PHP JavaScript will see is the result of the PHP-script, if any. It is not possible to 'run' PHP-code within JavaScript, as far as I'm aware. – Alen Androsevic Dec 18 '17 at 19:19
  • It dont have to be Js either though, It could be strictly PHP. but how do i run the php from an ONLICK event.... – Shane Dee Dec 18 '17 at 19:21
  • You cannot, unless you utilize AJAX. See [this](https://stackoverflow.com/questions/13840429/what-is-the-difference-between-client-side-and-server-side-programming) question for more information. – Alen Androsevic Dec 18 '17 at 19:23
  • Yeah, after simple research it seems that AJAX or a post form is the likley, But i also dont want the page refreshing. so il have to do a little more digging. But thanks guys. – Shane Dee Dec 18 '17 at 19:26