/    Sign up×
Community /Pin to ProfileBookmark

handling onclick window.open

hi,

i have a mysql table called footers.it’s fields are as follows
id–caption–content
1–aboutus–some company info
2–privacy–privacy info
3–copyright–copyright info

here i retrieved all the captions from table and print in the footer position on my form as footer menu.what i want to do actually is when i click aboutus,it should open small window and display the aboutus content from mysql table,similarly when i click privacy,it should open a small window and should display privacy info like that.everything i did,but when i click aboutus,it shows all the three records from table.i want to display uniquely.means if i click aboutus it should display only aboutus info in small window like that..any of your help will be greatly appreciated

here is my code
<?php
$conn4=mysql_connect(“localhost”,””,””);
mysql_select_db(“jrm”,$conn4);
$sql=”SELECT * FROM footers”;
$result=mysql_query($sql,$conn4) or die (mysql_error());
echo “<center><table border=’0′ style=’text-align:left;’><tr>”;
while($newarray=mysql_fetch_array($result))
{
$caption=$newarray[‘caption’];

echo “<center><a style=’text-decoration:underline;’

href onclick=window.open(‘xyz.php’,”,’top=200,left=350,screenY=0,screenX=0,width=400,height=300,scrollbars=yes’);>
<td><font color=’white’><b>”.$caption. “&nbsp;&nbsp;</b></font></td></a></center>”;
}
echo “</tr></table></center>”;
?>

xyz.php
——

<?php

$conn4=mysql_connect(“localhost”,””,””);
mysql_select_db(“jrm”,$conn4);
$sql=”SELECT * FROM footers”;
$result=mysql_query($sql,$conn4) or die (mysql_error());
while($newarray=mysql_fetch_array($result))
{
$caption=$newarray[‘caption’];
$content=$newarray[‘content’];

echo “<center><b><u><font color=’navy’>”.$caption.”</font></b></u><br><font color=’green’>”.$content.”</font></center>”;
}

?>

is it possible without using xyz.php file,i will display the $content in small window directly

thanks
mrjameer

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@NightShift58Jan 07.2007 — There would be ways to do something with AJAX, but since you want a new window anyway, there would be no need to go through all the trouble.

The problem right now is that xyz.php doesn't know what you want it do in each special case. Try the following:[code=php]<?php
$conn4=mysql_connect("localhost","","");
mysql_select_db("jrm",$conn4);

$sql="SELECT * FROM footers";
$result=mysql_query($sql,$conn4) or die (mysql_error());

echo "<center><table border='0' style='text-align:left;'><tr>";
while($newarray=mysql_fetch_array($result)) {
$caption=$newarray['caption'];

echo "<center><a style='text-decoration:underline;'
href onclick=window.open('xyz.php?cap=" . urlencode($caption) . "','','top=200,left=350,screenY=0,screenX=0,width=400,height=300,scrollba rs=yes');>
<td><font color='white'><b>".$caption. "&nbsp;&nbsp;</b></font></td></a></center>";
}
echo "</tr></table></center>";
?>


xyz.php
------
<?php
$conn4=mysql_connect("localhost","","");
mysql_select_db("jrm",$conn4);

$sql = "SELECT * FROM footers";
IF (isset($_GET['cap']) and $_GET['cap'] <> "") :
$sql .= " WHERE caption = '" . mysql_real_escape_string($_GET['cap']) . "'";
ENDIF;
$result=mysql_query($sql,$conn4) or die (mysql_error());

while($newarray=mysql_fetch_array($result)) {
echo "<center><b><u><font color='navy'>" . $newarray['caption'] . "</font></b></u><br><font color='green'>" . $newarray['content'] . "</font></center>";
}
?>[/code]

The changes mades are in [b]onclick[/b] where I changed/added [b]xyz.php?cap=" . urlencode($caption)[/b] and in [b]xyz.php[/b] where we now ask what parameter was passed.
×

Success!

Help @roshanjameer spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...