0

I'm trying to make a website with movies in it, everything is fine but i have just 1 little problem,when ever i make a website, i do all work in my local computer test it then I upload the web, the code below is for paging with query it works fine in WAMP (locally). But when I upload the paging code to my web server it says NOT EXIST. it shows the else part,whats the problem?

<?php

$per_page = 35; 
 $page = 1;
 if (isset($_GET['page'])) 
 {
  $page = intval($_GET['page']); 
  if($page < 1) $page = 1;
}

 $start_from = ($page - 1) * $per_page; 

$con= mysql_connect("localhost","sarya_asad","Thisisfor123");
 mysql_select_db('saryaal_com_movies',$con);

 $current_items = mysql_query( "SELECT * FROM `english` LIMIT $start_from, $per_page");
 if( mysql_num_rows($current_items) > 0)
 {
  while($item = mysql_fetch_assoc($current_items))
  {

  ?>
    <tr>
        <td> <strong><a href="english/english-preview.php?id=<?php echo$item['id']?>" ><?php echo $item['title'] ;?></a>    </strong></td>
        <td> <strong> <?php echo $item['year'] ;?>  </strong></td>
        <td> <strong> <?php echo $item['quality'] ;?>   </strong> </td>
    </tr>
    <tr><td>
    <?php
    }
 }
 else
 {
  echo 'this page does not exists'; 
 }

 $total_rows = mysql_query("SELECT COUNT(*) FROM `english`");
 $total_rows = mysql_fetch_row($total_rows);
 $total_rows = $total_rows[0];

 $total_pages = $total_rows / $per_page;
 $total_pages = ceil($total_pages); # 19/5 = 3.8 ~=~ 4

 for($i = 1; $i  <= $total_pages; ++$i)
 {
  echo "<a href='temp2.php?page=$i' class='pagNumActive'>$i</a> &nbsp;&nbsp;";
 }
 ?>
5
  • 1
    What does it say does "NOT EXIST?" You may have to change your database credentials to match that of your web server as you are no longer running on localhost. Commented Jan 16, 2013 at 21:46
  • 1
    Have your database connection details been updated since uploading your website to the web server? Commented Jan 16, 2013 at 21:46
  • 1
    Put error_reporting(E_ALL) at the top and see what errors it gives. My bet is failing to connect to MySQL Commented Jan 16, 2013 at 21:47
  • Make sure that your web host has the same db/tables/user/pass Commented Jan 16, 2013 at 22:09
  • my whole web is working and this code is also working until i change it to "...WHERE genre like '%$genre%' LIMIT $start_from, $per_page" Commented Jan 17, 2013 at 2:08

5 Answers 5

1
<?php if($Strkeyword=="" AND $StrLoc=="" AND $StrMinsal=="-1" AND $StrMaxsal=="-1" AND $StrMax_exp=="maximum" AND $Strcategory=="" AND $Strjobtype=="") {
 $sql=mysql_query("select * from job where AND status='Active'");
 } 
$per_page = 5;
 $page = 1; 
if (isset($_GET['page'])) { 
$page = intval($_GET['page']);
 if($page < 1) $page = 1; 
} 
$start_from = ($page - 1) * $per_page;
 if($Strkeyword=="" AND $StrLoc=="" AND $StrMinsal=="-1" AND $StrMaxsal=="-1" AND $StrMax_exp=="maximum" AND $Strcategory=="" AND $Strjobtype=="") 
{ 
$current_items=mysql_query("select * from job LIMIT $start_from, $per_page"); } $start_from, $per_page");
 if( mysql_num_rows($current_items)>0) { while($arr=mysql_fetch_array($current_items)) {
?> 

<?php include("include/result.php") ?>// result u want to display 
<?php 
} 
} else { 
echo 'Data does not exists'; } 
if($Strkeyword=="" AND $StrLoc=="" AND $StrMinsal=="-1" AND $StrMaxsal=="-1" AND $StrMax_exp=="maximum" AND $Strcategory=="" AND $Strjobtype=="") {
 $total_rows=mysql_query("select COUNT(*) from job where AND status='Active'");
 } 
$total_rows = mysql_query("SELECT COUNT(*) FROM job");
 $total_rows = mysql_fetch_row($total_rows); 
$total_rows = $total_rows[0]; 
$total_pages = $total_rows / $per_page;
 $total_pages = ceil($total_pages);
 # 19/5 = 3.8 ~=~ 4 
echo "<div style='margin-left:280px;'>";
 echo "Page : ";
 for($i = 1; $i <= $total_pages; $i++) {
 echo "[<a style='text-decoration:none' href='search_result.php?page=$i' class='pagNumActive'>$i</a>&nbsp;]"; 
} 
echo "</div>"; 
?> 
Sign up to request clarification or add additional context in comments.

Comments

0

This is your problem:

$con= mysql_connect("localhost","sarya_asad","Thisisfor123");
    mysql_select_db('saryaal_com_movies',$con);

You need to change the host details. localhost is the local server on your machine.

1 Comment

This might be the correct answer, but depending on the server it may allow localhost as the host.
0

change this

 $start_from = ($page - 1) * $per_page;

to

 $start_from = ($page) * $per_page;

4 Comments

for the first page you you'll get LIMIT 35,35 and not LIMIT 0,35
try without LIMIT $start_from, $per_page and see if it works
my query is working properly until i change my query SELECT id,title,year,quality,genre FROM english WHERE genre like '%$genre%' LIMIT $start_from, $per_page
your code looks good , try change to this your query SELECT * FROM english` LIMIT '$start_from', '$per_page'`
0

you might want to use something like:

$per_page = 35;
$start_from = $page * $per_page - $per_page;

Comments

0

Try this logic for pagination:

Your goal is to offset by the number of images you want to display on each page.

So let's say you want to display 6 movie thumbnails on a page... You'd have:

$videos_per_page = 6
$pageNumber = (isset($_GET['page']) ? ($_GET['page']) : 1);

And your offset would be:

$offset = $videos_per_page * $pageNumber 

(6 videos * page 0... so you're offsetting 0 videos. That's good because you want to display the first 6 videos in your data structure on page 0).


So now that you have your offset value... You need to set your array pointer to the correct spot... Loop through your database rows storing your movies and move your pointer by your offset value... Store that in $videos_to_offset...

while ($videos_per_page < $offset && ($row = $Query_Result->fetch_assoc())) {
    $videos_to_offset++;
}

Now you can loop through your database rows, outputting your videos from wherever your offset array pointer left off:

    $video_counter = 0;
    while ($video_counter < $videos_per_page && ($row = $Query_Result->fetch_assoc())) {

        echo   $row['videopath'];
        $video_counter++;
}

Something like that.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.