How To: PHP + Javascript Pop-up Window - php

I have the following code that gives me a list of items on the front-end, but I want those links to open in a new pop up window. Is there a way I can do this?
Thank you.
echo '<div class="item_row_header">';
for($i=0;$i<count($this->fields);$i++) {
echo '<div class="item_cell jdheader'.$this->fields[$i]->cssclass.'">';
//to display the header with/without sorting option
if(in_array($this->fields[$i]->type, array(10,11,12,13)))
echo $this->fields[$i]->name;
else
echo JHTML::_('jdgrid.sort', $this->fields[$i]->name, 'field_'.$this->fields[$i]->id, #$this->cparams->filter_order_Dir, #$this->cparams->filter_order );
echo '</div>';
}
echo '<div class="clr"></div></div>';
}
echo '<div class="itemlist itemlist_type'.$this->type->id.'">';
if(count($this->items)) {
//all the item list part display here
for($i=0;$i<count($this->items);$i++) {
$item = $this->items[$i];
require(dirname(__FILE__).DS.'default_item.php');
}
Here is what I get on the front-end with the code above:
<div class="item_row_header">
<div class="item_cell jdheader">Título</div>
<div class="item_cell jdheader">Fotos</div>
<div class="item_cell jdheader">Cidade</div>
<div class="item_cell jdheader">Estado</div>
<div class="item_cell jdheader">Tipo do Imóvel</div>
<div class="item_cell jdheader">Valor R$</div>
<div class="clr"></div>
</div>
<div class="itemlist itemlist_type15">
<div class="item_row_bg featured itemrow_type15">
<div class="item_content">
<div class="item_cell ">Temporada Destaque</div>
<div class="item_cell "><img src="http://mysite.com.br/joomla/images/joomd/thumbs/1350654862temporada-destaque.jpg" alt="Fotos" /></div>
<div class="item_cell ">Exemplo de Cidade</div>
<div class="item_cell ">São Paulo</div>
<div class="item_cell ">Casa</div>
<div class="item_cell ">600</div>
<div class="clr"></div>
</div>
</div>
<div class="item_row itemrow_type15">
<div class="item_content">
<div class="item_cell ">Temporada</div>
<div class="item_cell "><img src="http://mysite.com.br/joomla/images/joomd/thumbs/1350654792temporada.jpg" alt="Fotos" /></div>
<div class="item_cell ">Exemplo de Cidade</div>
<div class="item_cell ">São Paulo</div>
<div class="item_cell ">Casa</div>
<div class="item_cell ">800</div>
<div class="clr"></div>
</div>
</div>
</div>
Here is how I solved it:
I opened the default_item.php and found this:
if($j==0) {
echo '<a href="'.JRoute::_('index.php?option=com_joomd&view=item&layout=detail&typeid='.$item->typeid.'&id='.$item->id).'">';
echo $this->field->displayfieldvalue($item->id, $this->fields[$j]->id, true);
echo '</a>';
}
Then I could call the pop up using jQuery [http://swip.codylindley.com/popupWindowDemo.html][1]
Here is how my working code looks like now:
echo '<a class="propriedade" href="'.JRoute::_('index.php?option=com_joomd&view=item&layout=detail&typeid='.$item->typeid.'&id='.$item->id).'">';
Thank you all so much for the help.

As Alex noted, this isn't possible with just PHP. PHP is a server-side language that happens before the page is loaded. You can achieve this with HTML and JavaScript.
You should look into the JavaScript function open() which allows you to open a new window with an exact width/height and URL specified.
Read more about open() here
EXAMPLE CODE :
myWindow=window.open('http://google.com','','width=200,height=200')
This will open Google in a new window with dimensions of 200x200 pixels
To use this code, you must insert this in either a <script> tag or in an external JavaScript file. I suggest using this as a function like so:
function newWindow(url, width, height)
{
myWindow=window.open(url,'','width=' + width + ',height=' + height);
}
You can then call this with:
newWindow('http://google.com', 200, 200)
you can implement this in your code with the onCLick attribute:
Click Me
Demo of my function with HTML and JavaScript
The reason I suggest this function is that using the target="_blank" attribute on some browsers just opens in a new tab, which you can use, but I assumed you wanted a whole new window
Now that you have added some code to your question, I can see you have a lot of list items, you can simple add an anchor tag to make my function work, example:
<div class="item_cell "><img src="http://alii.com.br/joomla/images/joomd/thumbs/1350654792temporada.jpg" alt="Fotos" /></div>
<div class="item_cell ">Exemplo de Cidade</div>
<div class="item_cell ">São Paulo</div>
<div class="item_cell ">Casa</div>
<div class="item_cell ">800</div>
would become:
<div class="item_cell "><img src="http://alii.com.br/joomla/images/joomd/thumbs/1350654792temporada.jpg" alt="Fotos" /></div>
<div class="item_cell ">Exemplo de Cidade</div>
<div class="item_cell ">São Paulo</div>
<div class="item_cell ">Casa</div>
<div class="item_cell ">800</div>

add target="_blank" in tour tag or use window.open method.
e.g.:
Google
or
<script>window.open('http://google.com','','width=200,height=200'); </script>

Related

Printing the HTML generated Identity Card

I have created an identity card using HTML and PHP and I want to print it when a button is clicked. But I am not getting idea about what to do next / next step.
Currently I just have the following code. What should I do next that when the generate_idcard button is clicked it opens the print dialogue box for printing it.
if(isset($_POST['generate_idcard'])){
$idcard = '<div class="idholder">
<div class="photobox"><img src="students/'.$f['st_photo'].'" width="102" height="105"></div>
<div class="idtxt idtxt1">'.$f['st_dob'].'</div>
<div class="idtxt idtxt2">'.$f['st_blood'].'</div>
<div class="idtxt idtxt3">'.$f['st_phone'].'</div>
<div class="idtxt idtxt4">'.$f['st_admtype'].'</div>
<div class="idtxt idtxt5">'.$f['st_name'].'</div>
<img src="images/idcard.png" width="300" height="390">
</div>';
}
Currently, this code when echoed displays the ID card perfectly. I just need to print it now. Please help me on what code to write next to print it.
Do you want as it ?
CSS code for A4 paper size
#media print {
body{
width: 21cm;
height: 29.7cm;
margin: 30mm 45mm 30mm 45mm;
}
}
Php and html code
<?php if(isset($_POST['generate_idcard'])) :?>
<div class="idholder">
<div class="photobox"><img src="students/'<?=$f['st_photo']?>" width="102" height="105"></div>
<div class="idtxt idtxt1"><?=$f['st_dob']?></div>
<div class="idtxt idtxt2"><?=$f['st_blood']?></div>
<div class="idtxt idtxt3"><?=f['st_phone']?></div>
<div class="idtxt idtxt4"><?=$f['st_admtype']?></div>
<div class="idtxt idtxt5"><?=f['st_name']?></div>
<img src="images/idcard.png" width="300" height="390">
</div>
<button onclick="window.print()>print</button>
<?php endif; ?>

angular js onmouseover showhint not show data

I have problem with some angular things. I'm trying to set recursive dive with some info with some hintshow (tooltip).
The problem is all information show fine exclusive the hintshow. Added the screen show + some code. The data saved in {{x.who_liked}} as string, for example
"wyd3x, someoneXD, Shohamiko, guymaster, HUBHVNKL, Rauli, Matk, gal350"
<div ng-repeat="x in names | startFrom:currentPage*pageSize | limitTo:pageSize">
<div class="post">
<div class="posterDetails">
{{x.username}}</br>
פירסם ב<?php echo timeAgo("{{x.date}}"); ?>
<div ng-switch on="x.user_id">
<div ng-switch-when="<?=$_SESSION['id']?>">
<?php
echo " <a style='color:red;' href=\"?page=feeds&id={{x.id}}&delete\">(מחק סטטוס)</a>";
?>
</div>
</div>
</div>
<div class="postContent" ng-bind-html="x.msg | unsafe"></div>
<div class="options" style="text-align: right;padding: 5px;">
<div id="like" style="display:inline-block">
<img src="images/{{x.liked}}" post_id={{x.id}} ng-click="like(x)"> {{x.likes}} <div class="liked" onMouseover="showhint('{{x.who_liked}}', this)" style="display:inline-block">אהבו</div>
</div>
<div id="report" ng-click="report(x)" style="cursor: pointer; display:inline-block">
<img src="images/icons/vlag.png"> דווח
</div>
</div>
</div>
current station
tooltip: http://dynamicdrive.com/dynamicindex16/showhint.htm
You shouldn't be using {{}} interpolation inside your onMouseover directive.It should be onMouseover="showhint(x.who_liked, this)"
or
Angular solution
You can fix it like this :
ng-mouseover="showhint(x.who_liked,this)"
Instead of onMouseover , you can use ng-mouseover.
For better understanding , see this fiddle

How to display mysql array with limit together with PHP

I have a mysql query together with my html code looking like this.
<?php
/////////////////////////////////////////////////////////////
// RANDOM USER DISPLAYED WHICH MATCHS
/////////////////////////////////////////////////////////////
$statement = $dbConn->prepare("SELECT user_name, profile_image_url, user_age, country FROM users WHERE profile_image = '2' AND gender = ? ORDER BY RAND() LIMIT 2;");
$statement->execute(array($logged_in_user['searching_for']));
$random_match= $statement->fetch(PDO::FETCH_BOTH);
/////////////////////////////////////////////////////////////
// END OF RANDOM QUESTIONS
/////////////////////////////////////////////////////////////
?>
<div id="front_match">
<div class="front_box">
<div class="front_box_left">
<div style="position: relative;">
<img src="images/woman_1.jpg" style="max-width:100%;height:auto;">
<div class="transparent">Information about user one comes here</div>
</div>
</div>
<div class="front_box_right">
<div style="position: relative;">
<img src="images/woman_2.jpg" style="max-width:100%;height:auto;">
<div class="transparent">Information about user two comes here</div>
</div>
</div>
</div> <!-- div box finished here -->
</div> <!-- div match finished here -->
How to i insert information received from the database in
"Information about user one" and then "Information about user two"?
You can see that i'm using limit 2 so i want to display 1 results in one place and second result in second place
Cheerz
You can still use fetch_array to achieve your goal. Store it in an array, then you can call it whenever you want.
while($statement->fetch()){
$user_name_arr[] = $user_name;
$user_age_arr[] = $user_age;
/* ... REST OF CODE ... */
}
Then call them manually:
<div id="front_match">
<div class="front_box">
<div class="front_box_left">
<div style="position: relative;">
<img src="images/woman_1.jpg" style="max-width:100%;height:auto;">
<div class="transparent">
<?php
echo "Name: ".$user_name_arr[0];
echo "Age: ".$user_age_arr[0];
/* ECHO REST OF THE INFORMATION */
?>
</div>
</div>
</div>
<div class="front_box_right">
<div style="position: relative;">
<img src="images/woman_2.jpg" style="max-width:100%;height:auto;">
<div class="transparent">
<?php
echo "Name: ".$user_name_arr[1];
echo "Age: ".$user_age_arr[1];
/* ECHO REST OF THE INFORMATION */
?>
</div>
</div>
</div>
</div> <!-- div box finished here -->
</div> <!-- div match finished here -->
Just wondering:
I'm just wondering, why do you have to separate them and not use while loop. And just go with this:
<div id="front_match">
<div class="front_box">
<?php
while($statement->fetch()){
?>
<div class="front_box_left">
<div style="position: relative;">
<img src="<?php echo $profile_image_url; ?>" style="max-width:100%;height:auto;">
<div class="transparent">
<?php
echo "Name: ".$user_name;
echo "Age: ".$user_age;
/* ECHO REST OF THE INFORMATION */
?>
</div>
</div>
</div>
<?php
} /* END OF WHILE LOOP */
?>
</div> <!-- div box finished here -->
</div> <!-- div match finished here -->
You want excatly two rows? Then fatch two times:
$first_match = $statement->fetch(PDO::FETCH_BOTH);
$second_match = $statement->fetch(PDO::FETCH_BOTH);
You can use $first_match for the first table and $secon_match for the second table.

how to pass row from mysql database into div popup window

I need help passing row from a mysql database into a div popup window?
how doI pass product id into popup div which I call through View?
For Example I Want Like This
View</li>
Here My Code
<div class="latest_products_sec">
<div class="latest_products">
<div class="title_box">
</div>
<!--Latest Products Slider -->
<div class="latest_pro_box">
<h4>Latest Shirt's Collection</h4>
<div class="latest_products_slider">
<?php
$queryshirt=mysql_query("select image,id from products
where cid='1' LIMIT 5") or die ('die shirt query');
while($rowshirt=mysql_fetch_array($queryshirt))
{
echo '<ul>';
echo '<li><img src="admin/'.$rowshirt['image'].'"
width="225" height="300" alt="" />
View</li>';
echo '</ul>';?>
}
?>
#shirt Div Popup Window
<div id="shirt" class="proquickview">
<span class="close_btn" onclick="parent.jQuery.fancybox.close();">Close</span>
<h2 class="title">quick view</h2>
<div class="quickviewinfo">
<?php
// I Need To Get ID Here
echo $id=$_REQUEST['id'];
?>
<div class="quickviewinforight">
<div class="titlerow">
<h2>Latest Shirt's Collection</h2>
<div class="start_ratings">
<div class="start_rating">
</div>
</div>
<div>
<div class="quick_review">
<h3>Quick Discription</h3>
<p>TEST.</p>
</div>
<div class="qty_row">
<div class="qty_field">
<label>Select Quantity</label>
<span>
<select name="S">
<option>5</option>
</select>
</span>
</div>
<br class="clear" />
<span class="total_price">Price <strong>$88.00</strong>
<del>$102.00</del></span>
ADD TO CART
</div>
<div class="total_price_row">
</div>
</div>
</div>
</div>
Javascript For Popup Window
$(document).ready(function() {
$(".view_btn").fancybox({
'titlePosition' : 'inside',
'transitionIn' : 'none',
'transitionOut' : 'none'
});
});
$(document).ready(function(){
// Cufon Functions //
Cufon.replace ('.latest_products_slider ul li a.view_btn',{hover:true});
});
You can use new 'echo'
echo 'View</li>';
instead of using this
echo '<li><img src="admin/'.$rowshirt['image'].'" width="225" height="300" alt="" />
View</li>';
combined 'echo' statement for image and link to View
Use jQuery .load function. Then make a hidden div, tgen on an action, use the load function to load the hidden div and change the css selection to visible. Very simple, add effects as well.

Generate JQuery code inside a PHP foreach loop

UPDATE
for JLRiche
html structure below (here is the structure for the entire div id=content_body_right):
<div id="content_body_right">
<p class="user_text">Tim Flanagan</p><p class="date_text">02-06-2013 # 12:00PM</p>
<p class="message_text">Playin Augusta today. What a beautiful course!</p>
<div id="activity_image">
<img src="images/activities/1/actimg.jpg" width="435" />
</div>
<div id="tips">
<div id="tip_cap_left">
<a href="dashboard.php?captip=tipyourcap" title="Tip Your Cap" ></a>
</div>
<div id="tip_cap_right">
<p class="tips_right">12 Tips of the Cap</p>
</div>
</div>
<p class="comments_label">
4 Comments
see all
collapse
</p>
<div id="comment1">
<div id="comment_user_img">
<img src="images/defaultuserimg.jpg" width="30" height="30" />
</div>
<div id="comment_user">
<p class="user_text_comment">Tim Flanagan</p><p class="date_text_comment">02-06-2013 # 12:00PM</p>
<p class="message_text_comment">Nice jealous of you bro.</p>
</div>
</div>
<div class="comment2" style="display:none; clear:both; margin:0px; overflow:auto">
<div id="comment2_sub">
<div id="comment_user_img">
<img src="images/defaultuserimg.jpg" width="30" height="30" />
</div>
<div id="comment_user">
<p class="user_text_comment">Tim Flanagan</p><p class="date_text_comment">02-06-2013 # 12:00PM</p>
<p class="message_text_comment">Nice jealous of you bro.</p>
</div>
</div>
<div id="comment2_sub">
<div id="comment_user_img">
<img src="images/defaultuserimg.jpg" width="30" height="30" />
</div>
<div id="comment_user">
<p class="user_text_comment">Tim Flanagan</p><p class="date_text_comment">02-06-2013 # 12:00PM</p>
<p class="message_text_comment">Nice jealous of you bro.</p>
</div>
</div>
<div id="comment2_sub">
<div id="comment_user_img">
<img src="images/defaultuserimg.jpg" width="30" height="30" />
</div>
<div id="comment_user">
<p class="user_text_comment">Tim Flanagan</p><p class="date_text_comment">02-06-2013 # 12:00PM</p>
<p class="message_text_comment">Nice jealous of you bro.</p>
</div>
</div>
</div>
</div>
Let me know if you need more structure, because there is alot above and below it. Hope this helps.
I really appreciate your help!
END UPDATE
Good Evening All,
I need to dynamically create X amount of jquery scripts foreach of the X amount of db results. X meaning the the number will vary. It is sort of a forum type thing where you see the original post with one reply showing and you would click see all or collapse all to view or collapse the rest. I am incrementing my html elements inside a foreach loop with the typical $i variable so I need to output jquery click functions for each as well.
The code I need PHP to create is below:
$jquery .= "$('#see_all$i').click(function () {
$('#comment2_$i').slideDown('fast');
$('#collapse$i').css('display', 'inline-block');
$('#see_all$i').css('display', 'none');
return false;
});
$('#collapse$i').click(function () {
$('#comment2_$i').slideUp('fast');
$('#collapse$i').css('display', 'none');
$('#see_all$i').css('display', 'inline-block');
return false;
})";
Any help would and always will be much appreciated!
Thanks
Generating multiple, slightly different copies of the same jQuery code is not a very good design, IMHO. You should write your jQuery code in a way that it only needs to be in your page once, like:
$('.see_all').click(function(){
var thisItem = $(this);
thisItem.parent().find('.comment').slideDown('fast');
thisItem.parent().find('.collapse').css('display','inline-block');
thisItem.css('display','none');
return false;
});
$('.collapse').click(function(){
var thisItem = $(this);
thisItem.parent().find('.comment').slideUp('fast');
thisItem.css('display','none');
thisItem.parent().find('.see_all').css('display','inline-block');
return false;
})";
Of course, this would also involve adding collapse, see_all, and comment classes to the relevant HTML elements.
html :
<div class="seeall" data-elid="1">...</div>
...
<div class="collapse" data-elid="1">...</div>
...
js :
var $bdy=$(document.body)
$bdy.on("click",".seeall",function(e) {
var el=$(this).css('display','none').data("elid");
$('#comment2_'+el).slideDown('fast');
$('.collapse[data-elid="'+el+'"]').css('display','inline-block');
})
.on("click",".collapse", function(e) {
//same same
});

Categories