store and call specific mysql records from a query in a javascript window.open() function

Ron McCain
Ron McCain used Ask the Experts™
on
we have a ajax, php,mysql search script that gets records from a mysql dbase and list them in a table. the user can then select any of the found items and have a detail page returned.

we have a typical href script working to do this however what we need is to open the found item detail page(s) in a new browser window using the window.open() function.

We have this working, however selecting the window.open() function for any of the found items always calls the last record found when the query ran.

Below is the script producing this result, please assist so that we can get the window.open() to get the correct found item record.


.....mysql connects and queries database..............

while($row=mysql_fetch_array($sql))
{

      
?>
<font size=2 color="#000000" face="Arial">
<div align="left"><table width="100%" border="1" cellpadding="0"  cellspacing="0" bgcolor="#ffcc99">
<td width="95"><font size=2 color="#000000" face="Arial">
<div>Issue Date:</div>
</font>
</td>


<?php

$_SESSION['mainproduct']=$row['brand_wwb'];
$_SESSION['prod_selected_pkid']=$row['prodwwb_pkid'];


=====this script calls detail page and sends correct id for the appropriate found item

$prodsec1= "http://192.x.x.x/url_path/".$row['brand_wwb']."/".$row['type_wwb']."/".$call_detail_page."?prodwwb_pkid=".$row['prodwwb_pkid'].'">';



?>
<script type="text/javascript">
function open_win_article()
{
            
      window.showModelessDialog('<?php echo $prodsec1; ?>','<?php echo $prodsec1; ?>',"dialogHeight: 725px; dialogWidth: 850px; dialogTop: 150px; dialogright: 450px; edge: Raised; center: yes; help: No; scroll: yes; status: no;")
      
}

</script>

<input type="button" value="Review This Item" onclick="open_win_article()" />

<td width="434"><?php echo $row['model_wwb']; ?> <br />
</td>
</tr>

=========
As stated with the above script we  always get the last found item record from the query, and to restate, a typival href() script always works to get the correct found item as selected from the found item display table.

We can provide more info if need, we are in a bit of a hurry so any fast help will be appreciated.
Thanks
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2011
Top Expert 2016
Commented:
Please post the CREATE TABLE statements and the URL of the page that fails, thanks.

Author

Commented:
database is extremely large and work perfectly in all function except this, I think we just need help on making the query records available to the window.open(), the URL is on our dev server.

anyone else please.....
There is too few code for me to understand the full mechanincs about the way you are feeding the data to open_win_article(); from what I can see it will always call the LAST url generated $prodsec1 .. which will be the last row returned by the sql query.

Try feeding the data straight to js function

function   open_win_article(url) {
window.showModelessDialog(url,url,"dialogHeight: 725px; dialogWidth: 850px; dialogTop: 150px; dialogright: 450px; edge: Raised; center: yes; help: No; scroll: yes; status: no;")

}

Open in new window


when you generate the table in the while loop
feed the url with php echo to every input button
Most Valuable Expert 2011
Top Expert 2016

Commented:
Let me try this one more time, thanks.
Please post the CREATE TABLE statements and the URL of the page that fails, thanks.
Chris AshcraftSenior Analyst - Technology

Commented:
Kind of hard to troublehoot with the information given, but it sounds to me like it might be a browser caching issue. Try appending a timestamp or random number to the end of the URL in the window.open command. Something like &dt=(current datetime string)

Author

Commented:
sorry for the slim explaination to start, I wanted to get the basic issue out there. the problem is that the variable $prodsec1 contains composite variables concantonated from a search request database query. Using an href statement to make a link to get a found item as selected by a user works well and the href tag is called only once and is in sync with the query for each specific found item from the search. When we plug in the window.open() function , use the input type button and use the same  url composite variable $prodsec1 containing the same concantonated variables from a search request database query,  the variable $prodsec1 does not hold the progressive values associated with each button displayed as does the href links that display. I think we must need to store each $prodsec1 separately as the search query is produced and then make them avialable to the window.open() func.?
We need to get the input type buttons associated with the window.open () working like the href links do which is to say the links hold the correct url and variables to call a detail page for each different search item found.
Thanks

Author

Commented:
BTW, we are trying the suggestions made so far, and thanks for providing them.
Most Valuable Expert 2011
Top Expert 2016

Commented:
Last time I am going to ask:

Please post the CREATE TABLE statements and the URL of the page that fails, thanks.

Author

Commented:
Thanks everyone, we solved this here with help from asavah in house, as we suspected we just needed to rearrange the location in the while loop, store the variable then share with the function. Thanks to all who offered ideas. For those who wanted tables and urls etc, we didn't intend to ignore your offer to help but getting  what you ask would not have helped us but we do appreciate the response
Thanks again

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial