While loop looping through data twice - php

So I have this code, and I've been fretting over it for several hours now and my friend and I can't find the solution. It display reviews based on a descending ID pulled from a database. This is an endless scroll type of script to eliminate pagination. For some reason when I hit the bottom of the page and run the script, the while loop is iterating through the data twice. So if its supposed to display reviews ID 5 - 10, it display 10, 9, 8, 7, 6, 5, 10, 9, 8, 7, 6, 5; instead of 10, 9, 8, 7, 6, 5. This is going to be a very large bit of code, But I hope you can help me with my problem.
Thanks in advance!!
<?php
include("../mysql_server/connect_to_mysql.php");
if($_GET['lastPost']) {
$mysqlQuery = mysql_query('SELECT * FROM `reviews` WHERE `review_id` < "' . $_GET['lastPost'] . '" ORDER BY `review_id` DESC LIMIT 0, 10');
while ($review_row = mysql_fetch_assoc($mysqlQuery)) {
$review_title = $review_row['review_title'];
$user_id = $review_row['user_id'];
$user_firstname = $review_row['user_firstname'];
$user_lastname = $review_row['user_lastname'];
$review_id = $review_row['review_id'];
$review_body = $review_row['review_body'];
$review_referral = $review_row['review_referral'];
// Code to append text for title
// strip tags to avoid breaking any html
$review_title = strip_tags($review_title);
if (strlen($review_title) > 30) {
// truncate string
$stringCut = substr($review_title, 0, 30);
// make sure it ends in a word so assassinate doesn't become ass...
$review_title = substr($stringCut, 0, strrpos($stringCut, ' ')).'...';
}
// Code to append text and add Read More
// strip tags to avoid breaking any html
$review_body = strip_tags($review_body);
if (strlen($review_body) > 230) {
// truncate string
$stringCut = substr($review_body, 0, 230);
// make sure it ends in a word so assassinate doesn't become ass...
$review_body = substr($stringCut, 0, strrpos($stringCut, ' ')).'... <a class="reviewContentLink" href="../../pages/home_page/post_content.php?id='. $review_id .'">See Full Post</a>';
} else {
$review_body .= '<a class="reviewContentLink" href="../../pages/home_page/post_content.php?id='. $review_id .'">See Full Post</a>';
}
$review_date = $review_row['review_date'];
$review_date = date_create($review_date);
$review_date = date_format($review_date, 'g:ia \o\n F jS\, Y');
$user_firstname = $review_row['user_firstname'];
$review_rating = $review_row['rating'];
/////// Mechanism to Display Pic. See if they have uploaded a pic or not //////////////////////////
$check_pic = "../members/$user_id/thumb_image01.jpg";
$default_pic = "../members/0/image01.jpg";
if (file_exists($check_pic)) {
$review_pic = "<img src=\"../$check_pic\" width=\"80px\" />";
} else {
$review_pic = "<img src=\"../$default_pic\" width=\"80px\" />";
}
include_once('../include/star_display.php');
//Pull the Review Category from the row
$review_category = "";
$review_category = $review_row['review_category'];
include_once('../include/review_category.php');
//Pull the Referral Category from the row
$referral_category = $review_row['referral_category'];
include_once('../include/referral_category.php');
//Code for URL for Each Review
$review_url = $review_row['review_url'];
if (!function_exists('remove_http')) {
function remove_http($url = '') {
return(str_replace(array('http://','https://'), '', $url));
}
}
//CODE TO DISTINGUISH REFERRALS FROM REVIEWS
//Final Output List
if($review_referral == 0) {
//Code for Displaying URL Link
$review_url = remove_http($review_url);
$review_url = "<a target='_BLANK' href='http://". $review_url ."'>Buy It Here!</a> ";
echo ''. $review_id .' '. $review_referral .'
<div class="display_newsfeed" id="'.$review_id.'">
<table id="'.$review_id.'" style="width:98.5%; border:#00B347 1px solid; margin:10px 0px 20px 10px;">
<td style="float:left; width:15%; border-right:1px solid #DDDDDD; margin:5px 0px 5px 0px;">
<div class="review_user_name">'. $user_firstname.' '. $user_lastname .'</div>
<div class="review_prof_pic">'. $review_pic .'</div>
<div class="bought_it_newsfeed">Bought It!</div>
</td>
<td style="float:right; width:82%;">
<div class="review_title_p">
<p><span class="review_title">'. $review_title .'</span><span class="review_date_p">'. $review_date .'</span><span class="review_stars">'. $review_stars .'</span></p>
</div>
<div class="review_read_more">
<p class="review_body_p">'. $review_body .'</p><br />
<div>
<div style="float:left;" class="review_black_font_link">Website:'.$review_url.'</div>
<div style="float:right; margin-right:20px;" class="review_black_font_link">Category: '.$review_category_post .'</div>
</div>
</div>
</td>
</table>
<hr style="margin:0px 20px 0px 20px;" />
</div>
';
} else if($review_referral == 1) {
//Code for Displaying URL Link
$review_url = remove_http($review_url);
$review_url = "<a target='_BLANK' href='http://". $review_url ."'>Click Here</a> ";
echo '
<div class="display_newsfeed" id="'.$review_id.'">
<table id="'.$review_id.'" style="width:98.5%; border:#0099FF 1px solid; margin:10px 0px 20px 10px;">
<td style="float:left; width:15%; border-right:1px solid #DDDDDD; margin:5px 0px 5px 0px;">
<div class="review_user_name">'. $user_firstname.' '. $user_lastname .'</div>
<div class="review_prof_pic">'. $review_pic .'</div>
<div class="referral_newsfeed">Referral</div>
</td>
<td style="float:right; width:82%;">
<div class="review_title_p">
<p>'. $review_title .'<span class="review_date_p">'. $review_date .'</span><span class="review_stars">'. $review_stars .'</span></p>
</div>
<div class="review_read_more">
<p class="review_body_p">'. $review_body .'</p><br />
<div>
<div style="float:left;" class="review_black_font_link">Business Website:'. $review_url .'</div>
<div style="float:right; margin-right:20px;" class="review_black_font_link">Category: '. $referral_category_post .'</div>
</div>
</div>
</td>
</table>
<hr style="margin:0px 20px 0px 20px;" />
</div>
';
}
}
} else {
echo "didn't work";
}
?>

