tags:

views:

2085

answers:

3

I am having a problem in my php. What I'm trying to do here is, that I have a .html which directs to an external .js and this js file open up a .php The php extracts data from mysql tables and xml and displays the data on the webpage, (in .html form as table rows). Now when a user clicks on any row, I want that php should open up a new window and I want to display some more data from the same mysql and xml on it (the new window)

for($k=0;$k<=$x->length-1;$k++)
{
    for($l=0;$l<=$j-1;$l++)
    {
        if($y->item($k)->nodeValue==$JobNoArr[$l])
        {
            $m++;
            if ($m%2==0)
                {$a="#A5ADEA";}
            else 
                {$a="#D1D1D3";}

            //form_html1+="<tr onclick='show(" + x + ")' bgcolor="+ y +">";
            echo "<tr bgcolor=". $a .">";
            echo "<td>" . $m . "</td>";
            echo "<td>" . ($y->item($k)->nodeValue) . "</td>";
            echo "<td>" . ($TitleArr[$l]) . "</td>";
            echo "<td onclick=show(".$u->item($k)->nodeValue.")><i><font size=2>Click for Abstract</font></i></td>";
            echo "<td>" . $uu . "</td>";
            echo "</tr>";
        }
    }
}

If I use echo "<td onclick=show() " it opens the show function in the .js file but if I use echo "<td onclick=".show()."... " it opens the function in php itself but without the onclick functionality.

I don't know if have been able to clearly explain my problem here, but if you can help me in this, please do so.

+2  A: 

you can probably use YUI to create a floating dialog that is hidden, and contains the data for the "abstract" . Default to hiding all the abstracts for all the items on the page. Your js show function can just set that YUI element visible when the user clicks on the item. You won't even need to open a new browser window.

Zak
+2  A: 

You don't want to actually "do this in PHP", you're going to do it with JavaScript. PHP is a server-side technology, and what you want to do needs to happen on the client side (browser). There are a few different ways you can go about this; the method I outline below uses very little JavaScript.

First of all, you need to rewrite your onClick as follows:

echo "<td onClick=\"return show('".$u->item($k)->nodeValue."');\"><i><font size=2>Click for Abstract</font></i></td>";

We are going to use the window.open function to actually pop up a new window - this will require that you create a new PHP script that can display the data you want to show, given the specified row ID or some other identifier. In this case, your show function would be something like this:

I've updated the example below to be output from within PHP

echo "
 <script type=\"text/javascript\">
 <![CDATA[
   function show(rowid, arrno) {
     window.open(
       'showAbstract.php?rowid='+rowid+'&rowid2='+arrno,  // the url to the php script
       'somenameforthewindow',                            // some name for the window
       'status=0,width=100,height=100'                    // display options for the window
     );
     return false;
   }
 ]]>
 </script>";

Your PHP page should grab the $_GET['rowid'] parameter, lookup the appropriate data, and format/print it as you would like it to appear.

You could actually embed all your data in JSON and use DHTML and CSS Layers to have a similar effect without additional windows. If you would like, I can post an example of this.

Dustin Fineout
Thank you so much for such a detailed answer Dustin. I was trying to use the code. but it still gives an error:missing ) after argument list it was giving the same error before too.
Zeeshan Rang
That error isn't being caused by anything in the source above. That error usually indicates you missed a comma (,) after a parameter before listing another parameter. For example, if I had missed the comma after 'somenameforthewindow' above before going to the next line and listing the display option parameter. Take a look through the rest of your code to see if you can't find a place you missed a comma.
Dustin Fineout
Sorry, actually if I had missed the comma I mentioned it *would not* show that error, because that code is javascript (not PHP). This made me realize, though, that you might be trying to past the javascript directly in your PHP as PHP. I've updated my answer to show you how to print it to the page in PHP, just in case that is what you were doing.
Dustin Fineout
Dustin, it still gives the same error. but if i try to run my code without any argument in it.. i mean show().. then it runs and opens up a new window. but if i put in the argument, it give me the same error
Zeeshan Rang
Ya, i have been able to resolve that error using ':show('".$u->item($k)->nodeValue."');\">
Zeeshan Rang
Ah, ok. I should not have assumed that nodeValue was an integer.
Dustin Fineout
Dustin can you plz tell me how can i pass two values to a php:function show(jobno,arrno) { window.open( 'phpwithmysql11111.php?rowid='+jobno,'rowid2'=+arrno, // the url to the php script 'tesing', // some name for the window 'status=0,width=100,height=100' // display options for the window ); return false;I am trying to do something like this. but i know it is wrong
Zeeshan Rang
Dustin Fineout
I also updated the answer to reflect the fix with the quotes in the show() function call.
Dustin Fineout
A: 

Like said above, you'd want to use a javascript modal window to display the content. You can (with most modal windows anyway) use PHP code in the modal window, allowing you to use the same MySQL and XML, but PHP as a server-side technology cannot open a new window without refreshing the page or opening a new page entirely.

If you use jQuery (which I reccommend), I would suggest Facebox as a great, lightbox-style modal window that you can easily use and even customize yourself.

Hope this helps.