Repeated Record in php and mysql - php

I am trieng to list item form the database, however, the result comes out in two. 2 result is displayed for each record. currently i only have one record in the database but when i display them on the screen it is repaeted. i do not know why this is happening, i have tried to palce a counter and see how many times the loop goes on and the result is always once. however the result is displayed two times.
the code as follows:
<section class="container">
<div class="row">
<?php
if($bidCollection->selectBidsByStatusAndAppId(BidAccount::OPEN_NEW, $id)){
foreach($bidCollection->getBids() as $bid){
$banker->find($bid->getCustomerId());
$counter=0;
?>
<div class='col-xs-12 bg-more-light-gray bidlist'>
<div class="col-xs-12 col-sm-1 col-md-1">
<?php
if(!$uploader->findProfilePicture($banker->data()->_customer_id)){
echo "<img src='image/holder.png ' width='50' height='50' class='img-responsive' />";
}else{
echo "<img src='upload/proPicture/".$uploader->data()->pictureUrl."' width='50' height='50' class='img-responsive'/>";
}
?>
</div>
<div class="col-xs-12 col-sm-8 col-md-8">
<?php
echo '<h2>Agent name :'.$validate->cleanInput($banker->data()->officer_name).'</h2>';
echo '<h3>Institute name : '.$validate->cleanInput($banker->data()->bank_name).' '.++$counter.'</h3>';
if($bid->getApplicationOwnerId() === $customer->data()->_customer_id){
echo "<p>CheckBook: ";
if($bid->getRequestCheckBook()){echo "Yes";}else{echo "No";}
echo "</p>";
echo"<p> Minimum Deposit: AED ".$bid->getMinDeposit()."</p>";
echo"<p> Direct Debit Card: ";
if($bid->getRequestCreditCard()){echo "Yes";}else{echo "No";}
echo "</p>";
echo"<p> Other Fees / Arrangement Fees: AED ".$bid->getFees(). "</p>";
echo"<p> Account Will be ready in: ".$bid->getSetupTime() ."</p>";
}
?>
</div>
<div class="col-xs-12 col-sm-2 col-md-2">
<?php
$datetime = new DateTime($bid->getDatePosted());
$date = $datetime->format('Y-m-d');
$time = $datetime->format('H:i:s');
echo '<h4> Date: '.$date.'<br/>Time: '.$time.'</h4>';
echo"<form method='POST' action='viewBanker.php'>";
echo "<input type='hidden' name='banker' value='".$bid->getCustomerId()."'>";
echo "<input type='submit' class ='btn btn-default' name='submit' value='View Profile'>";
echo "</form>";
echo'<br/>';
if($bid->getApplicationOwnerId() === $customer->data()->_customer_id){
echo"<form method='post' action='acceptAccountBid.php'>";
echo "<input type='hidden' value='".$bid->getCustomerId()."' name ='bankerId'/>";
echo "<input type='hidden' value='".$id."' name ='appid'/>";
echo "<input type='hidden' value='".$bid->getApplicationOwnerId()."' name='ownerId'>";
echo "<input class='btn btn-default' type='submit' value='Accept Offer' name='submit'>";
echo"</form>";
}
?>
</div>
</div>
<?php
}
}
?>
The Methods that returns the the values is as follows:
public function selectBidsByStatusAndAppId($status, $appid)
{
$sql = "SELECT * FROM accountBid WHERE application_id = :appId AND status = :st";
try {
$sth = $this->_db->getConnection()->prepare($sql);
$sth->bindValue(':appId', $appid);
$sth->bindValue(':st', $status);
$sth->execute();
} catch (Exception $e) {
$this->setAlert('danger', 'Information Presentation Error: ' . $e->getMessage());
}
foreach ( $sth->fetchAll(PDO::FETCH_ASSOC) as $data) {
$this->addBid($data);
}
return true;
}
public function addBid($data = null)
{
$bid = new BidAccount($data);
$this->bids[] = $bid;
}
public function getBids()
{
return $this->bids;
}

