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.
Related
So I am doing the same grocery list I did before in JScript for an assignment but now in PHP. When I try to calculate the total it gives me a strange number.
$result is a calculation from product price multiplied by the quantity (waarde & aantal, its Dutch).
so when I do $total += $result;
And then I echo that, I get a very strange result.
To me it looks like it does not go by all the results. I tried using the $i index for it. But that does not work. What am I missing?
(Very new to PHP just learned a bit of the basic of JavaScript)
The expected outcome is all the totals shown in the table added together to create the total: 15.76
The result now is 31.984.85.98, what even is that magical number? Might be that I do something wrong with the number format, looking into that now too. (Also is it normal to share the code as I did? Apparently it's not really for PHP, I guess because it being a server-side thing) I have a CodePen of the original JavaScript version of it : https://codepen.io/3lly/pen/oNxaPKg maybe for clear view, you can see what I mean. The totals of all the total column cells.
table {
margin-top: 20px;
display: inline-block;
}
th, td , input {
border: 2px solid #FFB000;
padding: 2px;
color: black;
}
body {
text-align: center;
}
h1 {
color: #FFB000;
font-family: impact;
text-shadow: -1px 0 black, 0 1px black, 1px 0 black, 0 -1px black;
}
p {
color: white;
}
div {
display: inline-block;
}
#add {
display: inline-block;
padding: 10px 20px;
background: orange;
box-shadow: -3px 3px black, -2px 2px black, -1px 1px black;
border: 1px solid orange;
}
#add:hover {
background: green;
color: white;
}
input[type="text"], input[type="number"] {
background-color: skyblue;
}
input[type="number"]:hover {
background-color: black;
}
#totaal {
border: 2px solid #FFB000;
background-color: #282828;
padding: 5px;
color: skyblue;
}
#totaal:hover{
background-color: green;
color: white;
}
<head>
<link rel="stylesheet" href="style.css">
<title>Boodschappenlijst</title>
</head>
<body>
<h1> Boodschappenlijst </h1>
<div id="container"></div>
<table>
<tr>
<?php
$headerTexts = ['Name', 'Prijs', 'Aantal', 'Totaal'];
for($i=0;$i<count($headerTexts);$i++) {
echo "<th>" . $headerTexts[$i] . "</th>";
}
?>
</tr>
<?php
for($i=0;$i<count($products);$i++) {
//result calculations
$total = 0;
$result = number_format($products[$i]['waarde'] * $products[$i]['aantal'],2);
$total += $result;
echo $total;
//echo "<pre>" . is_int($products['waarde']) . "</pre>";
//Table Rows
echo "<tr>";
echo "<td>" . $products[$i]['omschrijving'] . "</td>" .
"<td>" . $products[$i]['waarde'] . "</td>" .
"<td>" . $products[$i]['aantal'] . "</td>" .
"<td>" . $result . "</td>";
echo "</tr>";
}
?>
</tr>
</table>
<p>Naam</p>
<form>
<input type="text" name="item" id="naam" /><br />
<p>Aantal</p>
<input type="text" name="quantity" id="qty" /><br />
<p>Prijs</p>
<input type="text" name="price" id="prijs" /><br/><br />
<input type="button" value="Add Product" onclick="updateTable()" id="add"><br /><br />
</form>
<div id="totaal"></div>
<!-- <script src="script.js"></script>-->
</body>
</html>
So I pushed the results of the total calculation of each products to the array which I did not do before like so :
$products[$i]['total'] = $products[$i]['waarde'] * $products[$i]['aantal'];
Next I did the calculation like so:
$total += $products[$i]['total'];
Within the loop. And that fixed it :D It was very simple apperently !
I'm developing a webpage that has many forms with some text close to form. This form and text are generated by a function, but I get this
As you can see the forms and the text are not aligned with forms and text below. I would like to have this:
(this work because I put spaces manually). This is how I create forms.
function add_form($product,$name,$productp)
{
$productpt = "X";
echo $name;
echo '<input type="text" name="'. $product. '" id="'. $product. '" style="font-size:12pt;height:30px"/> x'.$productp. '€
price:'.$productpt.'€<br>';
}
echo '<form method="post" name="form1" id="form1" autocomplete="off">'; //start form
echo '<div class="leftpane">'; //start leftpane
echo '<h1>';
echo '<font size="6" color="red"> ALIMENTS </font><br>';
//ADD ELEMENTS IN MY MENU
//The first argument is the form name and id, the second is the name that will be printed(to the left of the form), the third argument is the price.
$menu[] = new Menu("pasta", "Pasta", 2);
$menu[] = new Menu("spaghetti", "Spaghetti", 1.50);
$menu[] = new Menu("pizza", "Pizza", 5);
$menu[] = new Menu("chicken_wings_x4", "Chicken Wings X4", 4.50);
$menu[] = new Menu("cheeseburger", "Cheeseburger", 6);
$menu[] = new Menu("Sandwich", "Sandwich", 2);
$menu[] = new Menu("hamburger", "Hamburger", 4.50);
$menu[] = new Menu("stuff", "stuff", 15.50);
//FOR EACH ELEMENT CREATE A FORM
for($i=0; $i<count($menu); $i++){
add_form($menu[$i]->form_name, $menu[$i]->name, $menu[$i]->price);
}
echo '</h1>';
echo '</div>'; //Close leftpane
...Do Others stuff in middlepane and in rightpane
To be clearer in html, for example the first form will be:
<input type="text" name="pasta" id="pasta" style="font-size:12pt;height:30px"/> x2€ price:X€<br>
I thought to divide in 3 parts my leftpane and to place $name to the left, the form to the middle and the price to the right. But the problem is that i create form in function, so I do not know how to do it.
This is my css:
<style>
input[type=text] {
width: 10%;
margin: 7.5px 0;
box-sizing: border-box;
}
input[type=submit].class1 {
width: 50%;
padding: 12px 20px;
margin: 8px 0;
box-sizing: border-box;
}
input[type=submit].class2 {
width: 50%;
padding: 12px 20px;
margin: 8px 0;
box-sizing: border-box;
}
body, html {
width: 100%;
height: 100%;
margin: 0;
}
.container {
width: 100%;
height: 100%;
}
.leftpane {
width: 33%;
height: 100%;
float: left;
border-collapse: collapse;
}
.middlepane {
width: 33%;
height: 100%;
float: left;
border-collapse: collapse;
}
.rightpane {
width: 33%;
height: 100%;
position: relative;
float: right;
border-collapse: collapse;
}
form {
display: inline-block;
}
h1 {
font-size: 19.5px;
}
</style>
I would suggest you to use a table. https://www.w3schools.com/html/html_tables.asp
Or you could wrap every section into a div-container and define its width.
I think your output code would really benefit from some additional HTML structure with classes that allow you to control their layout in a consistent way with CSS. I would update the add_form() function:
function add_form($product,$name,$productp) {
$productpt = "X";
echo '<div class="form-wrap">';
echo '<span class="form-name">' . $name . '</span>';
echo '<input type="text" name="'. $product. '" id="'. $product. '"/> <span class="form-label">x'.$productp. '€</span> <span class="form-price">price:'.$productpt.'€</span>';
echo '</div>';
}
Then with the output having more targetable HTML structure you can do this with CSS:
.form-wrap input {
font-size: 12pt;
height: 30px
}
.form-name {
display: inline-block;
width: 100px;
margin-right: 20px;
}
.form-label {
display: inline-block;
margin-left: 5px;
margin-right: 20px;
}
<div class="form-wrap">
<span class="form-name">Something</span>
<input type="text" name="something" id="somethingId" />
<span class="form-label">x1€</span>
<span class="form-price">price:1€</span>
</div>
<div class="form-wrap">
<span class="form-name">Another one</span>
<input type="text" name="anotherone" id="somethingId2" />
<span class="form-label">x2€</span>
<span class="form-price">price:2€</span>
</div>
<div class="form-wrap">
<span class="form-name">Number Three</span>
<input type="text" name="thirdone" id="somethingId3" />
<span class="form-label">x3€</span>
<span class="form-price">price:3€</span>
</div>
Try this.
function add_form($product,$name,$productp)
{
$productpt = "X";
echo "<table><tr>";
echo "<td width='20%'>" . $name . "</td>";
echo "<td width='20%'><input type='text' name='". $product . "' id='" . $product . "' style='font-size:12pt;height:30px;' /></td>";
echo "<td width='20%'>x" . $productp . "€</td>";
echo "<td width='20%'>price:" . $productpt . "€</td>";
echo "</tr></table>";
}
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.
This question already has answers here:
How to fix "Headers already sent" error in PHP
(11 answers)
Closed 9 years ago.
I am currently encountering a problem that keeps giving me the error on the question title. here is my code, can anyone help me check what is wrong and how to fix it? Thank you so much.
The following part is the bottom part of a php file including "Header":
echo'<table>';
while ($result = mysql_fetch_array($sql, MYSQL_ASSOC)){
echo '<tr>';
echo '<td style="width:142px">';
echo $result['instrument_id'];
echo '</td>';
echo '<td style="width:142px">';
echo $result['instrument'];
echo '</td>';
echo '<td style="width:142px">';
echo $result['type'];
echo '<br>';
echo $result['amount'].' shares';
echo '</td>';
echo '<td style="width:142px">';
echo $result['opening_rate'];
echo '<br>';
$fp = fopen ("http://finance.yahoo.com/d/quotes.csv?s='".$result['instrument']."'&f=nsb2b3p2ophg.csv","r");
//this uses the fgetcsv function to store the quote info in the array $data
$data = fgetcsv ($fp, 1000, ",");
echo ($data[3]);//current rate
echo '</td>';
echo '<td style="width:142px">';
echo $result['opening_value'];
echo '<br>';
$value = $data[3] * $result['amount'];
$currentvalue = number_format($value, 2, '.', '');
echo $currentvalue;//current value
echo '</td>';
echo '<td style="width:142px">';
echo $result['open_time'];
echo '</td>';
echo '<td style="width:142px">';
if($data[3] == 0){
echo '<input type="submit" name="close'.$result['instrument_id'].'" value="Close" disabled="disabled"/>';}
else{
echo '<input type="submit" name="close'.$result['instrument_id'].'" value="Close"/>';}
echo '</td>';
echo '</tr>';
fclose ($fp);
$name = 'close'.$result['instrument_id'];
$close = isset($_POST[$name]);
if($close){
$instrumentid = $result['instrument_id'];
$_SESSION['instrumentid'] = $instrumentid;
$instrument = $result['instrument'];
$_SESSION['instrument'] = $instrument;
$amount = $result['amount'];
$_SESSION['amount'] = $amount;
header("Location:order_sell.php");
}
}
echo'</table>';
When I include a file on the top, which is the background file, only including html elements, it will give me the error message like Warning: Cannot modify header information ...
here is the code for the included file:
<?php
session_start();
// checks if $_SESSION['userid'] exists
$areYouLoggedIn = isset($_SESSION['username']);
?>
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
/* background*/
body { background: url(images/background2.png) center center fixed no-repeat;
webkit-background-size:cover;
moz-bacground-size:cover;
-o-background-size:cover;
background-size:cover;}
/* top menu layout*/
.Topmenu{
width:1000px;
background: #00AEEF;
border-radius: 3px 3px 3px 3px;
}
/* top menu cell layout*/
.Tabcells{ width:200px;
text-align:center;
}
/* top menu cell text layout*/
/* top menu cell text layout*/
.Tabtexteffect
{ text-decoration: none;
color:white;
font-family:Arial;
font-size:15px;
}
.Tabtexteffect:hover
{
text-decoration: none;
color:white;
font-family:Arial;
font-size:20px;
}
.Paragraph {text-align:justify;
text-justify:distributed-all-lines;
text-align-last:justify;
font-family:arial;
font-size:12pt;
width:1000px;
}
.Box {
width:950px;
text-align:left;
background: -webkit-linear-gradient(90deg, #F0E68C, #FFFFE0) repeat scroll 0 0 transparent;
background: -moz-linear-gradient(90deg, #F0E68C, #FFFFE0) repeat scroll 0 0 transparent;
border: 1px solid #AAAAAA;
border-radius: 10px 10px 10px 10px;
box-shadow: 0 0 15px #AAAAAA;
}
.Box2 {
width: 200px;
text-align: left;
background: -webkit-linear-gradient(90deg, #FFFA8C, #FFFFE0) repeat scroll 0 0 transparent;
background: -moz-linear-gradient(90deg, #FFFA8C, #FFFFE0) repeat scroll 0 0 transparent;
border: 1px solid #AAAAAA;
border-radius: 10px 10px 10px 10px;
box-shadow: 0 0 15px #AAAAAA;
}
.Button {
background: -moz-linear-gradient(90deg, #0459B7, #08ADFF) repeat scroll 0 0 transparent;
background: -webkit-linear-gradient(90deg, #0459B7, #08ADFF) repeat scroll 0 0 transparent;
border: 1px solid #093C75;
border-radius: 3px 3px 3px 3px;
box-shadow: 0 1px 0 #FFFFFF;
color: #FFFFFF;
cursor: pointer;
font-family: Arial,sans-serif;
font-size: 12px;
font-weight: bold;
margin-right: -16px;
margin-top: 16px;
padding: 5px 10px;
text-decoration: none;
text-shadow: 0 1px 1px #333333;
text-transform: uppercase;
}
</style>
</head>
<body>
<form action="HomePage.php" method="POST">
<div style="width:1000px; margin:0 auto; min-height:100%;">
<div>
<img style="width:25%;" src="images/Mock Apprentice.png" alt="Mock Apprentice"></img>
<?php
if($areYouLoggedIn==false){
echo'<table cellpadding="0" align="right" style="position: absolute; left: 940px; top: 15px;">';
echo'<tr>';
echo'<td width="130" align="center"><font face="Arial" size="3"><input type="button" class="Button" value="Sign In""/></font></td>';
echo'<td width="1" bgcolor=black><BR></td>';
echo'<td width="100" align="center"><font face="Arial" size="3"><input type="button" class="Button" value="Sign Up""/></font></td>';
echo'</tr>';
echo'</table>';
}
if($areYouLoggedIn == true){
echo'<table cellpadding="0" align="right" style="position: absolute; left: 950px; top: 40px;">';
echo'<tr>';
echo'<td width="130" align="center"><font face="Arial" size="4" color="#00AEFF">Welcome';
echo' ';
echo'<font color="#FFD700">';
echo($_SESSION['username']);
echo'</font>';
echo'</font></td>';
echo'<td width="1" bgcolor=black><BR></td>';
echo'<td width="100" align="center"><font face="Arial" size="4"><a style="text-decoration: none; color:#00AEFF;" href="Logout.php">Logout</a></font></td>';
echo'</tr>';
echo'<table>';
}
?>
<HR color="#00AEEF">
</div>
<div>
<table width="1020" height="30" class="Topmenu">
<tr>
<td width="200" height="30" class="Tabcells">Intro</td>
<td width="200" class="Tabcells">How to use</td>
<td width="200" class="Tabcells">Education Center</td>
<td width="200" class="Tabcells">Trading Platform</td>
<td width="196" class="Tabcells">Contact Us</td>
</tr>
</table>
</div>
</div>
</form>
</body>
</html>
Thank you so so so much!
Try replacing header("Location:order_sell.php"); with
echo '<META HTTP-EQUIV="Refresh" Content="0; URL=order_sell.php">';
exit;
Whatever you output - being HTML only or output from PHP: Unless you do some tricking with the ob_*() functions you lose the ability to send headers the moment you output anything.
This is why they are called headers: In the HTTP protocol they preceed every single piece of payload body - including whitespace such as empty lines before a <?php tag.
The typical way to tackle this would be to regroup your logic as to first calculate what headers you need, then create your output, via echo(), printf(), include() or whatever.
In PHP header functions must be called before any output is sent from the server. This includes echo calls as well as HTML info before the <?php ?> block.
You can't send a header after any text has been sent to the browser:
header("Location:order_sell.php");
Needs to be before ANY text/output/whitespace is sent/echo'ed to the browser.
When using header("Location:someLocation") be sure that you don't have any character outputted to the browser, otherwise you'll get the error Cannot modify header information. More on this at: http://php.net/manual/en/function.header.php
The following code is only grabbing the value of the last result in the PHP while loop. Any / all help much-appreciated. Thanks!
PHP/HTML/JS:
<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="width: 8%; margin-left: 13%;">Status</span>
<span style="width: 15%;">From</span>
<span style="width: 45%;">Subject</span>
<span style="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>" . $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")) {
$(".theMessage").fadeIn(1000);
}
});
return false;
});
</script>
</section>
When you say "grabbing the value of the last result," I'm guessing you're talking about the following line?
<div class="theMessage" style="display: none;"><?php echo $theMessage; ?></div>
That's outside the while() loop, so yeah, $theMessage will just retain the last value from the loop.
Seeing as how you're starting the <form> within the else block but closing the </form> outside the else block, I'm guessing you're ending your while and if-else too early.
First of all you have a syntax error in your code.
Escape double quotes or use single quotes for HTML.
What javascript library are you using? Looks like it could be JQuery?
If you expect your selector to return an array, then you need to use an iterator to act on each element. Try the each iterator function: http://api.jquery.com/each/
$('.outerDiv').each(function() {
this.click( function(e) {....