Jump to content

Pagination While loop issue : getting 2 records for same set of files


inversesoft123

Recommended Posts

can anybody tell me what's wrong with my query ?

 

$filesa = "SELECT id, uid, size, filehash, filename, dwnloads, swidth, sheight, fores, flabel, vpre FROM pf_fmusic WHERE (aid='$albumid' AND vpre='complete') ORDER BY id DESC";

 

I am using this in while loop with ps_pagination class but getting 2 records for same set of files. in other words its running while loop 2 time complete code is here...

 

       $filesa = "SELECT id, uid, size, filehash, filename, dwnloads, swidth, sheight, fores, flabel FROM ibwf_fmusic WHERE (aid='$albumid' AND vpre='complete') ORDER BY id DESC";
$pager = new PS_Pagination($conn, $filesa, 9, 5, $albumid, $sortid, $sub, $selectalbum3[uid], $title, $collective);
$results = $pager->paginate();
  while($files=mysql_fetch_array($results))
  {
// Blah Blah
}

 

Output is something like this

 

1. song 1

2. song 2

3. song 3

4. song 4

1. song 1

2. song 2

3. song 3

4. song 4

 

Thanks is advance :)

Link to comment
Share on other sites

Okay here is complete code. Thanks for your reply :)

 

//Include the PS_Pagination class
include('../ps_pagination.php');

//Connect to mysql db
$conn = mysql_connect('localhost','-----------','--------------');
mysql_select_db('----------',$conn);
       $filesa = "SELECT id, uid, size, filehash, filename, dwnloads, swidth, sheight, fores, flabel, vpre FROM pf_fmusic WHERE (aid='$albumid' AND vpre='complete') ORDER BY id DESC";
///Create the PS_Pagination object
$pager = new PS_Pagination($conn, $filesa, 9, 5, $albumid, $sortid, $sub, $selectalbum3[uid], $title, $collective);
$results = $pager->paginate();
if(!$selectalbum3[artwork])
{
echo "<tr><td><img src=\"http://www.-----------.com/images/no_preview.jpg\" alt=\".\"/></td></tr>";
if(isset($_SESSION['user']))
{ 
echo "<tr><td><a class='link' href=\"http://www.-----------.com/updatepreview.php?type=$current_folder&fileid=$albumid\" width=\"200\" height=\"250\" alt=\".\"/>Update Preview</a></td></tr>";
}
} else {
echo "<tr><td><img src=\"http://www.-----------.comm/files/music/musicname/thumbs/$selectalbum3[uid]/$selectalbum3[artwork]\" width=\"200\" height=\"250\" alt=\".\"/></td></tr>";
}
echo "<tr><td><hr color=\"#660099\" size=3></td></tr>";
  while($files=mysql_fetch_array($results))
  {
$ext = end(explode('.', $files[3]));
$compactfilename = substr($files[4],0,"25");
echo "<table align=\"left%\" width=\"100%\" border=\"0\">";
echo "<tr>";
echo "<b>$files[4]</b><hr>";

///////////// Get Other versions of file ////////// Viz. Full, Compressed and AMR for mobiles... /////////////

$othrvs = mysql_query("SELECT id, uid, size, filehash, filename, dwnloads, swidth, sheight, fores, flabel, vpre FROM pf_fmusic WHERE filename='$files[4]' ORDER BY id DESC LIMIT 3");
echo "</tr><tr>";
  while($othrv=mysql_fetch_array($othrvs))
  {
if($othrv[10] =="complete")
{
$fitype = "FULL (128 Kbps)";
} else if($othrv[10] =="compressed") {
$fitype = "COMPRESSED (16 Kbps)";
} else {
$fitype = "MOBILE AMR";
}
$modurl= ereg_replace("[^A-Za-z0-9]", "-", $files[4]);
echo "<td><a class =\"link\" href =\"http://www.-----------.com/landing/$othrv[0]/$othrv[1]/$current_folder/$albumid/$sortid/$ref/$modurl.php\">$fitype</a><br/>Size :";
print ByteSize("$othrv[2]");
echo "<br/>Hits : $othrv[5]</td>";
}
echo "</tr>";
echo "</table>";
echo "<hr color=\"#660099\" size=3>";
$selectres = "SELECT * FROM pf_resolutions WHERE swidth='$files[6]' AND sheight='$files[7]'";
$selectres2=mysql_query($selectres);
$selectres3=mysql_fetch_array($selectres2);
$selecthandsets="SELECT * from pf_handsets where ID='$selectres3[iD]'";
$selecthandsets2=mysql_query($selecthandsets);
$selecthandsets3=mysql_fetch_array($selecthandsets2);
if(isset($_SESSION['user']))
{ 
$selectrescat = "SELECT * FROM pf_handsets WHERE hand_set='$selectuser3[hand_set]'";
$selectrescat2=mysql_query($selectrescat);
$selectrescat3=mysql_fetch_array($selectrescat2);
if($selectres3[iD] == $selectrescat3[iD])
{
echo "<br/><img src=\"http://www.-----------.com/chat/images/onebit_34.png\" alt=\"loc\"/></i>Works fine with your phone.</td></tr>\n";
}
else
{
echo "<br/><img src=\"http://www.-----------.com/chat/images/onebit_36.png\" alt=\"loc\"/></i>May not work with your phone.</td></tr>\n";
}
}
}
//Display the navigation
echo "    <tr><td><br/> \n";
echo"<div class=\"wp-pagenavi\">";
echo $pager->renderFullNav();
echo "   </div> </tr></td>\n"; 
echo "</table>";

