Hello:

I am wondering if there are any suggestions on how to pass variable to a div in the following manner:

foreach (array_combine($playerState_array_clean_phase2, $membId_stripped_array_clean_phase2) as $playerState_array_clean_phase2 => $membId_stripped_array_clean_phase2)  
{ 
echo"
<a href=\"#_MultiDataProcessor?Pid=$membId_stripped_array_clean_phase2&Plname=$lname&Pfname=$fname\" title=\"$membId_stripped_array_clean_phase2\"><span style='font-size:1.5em'>$playerState_array_clean_phase2</span></a>";
}

I want to get those variable in a div that looks like:

    <div class="iLayer" id="MultiDataProcessor" title="Multi-Player Rating Data">
<div class="iBlock">


<?php


    $Player_id=$_GET['Pid'];
    $fname=$_GET['Pfname'];
    $lname=$_GET['Plname'];

    ?>
    <!--Other code stuff goes here-->
  </div>

I appreciate any thoughts on this!
Mossa

Member Avatar for diafol

I can't see the relationship between the two code blocks. In the first block is the loop missing and echo?

Diafol, thanks for the reply! I have corrected the missing echo ...it was an oversight during posting.

With regards to the relationship:

The loop iterates and displays different values. the values are clickable and targeted to the div. Within the div, I have a php that is to receive three values passed from the links and perform further processing and display.

I know I could easily do this on a separate page, but for the purpose of this project, it needs to be done inside the div on the same page.

Member Avatar for diafol

I don't understand where this:

&Plname=$lname&Pfname=$fname

is coming from in the loop as the vars have not been initialised/set

&Plname=$lname&Pfname=$fname

these are defined outside the loop (before).

$fname =$_POST['fname'];
$lname = $_POST['lname'];   
Member Avatar for diafol

I'm a bit lost as to what isn't working for you, but maybe...

<?php if(isset($_GET['Pid']) && isset($_GET['Pfname']) && isset($_GET['Plname'])){ ?>
<div class="iLayer" id="MultiDataProcessor" title="Multi-Player Rating Data">
<div class="iBlock">
<?php
    $Player_id=$_GET['Pid'];
    $fname=$_GET['Pfname'];
    $lname=$_GET['Plname'];
    ?>
    <!--Other code stuff goes here-->
  </div>
  </div>
<?php } ?>  

The question is can I pass variable through an html anchor like so: (my attempts have failed. Specifically, with the link constructed as below, on click, it is unresponsive)

<a href=\"#_MultiDataProcessor?Pid=23232&Plname=mossa&Pfname=joe\" title=\"$membId_stripped_array_clean_phase2\">value</a>

the values are received and processed in a div on the same page

vs the tradional url

<a href=\"MultiDataProcessor.php?Pid=23232&Plname=mossa&Pfname=joe\" title=\"$membId_stripped_array_clean_phase2\">value</a>

whereas here, the values are received and processed in on a separate

Hi Mossa,

If you build the link as follows ...

echo "<a class=\"playerState\" href=\"\" data-pid=\"$membId_stripped_array_clean_phase2\" data-plname=\"$lname\" data-pfname=\"$fname\" title=\"$membId_stripped_array_clean_phase2\"><span style='font-size:1.5em'>$playerState_array_clean_phase2</span></a>";

... and build the HTML as follows (or similar) ...

<div class="iBlock">
    <p>PID: <span class="pid"></span></p>
    <p>First name: <span class="pfname"></span></p>
    <p>Last name: <span class="plname"></span></p>
    <!--Other code stuff goes here-->
</div>

... then you can use jQuery to acces the data in the links and display it in the div. For example:

$("a.playerState").on('click', function(evt) {
    evt.preventDefault();
    var $this = $(this);
    var $targetDiv = $('#MultiDataProcessor .iBlock');
    var pid = $this.data('pid');
    var plname = $this.data('plname');
    var pfname = $this.data('pfname');
    $targetDiv.find('.pid').text(pid);
    $targetDiv.find('.plname').text(plname);
    $targetDiv.find('.pfname').text(pfname);
});

This may not be exactly what you want but should give you some strong clues.

Airshow,

Thanks for your input and creative approach. I'll give it an attempt and report back shortly.

Mossa

the following:

<p>PID: <span class="pid"></span></p>
<p>First name: <span class="pfname"></span></p>
<p>Last name: <span class="plname"></span></p>

I need to get these values inside the div as php var

like so:

$Player_id="";//$_GET['Pid'];
$fname="";//$_GET['Pfname'];
$lname="";//$_GET['Plname'];

in other to perform further php processing

Mossa, "perform further php processing" implies one of three things :

  • Further page-building when the page is initially served
  • an AJAX operation performed in response to the <a ....> links being clicked
  • conventional hyperlinking in response to the <a ....> links being clicked.

Which is it?

Airshow,

I need those php var to perform the following:

    $Player_id=$_GET['Pid'];
    $fname=$_GET['Pfname'];
    $lname=$_GET['Plname'];

    $fullName=$lname.", ".$fname;//$_GET['phone'];
    //$result = array();        
    //echo $fullname.$Player_id;

    $dom = phpQuery::newDocumentFile("http://domainame/dir/dir2/dir3/players.asp?NSearch=$lname");        
    $match = $dom->find('td:contains("'.$Player_id.'") '); 
    $match_strip=strip_tags($match);//strip html from string
    $match_array=preg_split("/$\n?/m", $match_strip);//turn each newline in string into array of characters
    $match_array_clean_phase1 = array_map('trim', $match_array);//clean phase one
    $match_array_clean_phase2=array_filter($match_array_clean_phase1);//clean phase 2

Issue resolved! I decided to implement the conventional way of passing of var (via url to another page)... little more coding, but it is working.

I appreciate the feedback and suggestions.

Mossa

Mossa,

Well done. I understand the problem better now you have explained the solution!

Never mind, let's hope we have better luck next time.

Best wishes - also to Diafol (he of the Virtual Hosts).

Airshow

commented: Long time no write Airshow :) +14
Member Avatar for iamthwee

I would also avoid escaping your php quotes like that: \"
Just simply use single quote to achieve the same. Otherwise it gets real hard to read and debug.

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.