why it float left is not working and these codes - php

my question is that why float left is not working under these codes
when i use them all the result just display on single div and other 7 where showing under that div at same place so please tell me what is the solution of this prob
<div class="tv_l" style="top:1465px;
left:10px;
position:absolute;
width:1690px;
height:10px;
border-radius:3px/3px;
padding-right:10px;
padding-top:px;
border-left:10px;">
<hr>
</div>
<?php
$link = mysqli_connect("localhost" , "***" ,"***" , "***");
if (mysqli_connect_errno()) {
echo mysqli_connect_error();
exit();
} else {
echo "";
}
?>
<?php
$result = mysqli_query($link, "SELECT * FROM **** ORDER BY RAND()
LIMIT 8" )
or die(mysqli_error());
while($row = mysqli_fetch_array( $result )){
?>;
<div class="son_s_p" style="top:1957px;
left:12px;
-webkit-box-shadow:0 3px 8px rgba(0, 0, 0, .25);
position:inherit;
background:white;
width:190px;
height:240px;
border-radius:3px/3px;
padding-right:10px;
padding-top:px;
border-left:10px;
text-align:center;
float:left;
">
<img src="../lu/music/tumb/<?php echo $row['img']; ?>"style="width:198px; height:148px;" >
<br>
<?php echo $row['name']; ?><br><br>
<div id="son_s_p" style="top:218px;
left:px;
position:absolute;
border-radius:3px/3px;
padding-right:10px;
padding-top:px;
border-left:10px;
text-align:justify;">
<?php echo $row['time']; ?> <span class="time&type" style="top;10px;"><?php echo $row['type']; ?></span>
</div>
</div>
<?php
}
?>
with using position
without using position data will go top and top do not work

your wrong is that you put in div "float: left;" and thats wrong.you should put before it style attribute and it is Style="float: left;"
correct code is:
<div class="tv_l" style="top:1465px;
left:10px;
position:absolute;
width:1690px;
height:10px;
border-radius:3px/3px;
padding-right:10px;
padding-top:px;
border-left:10px;">
<hr>
</div>
<?php
$link = mysqli_connect("localhost" , "***" ,"***" , "***");
if (mysqli_connect_errno()) {
echo mysqli_connect_error();
exit();
} else {
echo "";
}
?>
<?php
$result = mysqli_query($link, "SELECT * FROM **** ORDER BY RAND()
LIMIT 8" )
or die(mysqli_error());
while($row = mysqli_fetch_array( $result )){
?>;
<div class="son_s_p" style="top:1957px;
left:12px;
-webkit-box-shadow:0 3px 8px rgba(0, 0, 0, .25);
position:inherit;
background:white;
width:190px;
height:240px;
border-radius:3px/3px;
padding-right:10px;
padding-top:px;
border-left:10px;
text-align:center;
float:left;
">
<img src="../lu/music/tumb/<?php echo $row['img']; ?>"style="width:198px; height:148px;" >
<br>
<?php echo $row['name']; ?><br><br>
<div id="son_s_p" style="top:218px;
left:px;
position:absolute;
border-radius:3px/3px;
padding-right:10px;
padding-top:px;
border-left:10px;
text-align:justify;">
<?php echo $row['time']; ?> <span class="time&type" style="top;10px;"><?php echo $row['type']; ?></span>
</div>
</div>
<?php
}
?>

Your question was unclear, however I have cleaned up your code so that the div .tv_l is to the left of the div .son_s_p and its content:
.tv_l {
border-radius: 3px/3px;
padding-right: 10px;
border-left: 10px;
border: 1px solid;
float: left;
}
.son_s_p {
-webkit-box-shadow: 0 3px 8px rgba(0, 0, 0, .25);
background: white;
width: 190px;
height: 240px;
border-radius: 3px/3px;
padding-right: 10px;
border-left: 10px;
text-align: center;
float: left;
}
#son_s_p {
border-radius: 3px/3px;
padding-right: 10px;
padding-top: px;
border-left: 10px;
text-align: justify;
}
<div class="tv_l">
<hr>
</div>
<?php
$link = mysqli_connect("localhost" , "***" ,"***" , "***");
if (mysqli_connect_errno()) {
echo mysqli_connect_error();
exit();
}else{
echo "";
}
$result = mysqli_query($link, "SELECT * FROM **** ORDER BY RAND()
LIMIT 8")
or die(mysqli_error());
while($row = mysqli_fetch_array( $result )){
?>
<div class="son_s_p">
<img src="../lu/music/tumb/<?php echo $row['img']; ?>" style="width:198px; height:148px;">
<br>
<?php echo $row['name']; ?>
<br>
<br>
<div id="son_s_p">
<?php echo $row['time']; ?>
<span class="time&type" style="top;10px;"><?php echo $row['type']; ?></span>
</div>
</div>
<?php } ?>

It looks like you are using absolute positioning on your DIVs. Floats cannot work that way. Use this instead:
position: static;
float: left;
If I were you I would first try to get it to work with pure HTML and CSS with some dummy data, before hooking it up to the database.
Here's an example of how you can achieve floating with divs, in contrast to your approach:
https://jsfiddle.net/19zrr99n/

Related

Any idea how to stop paragraph from going over its div?

I'm currently trying to make a blog. When I try to make a "preview" of the body of the post. The first post seems to be fine, but the second post goes over its div. I tried changing what tags to use and css formatting but it stays like that.
My code:
HTML
<div class="module">
<div class="blog">
<div class="recents">
<h2>Recent Posts</h2>
<br><br>
<?php
$sql = "select title, body, created_at FROM posts";
$result = mysqli_query($link, $sql);
$query = mysqli_query($link, $sql) or die(mysqli_error($link));
while ($row = mysqli_fetch_assoc($query)) {
$title = $row['title'];
$body = $row['body'];
$created_at = $row['created_at'];
if (strlen($body) > 500) {
$body = substr($body, 0, 500);
}
echo "<h3>" . $title . "</h3><br>";
echo "<p>" . $body . "</p>";
echo "<small>" . $created_at . "</small>";
echo "<br><br>";
}
?>
</div>
<div class="categories">
<h3>Categories</h3>
</div>
</div>
CSS
html {
font-family: 'IBM Plex Serif', serif;
}
.module {
background-color: #fffff7;
box-shadow: 3px 10px 18px #888888;
padding-top: 70px;
padding-left: 130px;
border: 1px solid;
width: 1080px;
margin-left: 380px;
height: 821px;
}
.blog {
display: flex;
flex-direction: row;
text-align: left;
}
.recents {
flex-grow: 2;
width: 570px;
}
.categories {
flex-grow: 1;
}
Any help would be appreciated.
It is because there are no spaces
to fix this try this:
word-wrap: break-word;

PHP Searchbar only showing 1 result

I am trying to create a search bar in php.
I want to retrieve data from my database.
The problem is only that if I search I get only 1 result.
How do I solve this?
Or is there another way in which I get this working?
My code:
<?php
include("config.php");
session_start();
$zoekopdracht = $_GET['search'];
$categorie = $_GET['categorie'];
$zoekopdracht = mysqli_real_escape_string($db,$zoekopdracht);
$sql = ("SELECT * FROM activiteiten WHERE `inhoud` LIKE '%$zoekopdracht%'");
$result = mysqli_query($db,$sql);
$row = mysqli_fetch_array($result,MYSQLI_ASSOC);
$activiteit_id = $row['activiteit_id'];
$naamsql = ("SELECT * FROM `activiteiten` WHERE activiteit_id = {$activiteit_id} AND optie = 'naam'");
$naamresult = mysqli_query($db,$naamsql);
$naamrow = mysqli_fetch_array($naamresult,MYSQLI_ASSOC);
$beschrijvingsql = ("SELECT * FROM `activiteiten` WHERE activiteit_id = {$activiteit_id} AND optie = 'beschrijving'");
$beschrijvingresult = mysqli_query($db,$beschrijvingsql);
$beschrijvingrow = mysqli_fetch_array($beschrijvingresult,MYSQLI_ASSOC);
result bar:
<?php
if(mysqli_num_rows($result) > 0){
?>
<div class="Row" id="main" style="border: 2px solid #51BAA4;border-radius: 4px; height: 0px; width: 100%;padding: 0em 0 0em 0; margin: 0 auto; display: table;">
<div class="Column" id="plaatje" style="padding: 0em 0 0em 0;">
<left><img src="images/noimage.png" height="100px" width="100px" alt=""></left>
</div>
<div class="Column" id="titel">
<div style="text-align: left;position:relative;margin:0px;width:10%;height:40px;padding-top: 3px; font-size:125%; display: -webkit-box;-webkit-line-clamp: 1;">
<left><h3><?php echo $naamrow['inhoud'];?></h3>
</div>
<div style="text-align: left; height: 0px;width: 450px; word-wrap: break-word;white-space: initial;position:absolute;">
<p style=" overflow: hidden;display: -webkit-box;-webkit-line-clamp: 2;-webkit-box-orient: vertical"><?php echo "<b>"; echo $naamrow['inhoud']; echo "</b>, "; echo $beschrijvingrow['inhoud']; ?></p>
</div>
</div>
</div>
<?php
}
?>
You are process only first record there. You need to repeat for all the return value.
//$row = mysqli_fetch_array($result,MYSQLI_ASSOC);
$naamrows = [];
$beschrijvingrow = [];
while($row = mysqli_fetch_array($result,MYSQLI_ASSOC)) {
$activiteit_id = $row['activiteit_id'];
$naamsql = ("SELECT * FROM `activiteiten` WHERE activiteit_id = {$activiteit_id} AND optie = 'naam'");
$naamresult = mysqli_query($db,$naamsql);
$naamrow = mysqli_fetch_array($naamresult,MYSQLI_ASSOC);
$beschrijvingsql = ("SELECT * FROM `activiteiten` WHERE activiteit_id = {$activiteit_id} AND optie = 'beschrijving'");
$beschrijvingresult = mysqli_query($db,$beschrijvingsql);
$beschrijvingrow = mysqli_fetch_array($beschrijvingresult,MYSQLI_ASSOC);
// Store you data in array to be use later
array_push($naamrows,$naamrow);
array_push($beschrijvingrows,$beschrijvingrow);
}
Now change you template to iterate the array to render all.
<?php foreach ($naamrows as $key => $naamrow) { ?>
<div class="Row" id="main"
style="border: 2px solid #51BAA4;border-radius: 4px; height: 0px; width: 100%;padding: 0em 0 0em 0; margin: 0 auto; display: table;">
<div class="Column" id="plaatje" style="padding: 0em 0 0em 0;">
<left><img src="images/noimage.png" height="100px" width="100px" alt=""></left>
</div>
<div class="Column" id="titel">
<div
style="text-align: left;position:relative;margin:0px;width:10%;height:40px;padding-top: 3px; font-size:125%; display: -webkit-box;-webkit-line-clamp: 1;">
<left>
<h3><?php echo $naamrow['inhoud'];?></h3>
</div>
<div
style="text-align: left; height: 0px;width: 450px; word-wrap: break-word;white-space: initial;position:absolute;">
<p style=" overflow: hidden;display: -webkit-box;-webkit-line-clamp: 2;-webkit-box-orient: vertical">
<?php echo "<b>"; echo $naamrow['inhoud']; echo "</b>, "; echo $beschrijvingrows[$key]['inhoud']; ?></p>
</div>
</div>
</div>
<?php } ?>

Proplem in div right align?

i have php program that contain div main_wrapper that div have two sub div resultwrapper and adv_right. I want adv_right div exactly right side of the resultwrapper div.When i'm use float mean that div present outside of the main_wrapper div.
<style>
.resultwrapper{width:990px; margin: 10px auto 10px auto; clear:both; }
.resultitem{ float: left;
height: 170px;
margin-bottom: 0px;
margin-left: 10px;
min-height: 130px;
width:218px;}
.resultleftitem{padding-left:0;margin-left:0px;}
.resultitem img{border:dotted 1px #666; padding:6px;}
.resultitem img:hover{border:solid 1px #F60;}
.resultitem h4{font-size:12px; font-weight:bold; color:#249ce9; margin-top:5px; }
.resultitem a{color:#249ce9;}
.resultitem .caption{color:#9c9c9c; font-size:12px; display:block; margin-top:6px; text-align:justify;}
</style>
<div class="main_warpper">
<div class="resultwrapper">
<?php
while($row = mysql_fetch_array($rs)) {
$id=$row['id'];
$type=$row['type'];
$location=$row['location'];
if(file_exists("properties//". $imageloc ."//thumb.jpg") )
{
$thumb_img="properties/". $imageloc ."/thumb.jpg";
} else {
$thumb_img="images/default.jpg";
}
if($cnt==0 || $cnt ==4 ) $newResult=true; else $newResult=false;
?>
<div id="parent" >
<div class="resultitem <?php if($newResult) echo ' resultleftitem'; ?>" id="resultitem"> <a href="viewpropdetails.php?id=<?php echo $id;?>" target="_blank">
<img id="parent" src="<?php echo $thumb_img; ?>" alt="<?php $new=strtolower($heading); echo ucwords($new); ?>" title="<?php $new=strtolower($heading); echo ucwords($new); ?>" width="100" height="100" /></a>
<div class="itemdetails">
<h4 id="linkheading"><?php echo $type ." # ".$location; ?></h4>
<span class="box"><?php echo cropStr($desc,$MAX_DESC); ?></span>
</div>
</div>
</div>
<?php
$cnt++; } ?>
</div>
<div class="adv_right" style=" clear:both; width:15%; float:right;height:300px; background-color:#999999;">
</div>
</div>
Please try it,
Remove clear:both; from both div and set width what u want ,,
Please try this code you want like this ??
<style>
.resultwrapper {
margin: 10px auto 10px auto;
}
.resultitem {
float: left;
height: 170px;
margin-bottom: 0px;
margin-left: 10px;
min-height: 130px;
width:218px;
}
.resultleftitem {
padding-left:0;
margin-left:0px;
}
.resultitem img {
border:dotted 1px #666;
padding:6px;
}
.resultitem img:hover {
border:solid 1px #F60;
}
.resultitem h4 {
font-size:12px;
font-weight:bold;
color:#249ce9;
margin-top:5px;
}
.resultitem a {
color:#249ce9;
}
.resultitem .caption {
color:#9c9c9c;
font-size:12px;
display:block;
margin-top:6px;
text-align:justify;
}
</style>
<div class="main_warpper">
<div class="resultwrapper">
<?php
while($row = mysql_fetch_array($rs)) {
$id=$row['id'];
$type=$row['type'];
$location=$row['location'];
if(file_exists("properties//". $imageloc ."//thumb.jpg") )
{
$thumb_img="properties/". $imageloc ."/thumb.jpg";
} else {
$thumb_img="images/default.jpg";
}
if($cnt==0 || $cnt ==4 ) $newResult=true; else $newResult=false;
?>
<div id="parent" >
<div class="resultitem <?php if($newResult) echo ' resultleftitem'; ?>" id="resultitem"> <img id="parent" src="<?php echo $thumb_img; ?>" alt="<?php $new=strtolower($heading); echo ucwords($new); ?>" title="<?php $new=strtolower($heading); echo ucwords($new); ?>" width="100" height="100" />
<div class="itemdetails">
<h4 id="linkheading"><?php echo $type ." # ".$location; ?></h4>
<span class="box"><?php echo cropStr($desc,$MAX_DESC); ?></span> </div>
</div>
</div>
<?php
$cnt++; } ?>
</div>
<div class="adv_right" style="width:15%; float:right;height:300px; background-color:#999999;">23123 </div>
</div>
add float:left here
<div class="resultwrapper" style="float:left;">
and rempove clear:both and add float:left
<div class="adv_right" style=" clear:both; width:15%; float:left;height:300px;
background-color:#999999;">
see demo here ....http://jsfiddle.net/6e4xN/1/
when you going to use this code it will not work with more than 7-8 elements, to work when you have more elements then use below stylesheet.
<style>
.resultwrapper {
margin: 10px auto 10px auto;
width:80%;
float:left;
}
.resultitem {
float: left;
height: 170px;
margin-bottom: 0px;
margin-left: 10px;
min-height: 130px;
width:150px;
}
.resultleftitem {
padding-left:0;
margin-left:0px;
}
.resultitem img {
border:dotted 1px #666;
padding:6px;
}
.resultitem img:hover {
border:solid 1px #F60;
}
.resultitem h4 {
font-size:12px;
font-weight:bold;
color:#249ce9;
margin-top:5px;
}
.resultitem a {
color:#249ce9;
}
.resultitem .caption {
color:#9c9c9c;
font-size:12px;
display:block;
margin-top:6px;
text-align:justify;
}
</style>
Let me know if it works for you or not.
I guess there is some problem in the code. You CANNOT use the same ID for multiple elements in a page. Secondly when you are using percent width for the adv_right div, why don't you use the same for resultwrapper div with both the resultwrapper & adv_right divs floated left and no clear:both in the css. I feel this should solve your problem.

how to add star rating to product dynamically

i've been trying to add star ratings to my product but i keep getting an error. i've called both products and rating data from mysql but it aint working..my code is below pls kindly help me
/*rating.php*/
//this handles the rating input
<?php
include("db.php");
$users_ip = $_SERVER['REMOTE_ADDR'];
if($_REQUEST['value'])
{
$id = $_REQUEST['value'];
$r_id = $_REQUEST['$rid'];
$result = mysql_query("select users_ip from tbl_rating where users_ip='$users_ip'");
$num = mysql_num_rows($result);
if($num==0)
{
$query = "insert into tbl_rating (rating,rate_id,users_ip) values ('$id','$r_id','$users_ip')";
mysql_query( $query);
$result=mysql_query("select sum(rating) as rating from tbl_rating");
$row=mysql_fetch_array($result);
$rating=$row['rating'];
$quer = mysql_query("select rating from tbl_rating");
$all_result = mysql_fetch_assoc($quer);
$rows_num = mysql_num_rows($quer);
if($rows_num > 0){
$get_rating = floor($rating/$rows_num);
$rem = 5 - $get_rating;
}?>
<?php
for($k=1;$k<=$get_rating;$k++){?>
<div class="rating_enb" id="<?php echo $k?>"> </div>
<?php
}?>
<?php
for($i=$rem;$i>=1;$i--){?>
<div class="rating_dis" id="<?php echo $k?>"> </div>
<?php
$k++;
}?>
<div class="rating_value"><?php echo ((#$get_rating) ? #$get_rating : '0')?> /5</div>
<div class="user_message"><?php echo $rows_num?> times rated</div>
<?php
}
else
{
echo '<div class="rating_message">You already did it !</div>';
}
}
if(#$_REQUEST['show']) // show rating again after showing message
{
$result=mysql_query("select sum(rating) as rating from tbl_rating");
$row=mysql_fetch_array($result);
$rating=$row['rating'];
$quer = mysql_query("select rating from tbl_rating");
$all_result = mysql_fetch_assoc($quer);
$rows_num = mysql_num_rows($quer);
if($rows_num > 0){
$get_rating = floor($rating/$rows_num);
$rem = 5 - $get_rating;
}?>
<?php
for($k=1;$k<=$get_rating;$k++){?>
<div class="rating_enb" id="<?php echo $k?>"> </div>
<?php
}?>
<?php
for($i=$rem;$i>=1;$i--){?>
<div class="rating_dis" id="<?php echo $k?>"> </div>
<?php
$k++;
}?>
<div class="rating_value"><?php echo ((#$get_rating) ? #$get_rating : '0')?> / 5</div>
<div class="user_message"><?php echo $rows_num?> times rated</div>
<?php
}?>
/*index.php */
//here i want to echo the star rating with the product along side but its not working
<script type="text/javascript" src="js/jquery-1.2.6.min.js"></script>
<script type="text/javascript">
// <![CDATA[
$(document).ready(function(){
$('#loader').hide();
$('#inner').children().click(function(){
var a = $(this).attr("id");
$.post("rating.php?value="+a, {
}, function(response){
$('#inner').fadeOut();
$('#inner').html(unescape(response));
$('#inner').fadeIn();
setTimeout("hideMesg();", 2000);
});
});
});
function hideMesg(){
$('.rating_message').fadeOut();
$.post("rating.php?show=1", {
}, function(response){
$('#inner').html(unescape(response));
$('#inner').fadeIn('slow');
});
}
// ]]>
</script>
<?php
$resultm=mysql_query("select * from ratesummary GROUP BY pd_id");
$resultb=mysql_query("select sum(rating) as rating from ratesummary GROUP BY pd_id");
$rowb=mysql_fetch_array($resultb);
$rating=$rowb['rating'];
$quer = mysql_query("select rating from ratesummary GROUP BY pd_id");
$all_result = mysql_fetch_assoc($quer);
$rows_num = mysql_num_rows($quer);
if($rows_num > 0){
$get_rating = floor($rating/$rows_num);
$rem = 5 - $get_rating;
}
else
{
$rem = 5;
}
while($rowx=mysql_fetch_array($resultm))
{
echo '<div class="ratebox">
<p class=product_name>#'.$rowx['pd_id'].'</p>
<p class=product_name>'.$rowx['pd_name'].'</p> </div>'
;
}
?>
<div id="container">
<div id="outer">
<div id="inner">
<?php
for($k=1;$k<=$get_rating;$k++){?>
<div class="rating_enb" id="<?php echo $k?>"> </div>
<?php
}?>
<?php
for($i=$rem;$i>=1;$i--){?>
<div class="rating_dis" id="<?php echo $k?>"> </div>
<?php
$k++;
}?>
<div class="rating_value"><?php echo ((#$get_rating) ? #$get_rating : '0')?> / 5</div>
<div class="user_message"><?php echo $rows_num?> times rated</div>
</div>
</div>
</div>
css style used
#container{
font-family:Arial, Helvetica, sans-serif;
width:440px;
}
#customForm{
padding: 0 10px 10px;
}
.user_message{ margin-top:12px; color:#006600; font-family:Georgia, "Times New Roman", Times, serif; font-size:14px; font-weight:bold;}
#customForm label{
display: block;
color:#000000;
float:left;
width:130px;
font-size:14px;
line-height: 1.4em;
}
#customForm input{
width: 220px;
float:left;
padding: 4px;
text-shadow: 0 -1px 1px rgba(0,0,0,0.25);
border-bottom: 1px solid rgba(0,0,0,0.25);
font-size: 11px;
border: 1px solid #CCCCCC;
}
input#button{
width: 244px;
float:left;
padding: 4px;
text-shadow: 0 -1px 1px rgba(0,0,0,0.25);
border-bottom: 1px solid rgba(0,0,0,0.25);
font-size: 11px;
border: 1px solid #CCCCCC;
}
#outer{ width:150px; padding:6px;
background:#FFFFFF;
height:18px;
margin-top:12px;
color:#fff;
margin-bottom:5px;
font-weight:bold;
-moz-border-radius: 6px;
font-size:12px;
-webkit-border-radius: 6px;
-moz-box-shadow: 0 1px 3px rgba(0,0,0,0.6);
-webkit-box-shadow: 0 1px 3px rgba(0,0,0,0.6);
text-shadow: 0 -1px 1px rgba(0,0,0,0.25);
border-bottom: 1px solid rgba(0,0,0,0.25);}
#outer .rating_enb {
width:16px; padding:1px;
height:18px; float:left;
background:#CC0000;
margin-right:4px;
cursor:pointer;
}
#outer .rating_dis {
width:16px; padding:1px;
height:18px; float:left;
cursor:pointer;
background:#CCCCCC;
margin-right:4px;
}
#outer .rating_dis:hover, #outer .rating_enb:hover {background:#009933; }
#outer .rating_value{ color:#003399; padding-top:2px; font-size:14px}
#outer .rating_message{ color:#003399; padding-top:2px; font-size:14px}
database schema
CREATE TABLE `tbl_product` (
`pd_id` int(10) unsigned NOT NULL auto_increment,
`pd_name` varchar(100) NOT NULL default '',
`pd_image` varchar(200) default NULL,
PRIMARY KEY (pd_id),
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1007 ;
CREATE TABLE `tbl_rating` (
`r_id` int(10) unsigned NOT NULL auto_increment,
`pd_id` int(10) unsigned NOT NULL default '0',
`rating` int(11) NOT NULL default '0',
`users_ip` varchar(200) NOT NULL default '0',
PRIMARY KEY (`r_id`),
KEY `pd_id` (`pd_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;
the table ratesummary was created using mysql create view to join the tbl_product with tbl_rating
Please try to change your returns, like these lines
<div class="rating_value"><?php echo ((#$get_rating) ? #$get_rating : '0')?> /5</div>
<div class="user_message"><?php echo $rows_num?> times rated</div>
should look something like this:
echo "<div class='rating_value'>". ((#$get_rating) ? #$get_rating : '0')/5 ."</div>".
"<div class='user_message'>". $rows_num . "times rated</div>";

How to use jquery to perform actions on PHP loop results?

I've searched and can't seem to make sense of the answers I've found. Grateful for any help!!
Goal: Reveal selected message detail in section#details below the listed message headers in section#info.
Problem:
The following code alerts a result but won't fadeIn();, (or show();, or ...anything).
The following code is only grabbing the value of the last result in the PHP while loop.
php/html/jquery/javascript:
<section id="info">
<?php
$user = $session->username;
$q = sprintf("SELECT * FROM mail WHERE UserTo = '%s' ORDER BY SentDate DESC",
mysql_real_escape_string($user));
$getMail = mysql_query($q, $link) or die(mysql_error());
if(mysql_num_rows($getMail) == 0) {
echo "<p>you have no mail</p>";
}
else {
?>
<form id="inbox" class="mail">
<fieldset>
<ul>
<li style="border: 2px solid purple; width: 100%;">
<span style="display: inline-block; border: 1px solid black; width: 8%; margin-left: 13%;">Status</span>
<span style="display: inline-block; border: 1px solid black; width: 15%;">From</span>
<span style="display: inline-block; border: 1px solid black; width: 45%;">Subject</span>
<span style="display: inline-block; border: 1px solid black; width: 16%;">Time</span>
</li>
<?php
while($mail = mysql_fetch_object($getMail)) {
$status = $mail->status;
$mailId = $mail->mail_id;
$from = $mail->UserFrom;
$subject = $mail->Subject;
$received = $mail->SentDate;
$theMessage = $mail->Message;
?>
<li class="outerDiv" style="border: 2px dotted purple;">
<button style="display: inline;" class="viewButton">View</button>
<button style="display: inline;">Delete</button>
<?php
echo "<span style='border: 1px solid red;'>" . $mail_id . "</span>";
echo "<span style='display: inline-block; width: 8%; border: 1px solid red;'>" . $status . "</span>";
echo "<span style='display: inline-block; width: 15%; border: 1px solid red;'>" . $from . "</span>";
echo "<span style='display: inline-block; width: 45%; border: 1px solid red;'>" . $subject . "</span>";
echo "<span style='display: inline-block; font-size: x-small; width: 17%; border: 1px solid red;'>" . $received . "</span>";
?>
</li>
<?php }
} ?>
</ul>
</fieldset>
</form>
</section>
<section id="details">
<div class="theMessage" style="display: none;"><?php echo $theMessage; ?></div>
<script type="text/javascript">
$(document).ready(function() {
$(".outerDiv").click(function(e) {
if($(e.target).is(".viewButton")) {
alert($(document).find(".theMessage").text()); //this works
$(document).find(".theMessage").text().fadeIn(1000); //this doesn't work
var theMessage = $(document).find(".theMessage").text();
theMessage.fadeIn(1000); //this doesn't work
}
});
return false; (sometimes prevents default..sometimes not?
});
</script>
</section>
p.s. the crazy colors and borders are/were for temp layout purposes. also, the delete button will obviously have functionality... once I can figure this out.
Instead of
$(document).find(".theMessage").text().fadeIn(1000);
use
$('.theMessage').fadeIn(1000);
Starx is correct, but I figured I'll give an explanation as well.
$('.theMessage').fadeIn(1000);
In case you don't understand why, take a look at http://api.jquery.com/text/ . The text() method only returns a string, not an actual HTML element that you can manipulate (in this case fadeIn). So text() is good to get or set the contents of an element, but to animate you need to call the methods directly on the $('.theMessage') element.

Categories