Are you also sure there is no corruption in your database? you can try just
while ($review_row = mysql_fetch_assoc($mysqlQuery)) {
echo $review_row['review_title'] . "<br />";
}

Can you post the code that calls/posts to this script? As the others stated, it is quite possible this code is being called twice.
Also, if you run this query directly in the database, what is returned?
SELECT *
FROM `reviews`
WHERE `review_id` < (insert the id here)
ORDER BY `review_id` DESC
LIMIT 0, 10

Related

Unknown column 'activation_code' in 'field list'

I have a problem with my website of a game called World of Warcraft. In the registration part when I want to register, I skip this error
Unknown column 'activation_code' in 'field list'
I created the account, I can enter the page, but at the time of entering the game it tells me that my account is blocked
Unknown column 'activation_code' in 'field list'
Here is my file Register.php... help me please
> <?php
require_once("".$_SERVER['DOCUMENT_ROOT']."/header.php");
/*generate the code for activate the acccount*/
function random_str($length, $keyspace = '_0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')
{
$keyspace = str_shuffle($keyspace );
$pieces = [];
$max = mb_strlen($keyspace, '8bit') - 1;
for ($i = 0; $i < $length; ++$i) {
$pieces []= $keyspace[random_int(0, $max)];
}
return implode('', $pieces);
}
$regcode = random_str(255);
/*
$a = random_str(32);
$b = random_str(8, 'abcdefghijklmnopqrstuvwxyz');
*/
/*END genetare code*/
function encryptpw($user, $pass) {
$user = strtoupper($user);
$pass = strtoupper($user);
return sha1($user.':'.$pass);
}
//store all results from query records
$results = array();
$accexist = 'SELECT * FROM battlenet_accounts WHERE email = "'.$_POST['email'].'"';
//SQL select query
$accexistresult = mysqli_query($dbh, $accexist)or die(mysqli_error($dbh));
//execute SQL statement
$accexistrows = mysqli_num_rows($accexistresult);
// get number of rows returned
if($accexistrows){
while($row = mysqli_fetch_array($accexistresult)){
$results["accexist"] = $row;
}
}
$emailexist = $results["accexist"]["email"];
if(isset($_POST['submit']) AND $emailexist == ""){
$email = strtoupper($_POST['email']);
$expansion = "7";
$bnetindex = "1";
$acclock = "1";
$accunlock = "0";
// Battlenet Password
$bnetpassword = strtoupper(bin2hex(strrev(hex2bin(strtoupper(hash("sha256",strtoupper(hash("sha256", strtoupper($email)).":".strtoupper($_POST['pass']))))))));
// Queries
if($insbnet = 'INSERT INTO battlenet_accounts (email, sha_pass_hash, locked) VALUES ("'.$email.'", "'.$bnetpassword.'", "'.$acclock.'");'){
$insbnetresult = mysqli_query($dbh, $insbnet);
$getaccid = 'SELECT * FROM battlenet_accounts WHERE email = "'.$email.'"';
//SQL select query
$getaccidresult = mysqli_query($dbh, $getaccid)or die(mysqli_error($dbh));
//execute SQL statement
$getaccidrows = mysqli_num_rows($getaccidresult);
// get number of rows returned
if($getaccidrows){
while($row = mysqli_fetch_array($getaccidresult)){
$results["id"] = $row;
}
}
$id = $results["id"]["id"];
$bnetacc = $id;
$username = $bnetacc."#".$bnetindex;
$accpassword = encryptpw($username, $_POST['pass']);
if($insacc = 'INSERT INTO account (username, sha_pass_hash, email, expansion, battlenet_account, battlenet_index, activation_code) VALUES ("'.$username.'", "'.$accpassword.'", "'.$email.'", "'.$expansion.'", "'.$bnetacc.'", "'.$bnetindex.'", "'.$regcode.'")'){
$insaccresult = mysqli_query($dbh, $insacc) or die(mysqli_error($dbh));
//execute SQL statement
$results = array();
$success = '<h3 style="color: green;" align="center">Your Account: <span style="color: white;">' . strtolower($email) . '</span>
was created successfully! An email was sent to you with informations on how to activate it.</h3>';
//start the mail() setup
$password = $_POST['pass'];
$youremail = 'noreply#shadowmelt.com';
$subject = 'ShadowMelt Register Confirm';
$message = '<html><head>';
$message .= '</head><body>';
$message .= '<p align="left">Greetings,</p>';
$message .= '<p align="left">You are receiving this email because you register on our Website platform with this email <b>( ' . strtolower($email) . ' )</b>. If you not did this action, please delete this message.</p>';
$message .= '<p align="left">Next, it follows the data for you to Login in-game, however you need to activate your account to be able to play. To activate your Account, please click on next link or copy paste on your browser:</p>';
$message .= '<p align="center"><a style="
-moz-box-shadow:inset 0px 1px 0px 0px #ffffff;
-webkit-box-shadow:inset 0px 1px 0px 0px #ffffff;
box-shadow:inset 0px 1px 0px 0px #ffffff;
background:-webkit-gradient(linear, left top, left bottom, color-stop(0.05, #ededed), color-stop(1, #dfdfdf));
background:-moz-linear-gradient(top, #ededed 5%, #dfdfdf 100%);
background:-webkit-linear-gradient(top, #ededed 5%, #dfdfdf 100%);
background:-o-linear-gradient(top, #ededed 5%, #dfdfdf 100%);
background:-ms-linear-gradient(top, #ededed 5%, #dfdfdf 100%);
background:linear-gradient(to bottom, #ededed 5%, #dfdfdf 100%);
filter:progid:DXImageTransform.Microsoft.gradient(startColorstr=\'#ededed\', endColorstr=\'#dfdfdf\',GradientType=0);
background-color:#ededed;
-moz-border-radius:6px;
-webkit-border-radius:6px;
border-radius:6px;
border:1px solid #dcdcdc;
display:inline-block;
cursor:pointer;
color:#777777;
font-family:Arial;
font-size:15px;
font-weight:bold;
padding:13px 24px;
text-decoration:none;
text-shadow:0px 1px 0px #ffffff;
" href="https://www.shadowmelt.com/register?confreg=' . $regcode . '">Activate Account</a></p>';
$message .= '<p align="left"><b>Login:</b> ' . strtolower($email) . ' <br /><b>Password:</b> ' . $password . '</p>';
$message .= '<p align="left">For more information, how to connect, visit us on our website!</p>';
$message .= '</body></html>';
$headers = 'From: ' . $youremail . "\r\n";
$headers .= 'MIME-Version: 1.0' ."\r\n";
$headers .= 'Content-Type: text/HTML; charset=utf-8' . "\r\n";
$sendto = $email;
mail($sendto, $subject, $message, $headers);
}else{
echo "Insert account error...";
}
}else{
echo "Insert baccount error...";
}
}elseif(isset($_POST['submit']) AND $emailexist != ""){
$accexisterror = '<h3 style="color: red;" align="center">Your Account was not Created! That email <span style="color: white;">'.strtolower($email).'</span> already exists.</h3>';
}
?>
<div class="content">
<div class="container row">
<div id="left-content">
<div class="post_wrap">
<div class="news">
<br>
<br>
<br>
<!-- Main -->
<?php
if(isset($_GET["confreg"]) != ""){
$acclock = "1";
$accunlock = "0";
$confreg = htmlspecialchars($_GET["confreg"]);
$getaccemail = 'SELECT * FROM account WHERE activation_code = "'.$confreg.'"';
//SQL select query
$accemailresult = mysqli_query($dbh,$getaccemail) or die(mysqli_error($dbh));
//execute SQL statement
$accemailrows = mysqli_num_rows($accemailresult);
// get number of rows returned
if($accemailrows){
while($row = mysqli_fetch_array($accemailresult)){
$results["email"] = $row;
}
}
$idaccemail = $results["email"]["email"];
$getacccode = 'SELECT * FROM account WHERE email = "'.$idaccemail.'"';
//SQL select query
$acccoderesult = mysqli_query($dbh,$getacccode);
//execute SQL statement
$acccoderows = mysqli_num_rows($acccoderesult);
// get number of rows returned
if($acccoderows){
while($row = mysqli_fetch_array($acccoderesult)){
$results["storedcode"] = $row;
}
}
$storedcode = $results["storedcode"]["activation_code"];
$getacclock = 'SELECT * FROM battlenet_accounts WHERE email = "'.$idaccemail.'"';
//SQL select query
$acclockresult = mysqli_query($dbh,$getacclock);
//execute SQL statement
$acclockrows = mysqli_num_rows($acclockresult);
// get number of rows returned
if($acclockrows){
while($row = mysqli_fetch_array($acclockresult)){
$results["storedlock"] = $row;
}
}
$storedlock = $results["storedlock"]["locked"];
if(isset($confreg) == $storedcode AND $storedlock == $acclock){
$activacc = 'UPDATE battlenet_accounts SET locked = "'.$accunlock.'" WHERE email = "'.$idaccemail.'"';
//SQL select query
$activaccresult = mysqli_query($dbh,$activacc);
//execute SQL statement
if($activaccresult){
echo '<h3 style="color: green;" align="center">Your Account: <span style="color: white;">' . strtolower($idaccemail) . '
</span> was Activated! How to Connect?</h3>';
}else{
echo '<h3 align="center"><span style="color: red;">Your Account: </span><span style="color: white;">' . strtolower($idaccemail) . '
</span> was Not Activated. Something went wrong, please verify if you copy the correct full link, and if you continue receiving
this error message, please contact us!</h3>';
echo '<script type="text/javascript">alert(" Something went wrong, please verify if you copy the correct full link, and if you continue receiving
this error message, please contact us!");</script>';
}
}elseif(isset($confreg) == $storedcode AND $storedlock == $accunlock){
echo '<h3 align="center"><b>(i)</b> <i style="color: yellow;">Your account has already been activated.</i></h3>';
echo '<script type="text/javascript">alert("Your account has already been activated.");</script>';
}elseif(isset($confreg) != $storedcode){
echo '<h3 align="center"><b>(i)</b> <i style="color: yellow;">We can not identify this link!</i></h3>';
echo '<script type="text/javascript">alert("We can not identify this link!");</script>';
}else{
echo '<script type="text/javascript">alert("Something was wrong! We do not identify the issue, please contact us.");</script>';
}
}elseif(isset($success)){
echo $success;
}elseif(isset($accexisterror)){
echo $accexisterror;
}else{
?>
<h3 style="font-size:20px;font-weight:bold;text-transform:uppercase;" align="center">Sign-Up for Shadowmelt!</h3>
<hr />
<br />
<br />
<br />
<div style="width: 630px; margin-left: auto; margin-right: auto;"><form style="display: inline;" target="_blank" action=""><input type="hidden" name="shadowmelt" value="1" /><button class="upmenu">ShadowMelt [Legion]</button></form>
<form style="display: inline; margin-left: 20px;" target="_blank" action="http://www.rainandthunder.net/#register"><button class="upmenu">RainAndThunder [Vanilla]</button></form></div>
<br />
<br />
<br />
<hr />
<form action="" method="post" name="reg">
<table style="border-spacing: 30px; border-collapse: separate;" class="form">
<tr>
<td align="right">
E-mail Address:
</td>
<td align="left">
<input style="width: 400px; font-size: 16px;" name="email" type="email" maxlength="254" placeholder="Please insert a valid email(1)" required />
</td>
</tr>
<tr>
<td align="right">
Password:
</td>
<td align="left">
<input style="width: 400px; font-size: 16px;" name="pass" type="password" maxlength="16" placeholder="Insert a password to use on login" required />
</td>
</tr>
<tr>
<td align="right">
Confirm password:
</td>
<td align="left">
<input style="width: 400px; font-size: 16px;" name="pass2" type="password" maxlength="16" placeholder="Insert again your password" required />
</td>
</tr>
<tr>
<td></td>
<td align="center">
<input type="submit" class="sbm" value="Register" name='submit' />
</td>
</tr>
</table>
</form>
<p align="center"><b>¹</b> <i style="color: yellow;">Is required use a valid email, to activate your Account,
since our system will send you an email with details on how to activate your Account.</i></p>
<?php } ?>
</div>
</div>
</div>
<div id="right-content">
<br>
<img src="images/box.png">
</div>
</div>
</div>
<?php include_once("".$_SERVER['DOCUMENT_ROOT']."/footer.php"); ?>
You just have to add this not existing column:
ALTER TABLE account
ADD activation_code char(64);
either this table column is still missing or you have just spelled it wrong, if necessary check that before you create a new column for nothing

php while loop images that store in mysql and onlick modal

My intention is to display the content(which is stored in mysql) if the picture is clicked.
<?php
$query = "SELECT * FROM pet where pet_cat = 'D' ORDER BY petid ";
$result = mysqli_query($con, $query);
while($row = mysqli_fetch_assoc($result))
{
$_SESSION['petname'] = $row['petname'];
$_SESSION['petdesc'] = $row['petdesc'];
$_SESSION['petimg'] = $row['petimg'];
echo '<li style="
padding-right: 20px;
padding-left: 20px;">';
echo '<a style= "cursor: pointer;"onclick= "document.getElementById(\'dogmod\').style.display=\'block\'">';
echo '<img src="data:image/jpeg;base64,'.base64_encode($_SESSION['petimg'] ).'" />';
echo '<h4>';
echo $_SESSION['petname'] ;
echo '</h4>';
include 'desca.php';
echo '</a>';
echo '</li>';
}
?>
The modal only display one content and that is the first content of the first picture.(sorry for bad english )
This is the code of my modal:
<div id="dogmod" class="modal">
<center>
<form class="modal-content animate" style="margin: 0; padding-left:50px; padding-right:50px; padding-bottom:50px;">
<div class="imgcontainer">
<span onclick="document.getElementById('dogmod').style.display='none'" class="close" title="Close">×</span>
<h1 align=center>Description</h1>
<?php echo '<img src="data:image/jpeg;base64,'.base64_encode($_SESSION['petimg'] ).'" style="margin-top:50px;float:left; margin-right:50px;"/>'; ?>
<h1 style="margin-top:50px;margin-bottom:50px">
<?php echo $_SESSION['petname'] ;?>
</h1>
<p style="margin-bottom:50px;">
<?php echo $_SESSION['petdesc'] ;?>
</p>
<input type="button" value="Back" onclick=location.href='doga.php' class="button_1" style=" width: auto;padding: 10px 18px; background-color: #f44336; border:0px; color:white;">
<h2> </h2>
</form>
</center>
<script>
// Get the modal
var modal = document.getElementById('dogmod');
// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = "none";
}
}
</script>
</div>
The problem is that you are generating many modals with the same "id".
What happens in this case is that you will be displayed only the last image in the table.
Generate your modal id dynamically.
Use php and add an affix to the id attribute of the modal and call that one in your onclick event.
Here is how you do it:
$query = "SELECT * FROM pet where pet_cat = 'D' ORDER BY petid ";
$result = mysqli_query($con, $query);
while($row = mysqli_fetch_assoc($result))
{
$_SESSION['petname'] = $row['petname'];
$_SESSION['petdesc'] = $row['petdesc'];
$_SESSION['petimg'] = $row['petimg'];
$_SESSION['petid'] = $row['petid'];
echo '<li style="
padding-right: 20px;
padding-left: 20px;">';
echo '<a style= "cursor: pointer;"onclick= "document.getElementById(\'dogmod'.$row['petid'].'\').style.display=\'block\'">';
echo '<img src="data:image/jpeg;base64,'.base64_encode($_SESSION['petimg'] ).'" />';
echo '<h4>';
echo $_SESSION['petname'] ;
echo '</h4>';
include 'desca.php';
echo '</a>';
echo '</li>';
}
And in your modal php file, change only your first line to:
<div id="dogmod<?=$_SESSION['petid']?>" class="modal">
You should be good to go.
To make it close just fine, do the following in your modal php template find the 'close' link:
<span onclick="document.getElementById('dogmod<?= $_SESSION['petid'] ?>').style.display='none'" class="close" title="Close">×</span>

How to put radio button with a php value

I am currently having a trouble using the radio button, I'm getting confuse because of the output of my codes. In the left picture that's what my output like, in the right picture I want my output like that. When I choose from the candidates both radio button can choose instead of only one should be can be chosen.
Here's my code:
<?php
$YearNow=Date('Y');
$dsds=$rowasa['posid'];
$results = $db->prepare("SELECT * FROM candidates,student,school_year,partylist where student.idno = candidates.idno AND school_year.syearid = candidates.syearid AND posid =:a AND candidates.partyid = partylist.partyid AND school_year.from_year like $YearNow ");
$results->bindParam(':a', $dsds);
$results->execute();
for($i=0; $rows = $results->fetch(); $i++){
?>
//here's the part that i was confuse
<input type ="radio"><input style="padding: 35px 50px 35px 80px; background:url('admin/candidates/images/<?php echo $rows['image']; ?>') no-repeat scroll 5px 7px / 70px auto rgba(0, 0, 0, 0);"
value="<?php echo $rows['candid'] . "-" ."&nbsp". $rows['lastname'] .",". "&nbsp". $rows['firstname'] ?>"><?php echo $rows['lastname'] ?>,
<?php echo $rows['firstname'] ?>
- <?php
echo $rows['party_name']?>
<?php
}
?>
It looks like you SQL query is giving you the right results however I would really look into using JOINs. Regardless, im assuming your SQL results are something like this:
$candidates = array(
array(
"id" => "1",
"firstname" => "John",
"image" => "some/image/path",
"party_name" => "Party1",
),
array(
"id" => "2",
"firstname" => "Jane",
"image" => "some/image/path",
"party_name" => "Party2",
)
);
To iterate through this and build your HTML, it will be a lot easier to use foreach like so:
<form method="post" action="submit.php">
<?php
foreach ($candidates as $candidate) {
?>
<div class="box">
<div class="image">
<img src="admin/candidates/images/<?php echo $candidate['image']; ?>" alt="">
</div>
<div class="input">
<input type="radio" name="candidate_selected" value="<?= $candidate['id'] ?>">
</div>
<div class="text">
<?php echo $candidate['firstname'] . " - " . $candidate['party_name'] ?>
</div>
</div>
<?php
}
?>
<input type="submit">
</form>
Notice how the input has the same name and the id of your candidate results. Once this is submitted, you should only see the id of the selected candidate in your submit.php handler.
Now add some CSS:
.box {
display: inline-block;
text-align: center;
}
.box .image {
padding: 15px;
}
.box .image img {
width: 150px;
height: 150px;
display: block;
}
Hope this helps.
Try echo the radio button like this.
<?php
$YearNow=Date('Y');
$dsds=$rowasa['posid'];
$results = $db->prepare("SELECT * FROM candidates,student,school_year,partylist where student.idno = candidates.idno AND school_year.syearid = candidates.syearid AND posid =:a AND candidates.partyid = partylist.partyid AND school_year.from_year like $YearNow ");
$results->bindParam(':a', $dsds);
$results->execute();
for($i=0; $rows = $results->fetch(); $i++){
//here's the part that i was confuse
echo "<input type ='radio'><input style='padding: 35px 50px 35px 80px; background:url('admin/candidates/images/". $rows['image'] . "') no-repeat scroll 5px 7px / 70px auto rgba(0, 0, 0, 0);
value='" . $rows['candid'] . " - "$rows['lastname'] ", ". $rows['firstname'] . "'>" . $rows['lastname'] . "," . $rows['firstname'];
echo $rows['firstname'] ." - ". $rows['party_name'];
}
?>

table page break in CSS

I am implementing the printing of pages in HTML.
My aim is if a table will not be accommodated in the same page, the whole table will be transferred to the next page. How do i do this. i have this code.. please help me.
here is my CSS part.
<style type="text/css">
.printOnly {
margin-top: 100px;
display: none;
}
.textSummaryTable { page-break-inside:auto }
.textSummaryTable tr { page-break-inside:avoid; page-break-after:auto }
#media print {
.summaryTable tr:nth-child(odd){ background-color:#E1E4E5;}
.summaryTable tr:nth-child(even) { background-color:#ffffff; }
.printOnly { display: block; }
.panel {
border: 1px solid transparent;
padding: 2px;
margin: 0;
}
.textSummaryTable{ border:1px solid gray; }
.textSummaryTable td{ border:1px solid gray; }
#main {
overflow: hidden;
position: absolute;
padding: 0px;
height: auto;
width: 100%;
}
#title { display: none; }
#line-break { display: block; }
.textSummaryTable { width: 100%; }
}
#media screen {
#line-break { display: none; }
}
</style>
and My tables are here.
<?php
$this->pageTitle = Yii::app()->name . ' - View Evaluation';
$user = LoginForm::getUser();
?>
<?php $participants = $modelE->evaluationDetails; ?>
<style type="text/css">
#media print {
body {
overflow: hidden;
}
}
</style>
<div class=" non-printable">
<div class='pull-right non-printable'>
<button id="btnPrint" type="button" class="btn btn-default pull-right" onclick="window.print();">
<span class="glyphicon glyphicon-print"></span> Print
</button>
</div>
<?php
$startDate = date("M j, Y", strtotime($modelE->start_date));
$endDate = date("M j, Y", strtotime($modelE->end_date));
?>
</div>
<div id='line-break'>
<br>
<br>
<br>
</div>
<div class="container-fluid">
<div class="printable">
<h4><?php echo htmlentities($modelE->evaluationForm->name); ?></h4>
<h5><?php echo $startDate; ?> - <?php echo $endDate; ?></h5>
<h5>Candidate: <?php echo htmlentities($modelE->evaluatee); ?></h5>
<h5>Overall Evaluation: <?php echo htmlentities($modelE->getResult()); ?></h5>
<h5>Participants: <?php echo htmlentities(count($participants)); ?></h5>
<div class="panel panel-default">
<div class="panel-body">
<h5><strong>Instructions: </strong> <?php echo htmlentities($modelE->evaluationForm->description); ?></h5>
<!-- <h4>Results Summary</h4> -->
<?php
$radioFlag = false;
foreach ($modelE->evaluationForm->evaluationFormDetails as $question) {
$criteria = new CDbCriteria;
$criteria->with = 'evalResult';
$criteria->addInCondition('eval_form_question_id', array($question->id));
$criteria->addInCondition('evalResult.eval_id', array($modelE->id));
$resultSet = EvaluationResultsDetails::model()->findAll($criteria);
if ( strtolower($question->field_type) != "radioheader" && $question->field_type != "slider" ) {
if($radioFlag){
echo "</table>";
$radioFlag = false;
}
if( $question->field_type == "text" ) {
echo "<h4>" . $question->field_name . "</h4>";
}
else {
echo "<table class='textSummaryTable'><tr><td style='width: 100%'><label>" . $question->field_name . "</label></td></tr>";
foreach ($resultSet as $answer) {
echo "<tr><td>" . $answer->eval_answer . "</td></tr>";
}
echo "</table>";
}
} else {
if(!$radioFlag){
echo '<table border-size = 0px width=100% class="summaryTable">';
$radioFlag = true;
}
echo "<tr><td style='width: 90%'>" . $question->field_name . "";
echo "</td><td style='width: 10%'>";
$sum = 0;
$count = 0;
foreach ($resultSet as $answer) {
$count++;
$sum += $answer->eval_answer;
}
echo $count == 0 ? "-" : number_format($sum / $count, 2);
echo "</td></tr>";
/*** end here ***/
}
}
if($radioFlag){
echo "</table>";
}
?>
<table class="printOnly">
<tr>
<td colspan="2">
<p> I hereby certify that all information declared in this document are accurate and true. Each item have been discussed with my Immediate Superior and mutually agreed upon.</p>
</td>
</tr>
<tr>
<td>
<p>Prepared by
<?= $modelE->project->manager->family_name . ", " . $modelE->project->manager->first_name ?>
</p>
Date <?= date("Y-m-d"); ?>
</td>
<td>
<p>Conformed by <?= $modelE->evaluatee ?></p>
Date
</td>
</tr>
<tr>
<td colspan="2">
<p>Noted by HR Division</p>
</td>
</tr>
</table>
</div>
</div>
</div>
</div>
</div>

replace symbol .= php

hello i have this code:
$thread_qry5= "SELECT * FROM xenProve_prove ORDER BY view_count DESC LIMIT 5";
$row5 = XenForo_Application::get('db')->fetchAll($thread_qry5);
foreach ( $row5 AS $rows5 ) {
$viewid = $rows5['thread_id'];
$viewtitle = $rows5['title'];
$viewuser = $rows5['username'];
$MostView .= 'div style="height:30px; width:640px; border-bottom:1px solid #999;padding:5px;">
<div style="height:40px; width:500px;float:left">
<div style="height:20px; width:650px; font-size:16px;color:#6d3f03;">'.$viewtitle.'</div>
<div style="height:20px; width:650px; font-size:12px;color:#6d3f03;">'.$viewuser.'</div>
</div>
</div>';
how can replace this symbol .= ?
Xenforo system don't read this symbol (.=)
I tried :
$MostView = 'div style="height:30px; width:640px; border-bottom:1px solid #999;padding:5px;">
<div style="height:40px; width:500px;float:left">
<div style="height:20px; width:650px; font-size:16px;color:#6d3f03;">'.$viewtitle.'</div>
<div style="height:20px; width:650px; font-size:12px;color:#6d3f03;">'.$viewuser.'</div>
</div>
</div>' . $MostView;
but don't work.
And i tried the For cycle anche the While cycle but don't work.
Thanks you
You are trying to add a string to another string (by a concatenating assignment operator) that doesn't exist (yet). You have to define the string first:
$MostView = '';
and then:
foreach ( $row5 AS $rows5 ) {
$viewid = $rows5['thread_id'];
$viewtitle = $rows5['title'];
$viewuser = $rows5['username'];
$MostView .= 'div style="height:30px; width:640px; border-bottom:1px solid #999;padding:5px;">
<div style="height:40px; width:500px;float:left">
<div style="height:20px; width:650px; font-size:16px;color:#6d3f03;">'.$viewtitle.'</div>
<div style="height:20px; width:650px; font-size:12px;color:#6d3f03;">'.$viewuser.'</div>
</div>
</div>';
I don't think this problem is related to XenForo. If you turn on error reporting (just check Google or Stack Overflow) you will get more usefull information about this error.

Categories