first of all, I want to thank my mates who tried to help me earlier. the problem was I had another function which I forgot to post it here bidExist()
public function bidExist( $appId , $id){
$sql = "SELECT * FROM accountBid WHERE application_id = :appId AND _customer_id = :id";
try {
$sth = $this->_db->getConnection()->prepare($sql);
$sth->bindValue(':appId', $appId);
$sth->bindValue(':id', $id);
$sth->execute();
} catch (Exception $e) {
$this->setAlert('danger', 'Information Presentation Error: ' . $e->getMessage());
}
foreach ( $sth->fetchAll(PDO::FETCH_ASSOC) as $data) {
$this->addBid($data);
}
return $sth->rowCount();
}
The function above looped through the collection to check and see if the object exists before this and if it is then you can not add anymore bid, however, i forgot to remove the addBid() function on this method and that cause the object to be added twice to the collection. This took me the whole night to figure out. but I thank everyone who tried to support and assist.

Related

Same page is loading when clicking pagination in DataTable PHP

When I click page number in DataTable, it is not moving to next page instead it loads the whole page again.
But if I click the DataTable sorting button and again I click the pagination page number, the DataTable is working fine. Can anyone help me to solve this. Thanks in advance.
<?php include 'header.php'; ?>
</style>
<!-- Breadcrumbs -->
<section class="bg-gray-7">
<div class="breadcrumbs-custom box-transform-wrap context-dark">
<div class="container">
<h3 class="breadcrumbs-custom-title">Sailing Schedules</h3>
<div class="breadcrumbs-custom-decor"></div>
</div>
<div class="box-transform" style="background-image: url(images/bg-typography.jpg);"></div>
</div>
<div class="container">
<ul class="breadcrumbs-custom-path">
<li>Home</li>
<li class="active">Sailing Schedule</li>
</ul>
</div>
</section>
<br>
<br>
<div class="container">
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
// Include config file
require 'config.php';
$sql = "SELECT * FROM long_sched";
if($result = mysqli_query($con, $sql)){
if(mysqli_num_rows($result) > 0){
echo "<table class='table-custom table-custom-primary' id ='long_schd_table'>";
echo "<thead>";
echo "<tr>";
echo "<th>Service Name</th>";
echo "<th>Description</th>";
echo "</tr>";
echo "</thead>";
echo "<tbody>";
while($row = mysqli_fetch_array($result)){
echo "<tr>";
echo "<td><a href=http://localhost/permatest/". $row['long_filepath'] . " target='_self' download>".$row['long_service']."</a></td>";
echo "<td>" . $row['long_desc'] . "</td>";
echo "</tr>";
}
echo "</tbody>";
echo "</table>";
// Free result set
mysqli_free_result($result);
} else {
echo "<p class='lead'><em>No records were found.</em></p>";
} else {
echo "ERROR: Could not able to execute ".$sql." " . mysqli_error($con);
}
// Close connection
mysqli_close($con);
?>
</div>
</section>
<br>
<br>
<?php include 'off_footer.php'; ?>
<script>
$('#long_schd_table').DataTable({});
</script>
The above code is giving this error but in my console I didn't get any error information.

SQL Insert executes twice, php

Couldn't find a straight answer to this. My custom wordpress php code seems to be executed twice when I click on the submit once. When clicked, the codes adds two cities with the same name. As you can see, I tried to aviod this by checking for duplicates, but it ignores it... I tried moving the html to a function, but not help there either. Now my code looks weird and still no solution. Any new ideas?
<?php get_header(); ?>
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<?php
// Start the loop.
while ( have_posts() ) : the_post();
// Include the page content template.
get_template_part( 'template-parts/content', 'page' );
if ( comments_open() || get_comments_number() ) {
comments_template();
}
// End of the loop.
endwhile;
?>
</main><!-- .site-main -->
<?php
function showForm() {
echo "<form name='submit' method='post'>";
echo "<select name='countriesSelect'>
<option value='-1'>Choose...</option>";
$conn = new mysqli('localhost','a','b','c');
$query = "SELECT id,country_name FROM countries";
$result = $conn->query($query);
while($row = $result->fetch_assoc()) {
echo "<option value='" . $row['id'] . "'>" . $row['country_name'] . "</option>";
}
$conn->close();
echo "</select><br /><br />
Now choose a new city: <input type='text' name='cityname' maxlength='30' size='30' value='' style='width: 300px;' /><br /><br />
That is it: <br />
<input type='submit' value='Add new city' /><br /><br />
</form>";
return;
}
if (!empty($_POST['cityname']) && !empty($_POST['countriesSelect'])) {
$cityname = $_POST['cityname'];
$countriesSelect = $_POST['countriesSelect'];
// make sure city doesn't exist - also because for some unknown reason this script is called twice =/
$db = new mysqli('localhost','a','b','c');
$query = "SELECT city_name FROM cities WHERE city_name='$cityname'";
$result = $db->query($query);
$row = $result->fetch_assoc();
if (empty($row['city_name'])) {
// add new city
$query = "INSERT INTO cities (country_id, city_name, amount_raised_usd) VALUES ($countriesSelect, '$cityname', 0)";
$result = $db->query($query);
if ($db->query($query) === TRUE) {
echo "<div style='color: green;'>New city added successfully. Add another?";
} else {
echo "<div style='color: red;'>Error: " . $query . " :: " . $db->error;
}
echo '</div><br /><br />';
}
$db->close();
showForm();
} else {
showForm();
}
?>
<?php get_sidebar( 'content-bottom' ); ?>
</div><!-- .content-area -->
<?php get_footer(); ?>
Do you see this
$result = $db->query($query);
And the next line:
if ($db->query($query) === TRUE) {
This means that you run your query twice. Remove one of the $db->query, e.g.:
$result = $db->query($query);
if ($result === TRUE) { /* do stuff */
you execute the query twice:
$result = $db->query($query);
if ($db->query($query) === TRUE) {
should be:
$result = $db->query($query);
if ($result === TRUE) {

Pagination issue in my wordpress site. Some array is showing up

http://larasaget.com/works/sculpture/
You can see it in the bottom of the page Array ( [0] => Resource id #388 [1] => [2] => 5 )
I am not sure how this originated but the pagination is working fine. Only needs to remove the array.
Here is the code from the page template.
ajax-works.php
<?php
$rootD = $_SERVER['DOCUMENT_ROOT'];
include_once($rootD.'/wp-config.php');
if(is_file(dirname(__FILE__) .'/ajaxpaging.php')){
include_once(dirname(__FILE__) .'/ajaxpaging.php');
}elseif(is_file(dirname(__FILE__) .'/../ajaxpaging.php')){
include_once(dirname(__FILE__) .'/../ajaxpaging.php');
}elseif(is_file(dirname(__FILE__) .'/../../ajaxpaging.php')){
include_once(dirname(__FILE__) .'/../../ajaxpaging.php');
}
$ajax_pageing = new get_pageing_ajax();
global $post;
$pageid=$post->ID;;
define(TEMPLATE_URL,get_template_directory_uri()."/");
define(SITE_URL,get_bloginfo('url')."/");
$ajax_page = TEMPLATE_URL."ajax_works.php";
$listdivid = "gallery_div";
$perpage = "6";
if(isset($_REQUEST[gallery_id]) && $_REQUEST[gallery_id]!=""){
$gallery_id=$_REQUEST[gallery_id];
}else{
if($pageid==117)// Performance
$gallery_id=2;
elseif($pageid==374)//Paper
$gallery_id=3;
elseif($pageid==361)//press
$gallery_id=4;
else //Sculpture
$gallery_id=1;
}
$pg_query_string="&gallery_id=".$gallery_id;
$selgallery= "select * from ls_ngg_gallery where gid = ".$gallery_id;
$gres=mysql_query($selgallery);
if(mysql_num_rows($gres)>0)
$galval=mysql_fetch_array($gres);
$sel='SELECT * FROM ls_ngg_pictures WHERE exclude != 1 AND galleryid = '. $gallery_id .' ORDER by pid DESC';
$res = $ajax_pageing->number_pageing($sel,$perpage,0,'N','Y',"",$ajax_page,$pg_query_string,$listdivid);
?>
<div class="col-lg-8 col-md-8 col-sm-12 col-xs-12">
<div class="pagetitle"><h1><?php the_title()?></h1></div>
<div class="works">
<?php $total=mysql_num_rows($res[0]);
if($total>0)
{?>
<div class="row">
<?php
while($val=mysql_fetch_array($res[0])){
$secondesc= nggcf_get_field($val[pid], "Second Description");
$thirddesc= nggcf_get_field($val[pid], "Third Description");
?>
<div class="col-lg-4 col-md-4 col-sm-6 col-xs-6">
<a rel="lightbox[work_group]" href="<?php echo site_url() . '/' .$galval['path'] . '/' . $val['filename'];?>"
title="<?php echo $val[alttext]?><br /><?php echo $val[description]?><br /><?php echo $secondesc;?><br />
<?php echo $thirddesc?> "><img src="<?php echo site_url() . '/' .$galval['path'] . '/thumbs/thumbs_' . $val['filename']?>"
class="workimage" alt="work_group: image <?php echo $i?> 0f <?php echo $total?> thumb"/></a>
<div class="text-center worktitle">
<?php echo $val[alttext]?>
</div>
</div> <!-- .col-lg-4 .col-md-4 .col-sm-6 .col-xs-6 -->
<?php }?>
</div> <!-- end .row -->
<div class="row">
<div class="col-lg-6"></div>
<div class="col-lg-6 text-right">
</div>
</div>
<?php
}?>
</div>
<div class="clear"></div>
<?php print_r($res); ?>
</div>
ajaxpaging.php
<?php
class get_pageing_ajax{
var $record_per_page=10;
var $pages=5;
var $tbl,$file_names,$order,$query;
///////// GET THE VALUE OF START VARIABLE////////////////
function start()
{
if($_REQUEST["start"])
return $start=$_REQUEST["start"];
else
return $start=0;
}
////////////// END OF START FUNCTION///////////////////
////////////// GET THE CURRENT FILE NAME ///////////////////
function file_names()
{
$pt=explode("/",$_SERVER['SCRIPT_FILENAME']);
$totpt=count($pt);
return $this->file_names=$pt[$totpt-1];
}
////////////// END OF FILE_NAME FUNCTION///////////////////
////////////// DISPLAY THE NUMERIC PAGING WITHOUT RECORD DETAIL///////////////////
function number_pageing_nodetail($query,$record_per_page='',$pages='')
{
return $this->number_pageing($query,$record_per_page,$pages,"N");
}
function number_pageing_bottom_nodetail($query,$record_per_page='',$pages='')
{
return $this->number_pageing($query,$record_per_page,$pages,"N","Y");
}
function number_pageing_bottom($query,$record_per_page='',$pages='')
{
return $this->number_pageing($query,$record_per_page,$pages,"","Y");
}
////////////// END OF NUMERIC PAGING FUNCTION ///////////////////
function runquery($query)
{
return mysql_query($query);
}
function table($result,$titles,$fields,$passfield="",$edit,$delete,$parent="")
{
if($parent=="")
$parent="Y";
if($passfield=="")
$passfield="id";
$cont="<table width='100%' cellspacing='0' cellpadding='3' border='0' class='borders'><tr>";
foreach($titles as $K=>$V)
{
$cont1.="<td";
$cont1.=(is_numeric($V))?" width='$V%' align='center'><strong>$K</strong></td>":" align='center'><strong>$V</strong></td>";
}
$cont.=$cont1."</tr>";
$cont.="<tr><td colspan='".count($titles)."'><script language=javascript>
msg=\"<table border=0 cellpadding=3 cellspacing=1 class='bg1' width='100%'><TR>$cont1</TR></table>\";
</script>
<script src='topmsg.js'></script>
</td></tr>";
$j=0;
while($gets=mysql_fetch_object($result))
{
$j=1;
$cont.="<tr onMouseOver=\"this.className='yellowdark3bdr'\" onmouseout=\"this.className=''\">";
foreach($fields as $K=>$V)
{
$cont.="<td align='center'>";
$tmps=explode(",",$V);
$newval="";
foreach($tmps as $val)
{
$newval.=$gets->$val." ";
}
$cont.=(is_numeric($K))?$newval:"".$newval."";
$cont.=" </td>";
}
$cont.="<td><INPUT name='button' type='button' onClick=\"";
$cont.=($parent=="N")?"window":"parent.body";
$cont.=".location.href='$edit?$passfield=".$gets->$passfield."'\" value='Edit' onMouseOver=\"smsg('Edit This Record -> $newval');return document.prs_return\" onMouseOut=\"nosmsg('Done');return document.prs_return\"> <INPUT onClick=\"deleteconfirm('Are you sure you want to delete this Record?.','$delete?$passfield=".$gets->$passfield."');\" type='button' value='Delete' onMouseOver=\"smsg('Delete This Record -> $newval');return document.prs_return\" onMouseOut=\"nosmsg('Done');return document.prs_return\"> </td>";
$cont.="</tr>";
}
if($j==0)
{
$cont.="<tr><td colspan='".(count($fields)+1)."' align='center'><font color='red'><strong>No Record To Display</strong></font></td></tr>";
}
echo $cont.="</table>";
}
///////////// NUMERIC FUNCTION WITH RECORD DESTAIL//////////////////////////////////////
function number_pageing($query,$record_per_page='',$pages='',$detail='',$bottom='',$simple='',$cur_page="",$query_string="",$divid="")
{
$this->file_names();
$this->query=$query;
if($record_per_page>0)
$this->record_per_page=$record_per_page;
if($pages>0)
$this->pages=$pages;
$this->query=$query;
$result=$this->runquery($this->query);
$totalrows= mysql_affected_rows();
$start=$this->start();
$order=$_GET['order'];
$this->query.=" limit $start,".$this->record_per_page;
$result=$this->runquery($this->query);
$total= mysql_affected_rows();
$total_pages=ceil($totalrows/$this->record_per_page);
$current_page=($start+$this->record_per_page)/$this->record_per_page;
$loop_counter=ceil($current_page/$this->pages);
$start_loop=($loop_counter*$this->pages-$this->pages)+1;
$end_loop=($this->pages*$loop_counter)+1;
if ($current_page > 2)
$start_loop = $current_page-2 ;
if ($total_pages >= $current_page + 3)
{
$end_loop = $current_page + 3;
}
if($end_loop>$total_pages)
$end_loop=$total_pages+1;
$tmpva="";
foreach($_REQUEST as $V=>$K)
{
if($V!="start")
$tmpva.="&".$V."=".$K;
}
//$this->tbl="<table width='100%' border='0' cellpadding='0' cellspacing='0'><tr><td width='15%' align='left'> ";
$this->tbl="<ul class='pagination'>";
if ($cur_page == "")
$cur_page = $this->file_names;
if($start>0)
{
//$this->tbl.="<a class='paging' href='".$cur_page."?start=".($start-$this->record_per_page).$query_string."' class='boldbluelink' onMouseOver=\"smsg('Previous Page');return document.prs_return\" onMouseOut=\"nosmsg('Done');return document.prs_return\"><< Previous</a> ";
$this->tbl.="
<li class='num_off' onclick=call_ajax_view('".$cur_page."','start=".($start-$this->record_per_page).$query_string."','".$divid."')><a>«</a></li>";
}
else
{
$this->tbl.="<li class='num_on'><a>«</a></li>";
}
//$this->tbl.=" </td><td width='70%' align='center' class='bluenormaltahoma'> ";
if($detail!="N" and $simple !="N")
$this->tbl.="Result ".($start+1)." - ".($start+$total)." of ".$totalrows." Records<BR>";
if($simple!='N')
{
for($i=$start_loop;$i<$end_loop;$i++)
{
if($current_page==$i)
{
//$this->tbl.="<span class='currnet_page'>[".$i."]</span> ";
$this->tbl.="<li class='num_on_active'><a>".$i."</a></li>";
}
else
{
//$this->tbl.="<a class='paging' href='".$cur_page."?start=".($i-1)*$this->record_per_page.$query_string."' class='boldbluelink' onMouseOver=\"smsg('View Page Number $i');return document.prs_return\" onMouseOut=\"nosmsg('Done');return document.prs_return\">".$i."</a> ";
$this->tbl.="<li class='num_off' onclick=call_ajax_view('".$cur_page."','start=".($i-1)*$this->record_per_page.$query_string."','".$divid."')><a>".$i."</a></li>";
}
}
}
//$this->tbl.=" </td><td width='15%' align='right'>";
if($start+$this->record_per_page<$totalrows)
{
//$this->tbl.="<a class='paging' href='".$cur_page."?start=".($start+$this->record_per_page).$query_string."' class='boldbluelink' onMouseOver=\"smsg('Next Page');return document.prs_return\" onMouseOut=\"nosmsg('Done');return document.prs_return\">Next >></a>";
$this->tbl.="<li class='num_off' onclick=call_ajax_view('".$cur_page."','start=".($start+$this->record_per_page).$query_string."','".$divid."')><a>&raquo</a></li>";
}
else
{
$this->tbl.="<li class='num_on'><a>»</a></li>";
}
$this->tbl.="</ul>
";
if($bottom=="Y")
{
return $result=array($result,$this->tbl,$total_pages);
}
else
{
echo $this->tbl;
return $result;
}
}
////////////// SIMPLE NEXT-PRI PAGING ///////////////////
function pageing($query,$record_per_page="",$pages="")
{
return $this->number_pageing($query,$record_per_page,$pages,'','','N');
}
////////////// END OF SIMPLE PAGING FUNCTION///////////////////
////////////// WRITE ALL,A TO Z CHARACTER WITH CURRENT PAGE LINK ///////////////////
function order()
{
$this->file_names();
$this->order.="<TR><TD><a class=la href='".$this->file_names."' onMouseOver=\"smsg('View All Records');return document.prs_return\" onMouseOut=\"nosmsg('Done');return document.prs_return\">All</a></TD><TD class=lg>|</TD>";
for($i=65;$i<91;$i++)
{
$this->order.="<TD><a class=la href='$file_names?order=".chr($i)."' onMouseOver=\"smsg('View By ".chr($i)."');return document.prs_return\" onMouseOut=\"nosmsg('Done');return document.prs_return\">".chr($i)."</a></TD><TD class=lg>|</TD>";
}
return $this->order.="</TR>";
}
function MakeCombo($query,$value="",$fill_value,$comboname)
{
if($value=="")
$value=$fill_value;
$run=$this->runquery($query);
$totlist=mysql_affected_rows();
$Combo="<select name='$comboname'>";
$Combo.="<option value=''>----------Select-----------</option>";
for($i=0;$i<$totlist;$i++)
{
$get=mysql_fetch_object($run);
$Combo.="<option value='".$get->$value."'>".$get->$fill_value."</option>";
}
$Combo.="</select>";
echo $Combo;
}
}
?>
Replace
<?php print_r($res); ?>
with
<?php $ajax_pageing->number_pageing($sel,$perpage,0,'N','N',"",$ajax_page,$pg_query_string,$listdivid); ?>
And remove call to number_pageing on top of file.
Calling number_pageing method will echo it. No need to echo or print_r it again.

use string for select statement in database pdo php

This is just a thought i have for my project is it possible to use a string for example an echo as parameter for select statement in database query?
here is the scenario:
For example when my page loads i automatically display the latest data in database say last five entry, as echo of course. and for each entry there are other details and in order to view those other details i will have an anchor for each echo and i will direct the user to another page..using the echo i want to query the database for other details..
Is this possible?
I know I cant put attribute name to echo so how is this possible?
Any suggestions?
Update
this is the page that will show the echo
<form method="POST" action="crud.php" enctype="multipart/form-data" >
<div class="headerimage"><img src="images/events.png"/></div>
<?php
foreach (LoadEvent() as $value){
echo '<div id="upcomingevent">';
//echo "<a href=\"#\" >".$value['searchresultwhat']."</a>";
echo "".$value['searchresultwhat']."";
echo "<input type='hidden' name=\"eventwhatcontent\" value=".$value['searchresultwhat'].">";
echo "<br/>\n";
echo $value['searchresultwhen'];
echo "<br/>\n";
echo $value['searchresultwhere'];
echo '</div>';
}
?>
</form>
then this is the method and the page where i must display the details of the event
<form method="POST" action="crud.php" enctype="multipart/form-data" >
<?php
echo '<div id="middlecontentupcomingevents">';
LoadSpecificEvent();
echo '<div id="upcomingeventcontentimage">';
echo "<img src=\"admin/".$events[4]."\">";
echo $events[0];
echo $events[1];
echo $events[2];
echo $events[3];
echo '</div>';
echo "<br/>\n";
echo '</div>';
echo '</div>';
?>
</form>
function LoadSpecificEvent(){
global $dbh;
//var_dump($dbh);
if (isset($_POST['eventwhatcontent'])) {
$eventwhat = $_POST['eventwhatcontent'];
$stmt = $dbh->prepare("SELECT * FROM events WHERE event_what = ?");
$stmt->bindValue(1,$eventwhat);
$stmt->execute();
$events = array();
$selected_row = $stmt->fetch(PDO::FETCH_ASSOC);
$events[] = array(
'searchresultwhat' => $selected_row['event_what'],
'searchresultwhere' => $selected_row['event_where'],
'searchresultwhen' => $selected_row['event_when'],
'searchresultwho' => $selected_row['event_who'],
'searchresultimg' => $selected_row['img_url']
);
print_r ($events);
return $events;
}
}

PDO Messed Up My CSS / HTML Layout

One of my webpages that had perfect format under MySQL_* functions, suddenly got mixed up when I translated the old functions to PDO. The problem is that my Copyright bar is now floating above my table of MySQL data, while it should be at the bottom of the page. I'm not sure why it's happening. Any help is appreciated!
This is the portion of the file that I believe may be the problem:
<div id="content" style="float:center;background-image:url('http://tinyurl.com/bds4u2j');">
<ul class="menu">
<li>
<?php
if(!isset($_COOKIE['username'])){
echo "Welcome, guest!";
}else{
echo "Welcome, " . $_COOKIE['username'];
}
?>
</li>
<li><br></li>
<li><a class="item" href="index.html">Home</a></li>
<li><a class="item" href="classes.html">Classes</a></li>
<li><a class="item" href="contact.html">Contact</a></li>
<?php
if(!isset($_COOKIE['username'])){
echo '<li><a class="item" href="login.html">Login</a></li>';
}else{
echo '<li><a class="item" href="upload.html">Upload</a></li>';
echo '<li><a class="item" href="password_protect.php?logout=1">Logout</a></li>';
}
?>
</ul>
<center><h1>Mr. Stanford's first period</h1></center>
<br>
<center><h3>Your class files are available for download below</h3></center>
<br>
<br>
<center>
<?php
echo "<table border='1'>
<tr>
<th>Filename</th>
<th>Description</th>
<th>Download</th>";
IF(isset($_COOKIE["username"]))
{
echo "<th>Delete</th>","</tr>";
}
ELSE
{
echo "</tr>";
}
try{
$dbh = new PDO('mysql:host=$host;port=$port;dbname=$dbname','$username','$password');
foreach($dbh->query('SELECT * from period1') as $row) {
echo "<tr>";
echo "<td>" . $row['Filename'] . "</td>";
echo "<td>" . $row['Description'] . "</td>";
echo "<td><a href = ". $row['File'] ." ><button>Download</button></a></td>";
IF(isset($_COOKIE["username"]))
{
echo "<td><a href = 'deletefile.php?$s_id=". $row['s_id'] ."'><button>Delete</button></a></td>","</tr>";
}
ELSE
{
echo "</tr>";
}
echo "</table>";
}
$dbh=null;
} catch (PDOException $e) {
print "<br>ERROR: " . $e->getMessage() . "<br/>";
die();
}
$dbh=null;
?>
</center>
<br>
<br>
<br>
</div>
<div id="footer" style="background-color:#99FF33;clear:both;text-align:center;">
Copyright © David Schilpp 2013, All Rights Reserved
</div>
Again, thank you to anybody who can help me debug this problem!
I guessed that your table was not closed. see comments on question.
When you are facing this kind of problem (broken html), you should first analyse the html generated.
You can right-click on page and select View page source.
You can use tools freely available too.
As always, StackOverflow is great place to find answer and new stuff

Categories