Link to comment
Share on other sites

OK I have removed some unnecessary part from previous code. Tried to make it more consistent. :)

 

  $selectalbum="SELECT * from pf_amusic where id='$albumid'";
  $selectalbum2=mysql_query($selectalbum);
  $selectalbum3=mysql_fetch_array($selectalbum2);

//Include the PS_Pagination class
       include('../ps_pagination.php');
//Connect to mysql db
       $conn = mysql_connect('localhost','-----------','--------------');
       mysql_select_db('----------',$conn);

       $filesa = "SELECT id, uid, size, filehash, filename, dwnloads, swidth, sheight, fores, flabel, vpre FROM pf_fmusic WHERE (aid='$albumid' AND vpre='complete') ORDER BY id DESC";

//Create the PS_Pagination object some values are passed to ps_pagination class for next and previous links as I am using Apache mod rewrite.

$pager = new PS_Pagination($conn, $filesa, 9, 5, $albumid, $sortid, $sub, $selectalbum3[uid], $title, $collective);
$results = $pager->paginate();

/////////////// While loop for pagination begins //////////////////
       while($files=mysql_fetch_array($results))
      {
                 $ext = end(explode('.', $files[3]));
                 $compactfilename = substr($files[4],0,"25");
                 echo "<table align=\"left%\" width=\"100%\" border=\"0\">";
                 echo "<tr>";
                 echo "<b>$files[4]</b><hr>";

                 ///////////// Get Other versions of file ////////// Viz. Full, Compressed and AMR for mobiles... /////////////

                      $othrvs = mysql_query("SELECT id, uid, size, filehash, filename, dwnloads, swidth, sheight, fores, flabel, vpre FROM pf_fmusic WHERE filename='$files[4]' ORDER BY id DESC LIMIT 3");
                      echo "</tr><tr>";
                  //while loop for other versions
                         while($othrv=mysql_fetch_array($othrvs))
                            {
                               if($othrv[10] =="complete")
                                  {
                                   $fitype = "FULL (128 Kbps)";
                                   } else if($othrv[10] =="compressed") {
                                  $fitype = "COMPRESSED (16 Kbps)";
                                   } else {
                                  $fitype = "MOBILE AMR";
                             } 
                      //while loop for other versions ends

                    $modurl= ereg_replace("[^A-Za-z0-9]", "-", $files[4]); // For mod_rewrite urls
                   
echo "<td><a class =\"link\" href =\"http://www.-----------.com/landing/$othrv[0]/$othrv[1]/$current_folder/$albumid/$sortid/$ref/$modurl.php\">$fitype</a><br/>Size :";
                     print ByteSize("$othrv[2]");
                     echo "<br/>Hits : $othrv[5]</td>"; // Printing file size 
            }
                     echo "</tr>";
                     echo "</table>";
                     echo "<hr color=\"#660099\" size=3>";
}  
/////////////// While loop for pagination ends //////////////////
//Display the navigation
echo "    <tr><td><br/> \n";
echo"<div class=\"wp-pagenavi\">";
echo $pager->renderFullNav();
echo "   </div> </tr></td>\n"; 
echo "</table>";

Link to comment
Share on other sites

Could you also bother to provide some background information -

 

1) Has this code ever worked correctly?

2) What is the pagination class? Either provide a link to the author's web site so that someone could download it or post the source code for it. Also, have you modified the source code for it in any way?

3) Is the output (the <img> and <a href ...>) surrounding the double output correct (a single copy of it) or is doubled as well?

4) Have you checked directly in your database what your data is, so that you know that you don't have double data that would produce the double output?

5) Is this code being included into another file so that the possibility exists that it is being included twice or it is in some outer main loop and so produces the same output twice?

 

Frankly, you haven't provided much actual information to use to help you with your problem :psychic:

 

Link to comment
Share on other sites

A few tips..

 

You can use the * operator to pull all the fields from a table:

$filesa = "SELECT * FROM pf_fmusic WHERE aid='$albumid' AND vpre='complete' ORDER BY id DESC";

 

It may also help to clean up the code by using named indices for the returned data such as:

// replace 
$files[4]
// with 
$files['actual_data_name']

 

ALSO, Get those Database connection variables out of your script!! Store them in a connections.php file that is included in your script. The connections.php should be stored outside of the web root (below the httpdocs directory) OR in a folder that is blocked from web access VIA .htaccess

 

I know none of these solves your immediate problem, but they will help you to read and understand your code a LOT more, and also prevent some basic attacks against your DB

Link to comment
Share on other sites

Not being a nit-picker here but be aware that: ereg_replace is now a deprecated function (having error_reporting(E_ALL|E_DEPRECATED) would have flagged this up >php5.3.0) using preg_ would be a preferential choice, and it only means a slight tweek to the pattern as your using

 

And as the other chaps have suggested using * (everything) in the sql would save on RAM being used to store the requested info.

 

Again, just trying to be helpful ;p

 

Cheers,

Rw

Link to comment
Share on other sites

This code is working fine with older database entries.. problem is only with newly added files let me restore my database and update it again.. We have many albums near about 230 each album contains some ringtones. each ringtone is having 3 types of it full compressed and in amr format for mobile. Now this problem is with only newly added few albums (no duplicate entries in database) and contents of that album. Thank you very much for your help.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.