PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
BEACON
Forum Newbie
Posts: 5 Joined: Mon Jun 04, 2012 7:48 pm
Post
by BEACON » Mon Jun 04, 2012 9:57 pm
Hi
I have this weird issue, I am listing all videos from a database, 5 videos per page with an option to skip to a certain page.
[text]
Previous 1 2 3 4 5 6........39 40 Next
[/text]
The weird thing is that it is repeatedly listing videos from the previous page.
For example when i click on page 2 , I get page 2 with only one video that was not on the 1st page and 4 videos that were already listed on page 1.
Anyone can please help with the code:
thanks
Code: Select all
?>
<SPAN
class=bodytext> <?=stripslashes($LangRes->Language)?></SPAN><span class="bluebold"><br>
Subtitles: </span>
<SPAN
class=bodytext><?=stripslashes($LangRes1->Language)?></SPAN></p>
</td>
<td valign="top"><SPAN class=newstitle>
<font size="4"><?=stripslashes($value->Title)?><br>
</font></SPAN>
<SPAN
class=bodytext><b><font size="2"><?=stripslashes($value->ShortDesc)?></font></b></SPAN></td>
</tr>
<tr>
<td height="118" valign="top">
<SPAN class=bodytext><?=stripslashes($value->LongDesc)?></SPAN>
<!--<br><a href="showVideo.php?vid=<?=$value->Id;?>">More...</a>-->
</td>
</tr>
<tr>
<td height="1" colspan="3" bgcolor="#CCCCCC"></td>
</tr>
<? } }?>
<tr>
<td colspan="2" class="text"> </td>
<td> </td>
</tr>
<tr>
<td colspan="2" class="text">
<p align="center"><? if($cnt>$size) {
if($page>=$size){ ?>
<a href="?page=<?=$page-1?>&size=<?=$size?>&act=all&lang=<?=$myLang?>&cat=<?=$myCat?>"><b>
Previous</b></a>
<? } else echo "Previous ";
// Build Previous Link
for($i = 1; $i <= $totalpage; $i++){
if(($page) == $i){
echo "$i";
} else {
echo ("<a href=http://www.watchmyvideos.com/video.php?cat=$cat&size=$size&page=$i> $i </a> ");
}
}
?> <? if($page_rows>($page+1)) { ?>
<a href="?page=<?=$page+1?>&size=<?=$size?>&act=all&lang=<?=$myLang?>&cat=<?=$myCat?>"><b>
Next</b></a>
<? } else echo "Next"; } ?></td>
</tr>
</table>
</td>
</tr>
</table>
<?
requinix
Spammer :|
Posts: 6617 Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA
Post
by requinix » Mon Jun 04, 2012 11:16 pm
And the code where you query the database would be... what?
Actually let me just guess at the problem. With LIMIT X,Y in your query, X is the starting offset. Not the starting page. Then Y is the number of items to show from that point. So if all you know is the starting page then you have to do a little math to get the offset (hint: subtract one and multiply by the number of items per page).
BEACON
Forum Newbie
Posts: 5 Joined: Mon Jun 04, 2012 7:48 pm
Post
by BEACON » Tue Jun 05, 2012 2:02 pm
Hi Requinix,
you are right I should have post all of the code, sorry about that:
I think this is the code you were asking about, below it I posted the the complete code that has issues.
thank you
Code: Select all
<!-- BEGIN INCLUDE video_header.inc -->
<TH>
<form name="filter_form">
<TABLE width="100%" cellspacing="3" cellpadding="0" align=center border=0>
<TR><TD bgcolor="#052560" height="17" align=left><img border="0" src="images/0video.jpg" width="256" height="17"></TD></TR>
<TR>
<TD align=center>
<span class="bodytext">Select language:</span><?
$LangObj = new LanguageDetails();
$LangRes = $LangObj->SelectAllLanguageDetails();
$CatObj = new CatDetails();
$CatRes = $CatObj->SelectAllCatDetails();
?>
<select name="Language_Filter" id="Language_Filter" style="font-size: 9pt" size="1">
<?
$LangDis = "";
foreach ($LangRes as $value)
{
if ($value->Id != 6) {
$LangDis .= "<option value=\"$value->Id\""
.
( isset($_REQUEST['lang']) && ($_REQUEST['lang']!='') && $_REQUEST['lang'] == $value->Id ? ( $LangStatus = "selected" ) : "")
.
">$value->Language</option>";
}
}
if ($LangStatus != "selected") {
echo "<option value=\"all\" selected>All languages</option>";
} else {
echo "<option value=\"all\">All languages</option>";
}
echo $LangDis;
?>
</select>
<span class="bodytext">Select category:</span>
<select name="Category_Filter" id="Category_Filter" style="font-size: 9pt" size="1">
<?
$CatDis = "";
foreach ($CatRes as $value)
{
$CatDis .= "<option value=\"$value->Id\""
.
( isset($_REQUEST['cat']) && ($_REQUEST['cat']!='') && $_REQUEST['cat'] == $value->Id ? ( $CatStatus = "selected" ) : "")
.
">$value->CatName</option>";
}
if ($CatStatus != "selected") {
echo "<option value=\"all\" selected>All categories</option>";
} else {
echo "<option value=\"all\">All categories</option>";
}
echo $CatDis;
?>
</select>
<span class="bodytext"> <a href="javascript:FilterLanguage();">GO</a></span></TD>
</TR>
</TABLE> </form>
</TH>
<!-- END INCLUDE video_header.inc -->
Here is the code:
Code: Select all
<? ob_start();?>
<?
include_once("includes/header.inc.php");
include_once("includes/sidebar.inc.php");
?>
<TABLE class=defMain>
<TBODY>
<TR>
<?php
include ("includes/video_header.inc");
?>
<TR>
<TD class=content>
<div align="center">
<table border="0" cellpadding="5" cellspacing="0" width="100%">
<?
$cnt=0;
/////paging
if(isset($_REQUEST['size'])) {
$size=$_REQUEST['size'];
} else {
$size=5;
}
if(isset($_REQUEST['page'])) {
$page=$_REQUEST['page'];
} else {
$page=0;
}
/////end paging
$VideoObj= new VideoLibrary();
$where = "where 1";
if (isset($_REQUEST['lang']) && $_REQUEST['lang'] != "") {
$where .= " AND `Language` = " . $_REQUEST['lang'];
$myLang = $_REQUEST['lang'];
}
if (isset($_REQUEST['cat']) && $_REQUEST['cat'] != "") {
$where .= " AND `Category` = " . $_REQUEST['cat'];
$myCat = $_REQUEST['cat'];
}
$cnt = count( $VideoObj->SelectAllVideoDetails(NULL,NULL,$where) );
//////for paging////
$page_rows=$cnt;
$totalpage=ceil($page_rows/$size);
////end paging/////
if($cnt==0) {
?>
<tr>
<td colspan="3"><div align="center" class="errorfont">There are no
matching videos - please expand your search criteria</div></td>
</tr>
<?
} else { // end cnt==0
$VideoRes = $VideoObj->SelectAllVideoDetails($page, $size, $where);
$sno=1;
foreach ($VideoRes as $key => $value) {
?>
<tr>
<td rowspan="2" width="162" valign="top">
<a href="showVideo.php?vid=<?=$value->Id;?>">
<IMG width=160 height=120 alt="" src="../<? if ($value->Video_Thumbnail=='') echo 'images/coming.jpg'; else echo $value->Video_Thumbnail; ?>" style="border: 1px solid #000000; padding: 0"></a><p align="center">
<a href="showVideo.php?vid=<?=$value->Id;?>"><b><font size="2">
WATCH THIS VIDEO</font></b></a>
<!-- comments commented
<br><a href="javascript:OpenWindow('showcomments.php?type=Video&itemid=<?=$value->Id?>',300,200)"><b><font size="2">Add/View Comments</font></b></a><br />
-->
</p>
<p>
<?
$CatObj= new CatDetails();
$CatObj->Id = $value->Category;
$CatRes = $CatObj->SelectCatDetails();
?>
<SPAN
class=bluebold>Category:</SPAN><SPAN
class=bodytext> <?=stripslashes($CatRes->CatName)?></SPAN><br>
<SPAN class=bluebold>Language: </SPAN>
<?
$LangObj= new LanguageDetails();
$LangObj->Id = $value->Language;
$LangRes = $LangObj->SelectLanguageDetails();
$LangObj1= new LanguageDetails();
$LangObj1->Id = $value->Subtitles_Language;
$LangRes1 = $LangObj1->SelectLanguageDetails();
?>
<SPAN
class=bodytext> <?=stripslashes($LangRes->Language)?></SPAN><span class="bluebold"><br>
Subtitles: </span>
<SPAN
class=bodytext><?=stripslashes($LangRes1->Language)?></SPAN></p>
</td>
<td valign="top"><SPAN class=newstitle>
<font size="4"><?=stripslashes($value->Title)?><br>
</font></SPAN>
<SPAN
class=bodytext><b><font size="2"><?=stripslashes($value->ShortDesc)?></font></b></SPAN></td>
</tr>
<tr>
<td height="118" valign="top">
<SPAN class=bodytext><?=stripslashes($value->LongDesc)?></SPAN>
<!--<br><a href="showVideo.php?vid=<?=$value->Id;?>">More...</a>-->
</td>
</tr>
<tr>
<td height="1" colspan="3" bgcolor="#CCCCCC"></td>
</tr>
<? } }?>
<tr>
<td colspan="2" class="text"> </td>
<td> </td>
</tr>
<tr>
<td colspan="2" class="text">
<p align="center"><? if($cnt>$size) {
if($page>=$size){ ?>
<a href="?page=<?=$page-1?>&size=<?=$size?>&act=all&lang=<?=$myLang?>&cat=<?=$myCat?>"><b>
Previous</b></a>
<? } else echo "Previous ";
// Build Previous Link
for($i = 1; $i <= $totalpage; $i++){
if(($page) == $i){
echo "$i";
} else {
echo ("<a href=http://www.watchmyvideos.com/video.php?cat=$cat&size=$size&page=$i> $i </a> ");
}
}
?> <? if($page_rows>($page+1)) { ?>
<a href="?page=<?=$page+1?>&size=<?=$size?>&act=all&lang=<?=$myLang?>&cat=<?=$myCat?>"><b>
Next</b></a>
<? } else echo "Next"; } ?></td>
</tr>
</table>
</td>
</tr>
</table>
<?
include_once("includes/footer.inc.php");
?>
califdon
Jack of Zircons
Posts: 4484 Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA
Post
by califdon » Tue Jun 05, 2012 7:46 pm
Let's try this: your problem is that you are not displaying the desired data when you request another page, right? So the problem must be in the part of your code that selects the data from the database. So we don't need any of the code that you have provided so far. We need to see the part of the code that queries your database.
BEACON
Forum Newbie
Posts: 5 Joined: Mon Jun 04, 2012 7:48 pm
Post
by BEACON » Wed Jun 06, 2012 2:30 pm
Thanks Califdon,
With all of your guy's kind help, I think I am slowly getting there.
this might be the code that queries the database
Code: Select all
<?
class Connection{
var $dbconn;
function Connection(){
$link = mysql_connect('localhost:/tmp/mysql5.sock', "dbuser", "password");
if($link){
$this->dbconn = $link;
mysql_select_db ("watchmyvideos",$link);
}else{
echo mysql_error();
$this->dbconn = false;
}
}
function insert($sql){
mysql_query($sql) or die(mysql_error());
}
function select($sql){
$result = mysql_query($sql) or die(mysql_error());
return $result;
}
function update($sql){
mysql_query($sql) or die(mysql_error());
}
function delete($sql){
mysql_query($sql) or die(mysql_error());
}
function close(){
mysql_close($this->dbconn);
}
function generateShortCode() {
for($i=0;$i<5;$i++)
{
$r = rand(48,90);
if($r > 57 && $r < 65)
$i--;
else
$p .= chr($r);
}
return $p;
}
}
?>
<?
$dbconn = new Connection();
$sql="select * from SiteSettings where id=1";
//echo $sql;
$res = $dbconn->select($sql);
$rw = mysql_fetch_object($res);
$site_title=$rw->sitetitle;
$admin_title=$rw->admintitle;
$site_url=$rw->url;
$webmaster=$rw->webmaster_email;
$support=$rw->support_email;
$copyright=$rw->copyright;
?>
califdon
Jack of Zircons
Posts: 4484 Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA
Post
by califdon » Wed Jun 06, 2012 3:43 pm
No, what we need to see is the code that uses that class. Have you any experience with PHP code at all?
Celauran
Moderator
Posts: 6427 Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada
Post
by Celauran » Wed Jun 06, 2012 4:46 pm
Code: Select all
function insert($sql){
mysql_query($sql) or die(mysql_error());
}
function select($sql){
$result = mysql_query($sql) or die(mysql_error());
return $result;
}
function update($sql){
mysql_query($sql) or die(mysql_error());
}
function delete($sql){
mysql_query($sql) or die(mysql_error());
}
Seriously?
BEACON
Forum Newbie
Posts: 5 Joined: Mon Jun 04, 2012 7:48 pm
Post
by BEACON » Thu Jun 07, 2012 1:04 pm
Califdon,
you are right my PHP knowledge is limited, I appreciate your kindness and patience.
I am looking through the code to find what else could be useful but don't see anything else that might query the database for my issue,
if you could kindly help me narrow it down I will search for it.
Thank you again
califdon
Jack of Zircons
Posts: 4484 Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA
Post
by califdon » Thu Jun 07, 2012 7:19 pm
Where did this code come from? Is it a commercial package, an open source package, or what?