FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Strange Problem in PHP-MYSQL





bukaida
I have developed a bibliographic database.In the navigation it has a prev and next button.For some records even if the record is present, it is not showing when I click prev or next button.The problem can be viewed at http://www.pratik.frih.net/biblio/search_prev.php?id=4. But when the same id is input directly in the search by id field, the record is fetched without any problem.If the blank fields(author, title etc) are filled with something like Not Available, the record is displayed.What may be the problem? Below is the code for nevigation search (search_next.php)--
Code:

<? header("Content-Type: text/html; charset=UTF-8"); ?>
<?
include 'menu.php';
include 'connect.php';
  if(!empty($_GET['id'])){
    $book_id=$_GET['id'];
   
    $query2="SELECT *
    FROM bibdata;";
    $result2=mysql_query($query2)or die(mysql_error());
    $num=mysql_num_rows($result2);
    if($book_id >=$num){
    echo'<div align="center"><font color="red" size="+2">YOU HAVE REACHED AT THE END OF THE RECORD, MOVING  FURTHER IS NOT POSSIBLE.</font></div>';
    $book_id==$num;
    ?>
    <pre><a href="search_prev.php?id=<?echo $book_id?>"><img src="images/prev.JPG" alt="" width="90" height="34" border="0"></a></pre>
   <?php
   
exit(0);
                }?>
                 
 <?
   
   $book_id=$book_id+1;   
   
    $query="SELECT *
    FROM bibdata
    WHERE b_id='$book_id'";
    $result=mysql_query($query)or die(mysql_error());
    if($result){
      while($row=mysql_fetch_array($result)){
        extract($row);
       
      }
    }
   
   
   
if($b_id!=0 && $author!="" && $title!="" && $callnumb!="" && $verified!=""){

 echo'<div align="center"><p><span style="text-transform: uppercase;"><u><b><font face="Arial Black" size="+3" color="green">Book record</font></b></u></span></p></div>';
      echo'<table align="center">';
      echo'<p><tr><td><b><font face="Sylfaen" color="green">Book id:</font></b></td><td><span style="text-transform: capitalize;"><font size="+1" color="blue">';
      echo $b_id;
      echo'</font></span></td></tr>';
      echo'<p><tr><td><b><font face="Sylfaen" color="green">subject:</font></b></td><td><span style="text-transform: capitalize;"><font size="+1" color="blue">';
      echo $subject;
      echo'</font></span></td></tr>';
   
   
   echo'<p><tr><td><b><font face="Sylfaen" color="green">series:</font></b></td><td><span style="text-transform: capitalize;"><font size="+1" color="blue">';
      echo $series;
      echo'</font></span></td></tr>';
     
     echo'<p><tr><td><b><font face="Sylfaen" color="green">title:</font></b></td><td><span style="text-transform: capitalize;"><font size="+1" color="blue">';
      echo $title;
      echo'</font></span></td></tr>';
     
     echo'<p><tr><td><b><font face="Sylfaen" color="green">translated_title:</font></b></td><td><span style="text-transform: capitalize;"><font size="+1" color="blue">';
      echo $translated_title;
      echo'</font></span></td></tr>';
     
     echo'<p><tr><td><b><font face="Sylfaen" color="green">author:</font></b></td><td><span style="text-transform: capitalize;"><font size="+1" color="blue">';
      echo $author;
      echo'</font></span></td></tr>';
     
     echo'<p><tr><td><b><font face="Sylfaen" color="green">place_of_publication:</font></b></td><td><span style="text-transform: capitalize;"><font size="+1" color="blue">';
      echo $place_of_publication;
      echo'</font></span></td></tr>';
     
     echo'<p><tr><td><b><font face="Sylfaen" color="green">year_of_publication:</font></b></td><td><span style="text-transform: capitalize;"><font size="+1" color="blue">';
      echo $year_of_publication;
      echo'</font></span></td></tr>';
     
     echo'<p><tr><td><b><font face="Sylfaen" color="green">press:</font></b></td><td><span style="text-transform: capitalize;"><font size="+1" color="blue">';
      echo $press;
      echo'</font></span></td></tr>';
     
     echo'<p><tr><td><b><font face="Sylfaen" color="green">collation:</font></b></td><td><span style="text-transform: capitalize;"><font size="+1" color="blue">';
      echo $collation;
      echo'</font></span></td></tr>';
     
     echo'<p><tr><td><b><font face="Sylfaen" color="green">pagination:</font></b></td><td><span style="text-transform: capitalize;"><font size="+1" color="blue">';
      echo $pagination;
      echo'</font></span></td></tr>';
     
     echo'<p><tr><td><b><font face="Sylfaen" color="green">size:</font></b></td><td><span style="text-transform: capitalize;"><font size="+1" color="blue">';
      echo $size;
      echo'</font></span></td></tr>';
     
     echo'<p><tr><td><b><font face="Sylfaen" color="green">price:</font></b></td><td><span style="text-transform: capitalize;"><font size="+1" color="blue">';
      echo $price;
      echo'</font></span></td></tr>';
     
      echo'<p><tr><td><b><font face="Sylfaen" color="green">Title page:</font></b></td><td><span style="text-transform: capitalize;"><font face="arial" size="+2" color="blue">';
      echo $title_page;
      echo'</font></span></td></tr>';
     
     echo'<p><tr><td><b><font face="Sylfaen" color="green">Note:</font></b></td><td><span style="text-transform: capitalize;"><font size="+1" color="blue">';
      echo $note;
      echo'</font></span></td></tr>';
     
      echo'<p><tr><td><b><font face="Sylfaen" color="green">Library Name:</font></b></td><td><span style="text-transform: capitalize;"><font size="+1" color="blue">';
      echo $libname;
      echo'</font></span></td></tr>';
     
      echo'<p><tr><td><b><font face="Sylfaen" color="green">Call Number:</font></b></td><td><span style="text-transform: capitalize;"><font size="+1" color="blue">';
      echo $callnumb;
      echo'</font></span></td></tr>';
     
     echo'<p><tr><td><b><font face="Sylfaen" color="green">Status:</font></b></td><td><span style="text-transform: capitalize;"><font size="+1" color="blue">';
      echo $verified;
      echo'</font></span></td></tr>';
      echo'</table>'; 

    }else{
      echo'<div align="center"><font color="red" size="+2">No Book record exist for ID:</font><font color="yellow" size="+3">';echo $b_id ;
     echo'</font><br><br><font color="green" size="+1">Please press next button to try with next record</font></div>';
    }
   
  }else{
 echo'<div align="center"><font color="red" size="+1">Please enter a valid id<br><br>Click </<a href="search_by_id_form.php">here</a></font></div>';
    }
  echo'
</body>
</html>';
include 'navigation.php';
include 'footer.php';
 ?>


and the code for direct search(search_by_id.php)--
Code:


<? header("Content-Type: text/html; charset=UTF-8"); ?>
<?
include 'menu.php';
include 'connect.php';
  if(!empty($_POST['id'])){
    $book_id=$_POST['id'];
    $query="SELECT *
    FROM bibdata
    WHERE b_id='$book_id'";
    $result=mysql_query($query)or die(mysql_error());
    if($result){
      while($row=mysql_fetch_array($result)){
        extract($row);
      }
    }
if($b_id==$book_id){

 echo'<div align="center"><p><span style="text-transform: uppercase;"><u><b><font face="Arial Black" size="+3" color="green">Book record</font></b></u></span></p></div>';
      echo'<table align="center">';
      echo'<p><tr><td><b><font face="Sylfaen" color="green">Book id:</font></b></td><td><span style="text-transform: capitalize;"><font size="+1" color="blue">';
      echo $b_id;
      echo'</font></span></td></tr>';
      echo'<p><tr><td><b><font face="Sylfaen" color="green">subject:</font></b></td><td><span style="text-transform: capitalize;"><font size="+1" color="blue">';
      echo $subject;
      echo'</font></span></td></tr>';
   
   
   echo'<p><tr><td><b><font face="Sylfaen" color="green">series:</font></b></td><td><span style="text-transform: capitalize;"><font size="+1" color="blue">';
      echo $series;
      echo'</font></span></td></tr>';
     
     echo'<p><tr><td><b><font face="Sylfaen" color="green">title:</font></b></td><td><span style="text-transform: capitalize;"><font size="+1" color="blue">';
      echo $title;
      echo'</font></span></td></tr>';
     
     echo'<p><tr><td><b><font face="Sylfaen" color="green">translated_title:</font></b></td><td><span style="text-transform: capitalize;"><font size="+1" color="blue">';
      echo $translated_title;
      echo'</font></span></td></tr>';
     
     echo'<p><tr><td><b><font face="Sylfaen" color="green">author:</font></b></td><td><span style="text-transform: capitalize;"><font size="+1" color="blue">';
      echo $author;
      echo'</font></span></td></tr>';
     
     echo'<p><tr><td><b><font face="Sylfaen" color="green">place_of_publication:</font></b></td><td><span style="text-transform: capitalize;"><font size="+1" color="blue">';
      echo $place_of_publication;
      echo'</font></span></td></tr>';
     
     echo'<p><tr><td><b><font face="Sylfaen" color="green">year_of_publication:</font></b></td><td><span style="text-transform: capitalize;"><font size="+1" color="blue">';
      echo $year_of_publication;
      echo'</font></span></td></tr>';
     
     echo'<p><tr><td><b><font face="Sylfaen" color="green">press:</font></b></td><td><span style="text-transform: capitalize;"><font size="+1" color="blue">';
      echo $press;
      echo'</font></span></td></tr>';
     
     echo'<p><tr><td><b><font face="Sylfaen" color="green">collation:</font></b></td><td><span style="text-transform: capitalize;"><font size="+1" color="blue">';
      echo $collation;
      echo'</font></span></td></tr>';
     
     echo'<p><tr><td><b><font face="Sylfaen" color="green">pagination:</font></b></td><td><span style="text-transform: capitalize;"><font size="+1" color="blue">';
      echo $pagination;
      echo'</font></span></td></tr>';
     
     echo'<p><tr><td><b><font face="Sylfaen" color="green">size:</font></b></td><td><span style="text-transform: capitalize;"><font size="+1" color="blue">';
      echo $size;
      echo'</font></span></td></tr>';
     
     echo'<p><tr><td><b><font face="Sylfaen" color="green">price:</font></b></td><td><span style="text-transform: capitalize;"><font size="+1" color="blue">';
      echo $price;
      echo'</font></span></td></tr>';
     
      echo'<p><tr><td><b><font face="Sylfaen" color="green">Title page:</font></b></td><td><span style="text-transform: capitalize;"><font face="arial" size="+2" color="blue">';
      echo $title_page;
      echo'</font></span></td></tr>';
     
     echo'<p><tr><td><b><font face="Sylfaen" color="green">Note:</font></b></td><td><span style="text-transform: capitalize;"><font size="+1" color="blue">';
      echo $note;
      echo'</font></span></td></tr>';
     
      echo'<p><tr><td><b><font face="Sylfaen" color="green">Library Name:</font></b></td><td><span style="text-transform: capitalize;"><font size="+1" color="blue">';
      echo $libname;
      echo'</font></span></td></tr>';
     
      echo'<p><tr><td><b><font face="Sylfaen" color="green">Call Number:</font></b></td><td><span style="text-transform: capitalize;"><font size="+1" color="blue">';
      echo $callnumb;
      echo'</font></span></td></tr>';
     
     echo'<p><tr><td><b><font face="Sylfaen" color="green">Status:</font></b></td><td><span style="text-transform: capitalize;"><font size="+1" color="blue">';
      echo $verified;
      echo'</font></span></td></tr>';
      echo'</table>'; 

    }else{
      echo'<div align="center"><font color="red" size="+1">Book id does not match!<br><br>Please <a href="search_by_id_form.php">submit</a> a valid ID</font></div>';
    }
  }else{
 echo'<div align="center"><font color="red" size="+1">Please enter a valid id<br><br></<a href="search_by_id_form.php">Click here</a></font></div>';
    }
  echo'
</body>
</html>';
include 'navigation.php';
include 'footer.php';
 ?>



Please help.
Star Wars Fanatic
I'm afraid the record shows up fine for me... Maybe you can post some screenshots of the problem happening?
Fire Boar
Code:
  if(!empty($_GET['id'])){
    $book_id=$_GET['id'];
   
    $query2="SELECT *
    FROM bibdata;";
    $result2=mysql_query($query2)or die(mysql_error());
    $num=mysql_num_rows($result2);


No.

Code:
  if(!empty($_GET['id'])){
    $book_id=$_GET['id'];
   
    $query2="SELECT COUNT(1) FROM bibdata;";
    $result2=mysql_query($query2)or die(mysql_error());
    $row=mysql_fetch($result2);
    $num=$row[0];


Use that instead. It's far and away more efficient.
bukaida
Thanx guys, one more problem is happening, when I delete a record, say record number 8 from a record set of 10; I am decrementing all the records having id greater than the current record by one.So the records are maintaining the previous structure without any gap.In my example of 10 records after deleting record number 8, id of record 9 and 10 are decremented by 1 and total records now becomes 9 (1-9).Now when I am inserting a new record, the auto increment id field takes the value 11 instead of 10.How to rectify that? please help.

BTW-The previous problem is partialy solved by changing the if statement as only checking the id !=0.However more number of records has to be checked and I am implementing Fire Boar's code in sql query, it indeed places less overhead on the server specially if the number of records are large.Thanx.
Fire Boar
ALTER TABLE tablename AUTO_INCREMENT = number

That's the way to do it. You can also do this in phpMyAdmin if you have it.

Also, a little explanation for the simple tweak I suggested to speed up the SQL. Before, the query was selecting absolutely everything, no ifs, no buts, just for the purpose of checking the number of rows. Simply counting the number within MySQL is bound to be quicker. It's like the difference between counting the number of rows of a jigsaw puzzle against collecting up each piece, putting them into piles depending on which row they were in and counting the piles.
imagefree
well i havent read all of your code, but you can do the same thing lot more easily.

I have made an image gallery system. There i too used a Next Previous system.
What i am doing there is submitting info through GET/POST variable whatever the case may be and then process the info and see whether the user wants to go to next or previous. The next/previous entry is taken from database ( whether the next/previous id is in sequance with the current one or not) and then the info is used to make a URL, and finally i use the following piece of code to send user to next/previous page.



Code:
header("Location: {$destination_complete_url_with_http}");
die;


the user is automatically taken to the next/prev page.


The problem with your system is that you are using 2 different pages "search_prev.php" and "search_next.php" and navigation in existance of these two pages become very much confusing.


Apart from my suggestion above, you can do the same by keeping the URL unique. ie, when getting records from database for current $_GET['id'] variable, also get records for id+1 and id-1 or whatever the sequance you follow. Make the URLs of both the records too and place them in the NEXT and PREVIOUS buttons.

In this way you can use just one page to display 3 different pages 1-Current page, 2-Next, 3-Previous.


Need more suggestions? I can help you more. And i can show you my script too.
imagefree
continuing the 1st solution, here is the example code copied from my site:
Code:
if(isset($_POST['prev']))
{
   if(!isset($img_id_prev))
   {
      $slideshow_errors[]="These is no previous image in the slide.";//This is infact an imaginary case where this error occurs. The code automatically disables the previous button in case of 1st recode and the next button in case of the last recode. This error message is to prevent attacks.
   }
   else
   {
      header("Location: ".WEBSITE."slideshow.php?id=".$gallery_id.'&image='.$img_id_prev);
      die;
   }
}
if(isset($_POST['next']))
{
   if(!isset($img_id_next))
   {
      $slideshow_errors[]="These is the last image of the slideshow.";
   }
   else
   {
      header("Location: ".WEBSITE."slideshow.php?id=".$gallery_id.'&image='.$img_id_next);
      die;
   }   
}


Hope you get some Idea.
bukaida
Quote:
Need more suggestions? I can help you more. And i can show you my script too.

OFCOURSE-------
Nothing can be more joyful than that ! Actually I have just started php and not very familiar with the code optimization.So I will also bother you with lots of(silly) questions where ever I will be having doubt, because I will hardly get such opportunity again Very Happy .

Now seriously-- My page has a form (err textbox to be precise) with two images labelled as previous and next having hyperlink to the pages search_prev.php and search_next.php. I am only passing the current id to both the pages and one page is decrementing it by 1 and the other incrementing it by one and displaying the record.Basicaly 99.99% of the codes are same for these two pages. I thought of combining them into one but I donot have that much of control over PHP. The boundary checking is done by counting the number of records and using it as upper bound and when that one is reached only back button is available and one warning will show that this is the last record. You can view it in the url http://www.pratik.frih.net/biblio/search_by_id_form.php.Similarly id 0 for lower bound.
Now this is the scenario and lots of optimization is required. Waiting for your further suggestion.

Thanx a lot to both of you.
imagefree
bukaida wrote:
Quote:
Need more suggestions? I can help you more. And i can show you my script too.

OFCOURSE-------
Nothing can be more joyful than that ! Actually I have just started php and not very familiar with the code optimization.So I will also bother you with lots of(silly) questions where ever I will be having doubt, because I will hardly get such opportunity again Very Happy .

Now seriously-- My page has a form (err textbox to be precise) with two images labelled as previous and next having hyperlink to the pages search_prev.php and search_next.php. I am only passing the current id to both the pages and one page is decrementing it by 1 and the other incrementing it by one and displaying the record.Basicaly 99.99% of the codes are same for these two pages. I thought of combining them into one but I donot have that much of control over PHP. The boundary checking is done by counting the number of records and using it as upper bound and when that one is reached only back button is available and one warning will show that this is the last record. You can view it in the url http://www.pratik.frih.net/biblio/search_by_id_form.php.Similarly id 0 for lower bound.
Now this is the scenario and lots of optimization is required. Waiting for your further suggestion.

Thanx a lot to both of you.



You are decrementing the ID by 1 ( or incrementing by 1) what if the decremented or incremented record is already deleted? It should be coded to take the user to the next available record.


If you write the code of both of the pages, i can provide you the solution.
Also provide the heads of all of your fields in Table.
bukaida
When deleting I took care that all the records > current deleting id should be decrementing by one. i am giving the search_prev.php and search_next.php.Another problem in my code is that when it is reaching the last record and the user pressing prev , instead of the previous record it is fetching prev to prev(jumping one record).Can you please rectify it?

search_prev.php
Code:

<? header("Content-Type: text/html; charset=UTF-8"); ?>
<?
include 'menu.php';
include 'connect.php';
  if(!empty($_GET['id'])){
    $book_id=$_GET['id'];
    $book_id=$book_id-1;
    if($book_id<1){
    echo'<div align="center"><font color="red" size="+2">YOU HAVE REACHED AT THE BEGINING OF THE RECORD, GOING BACK FURTHER IS NOT POSSIBLE.</font></div>';
$book_id=$book_id+1;   ?>
    <pre>                                         <a href="search_next.php?id=<?echo $book_id?>"><img src="images/next.JPG" alt="" width="90" height="34" border="0"></a></pre>
   <?   exit(0);
                 }?>
   <?             
   
   
      
   
    $query="SELECT *
    FROM bibdata
    WHERE b_id='$book_id'";
    $result=mysql_query($query)or die(mysql_error());
    if($result){
      while($row=mysql_fetch_array($result)){
        extract($row);
      }
    }
if($b_id!=0){

 echo'<div align="center"><p><span style="text-transform: uppercase;"><u><b><font face="Arial Black" size="+3" color="green">Book record</font></b></u></span></p></div>';
      echo'<table align="center">';
      echo'<p><tr><td><b><font face="Sylfaen" color="green">Book id:</font></b></td><td><span style="text-transform: capitalize;"><font size="+1" color="blue">';
      echo $b_id;
      echo'</font></span></td></tr>';
      echo'<p><tr><td><b><font face="Sylfaen" color="green">subject:</font></b></td><td><span style="text-transform: capitalize;"><font size="+1" color="blue">';
      echo $subject;
      echo'</font></span></td></tr>';
   
   
   echo'<p><tr><td><b><font face="Sylfaen" color="green">series:</font></b></td><td><span style="text-transform: capitalize;"><font size="+1" color="blue">';
      echo $series;
      echo'</font></span></td></tr>';
     
     echo'<p><tr><td><b><font face="Sylfaen" color="green">title:</font></b></td><td><span style="text-transform: capitalize;"><font size="+1" color="blue">';
      echo $title;
      echo'</font></span></td></tr>';
     
     echo'<p><tr><td><b><font face="Sylfaen" color="green">translated_title:</font></b></td><td><span style="text-transform: capitalize;"><font size="+1" color="blue">';
      echo $translated_title;
      echo'</font></span></td></tr>';
     
     echo'<p><tr><td><b><font face="Sylfaen" color="green">author:</font></b></td><td><span style="text-transform: capitalize;"><font size="+1" color="blue">';
      echo $author;
      echo'</font></span></td></tr>';
     
     echo'<p><tr><td><b><font face="Sylfaen" color="green">place_of_publication:</font></b></td><td><span style="text-transform: capitalize;"><font size="+1" color="blue">';
      echo $place_of_publication;
      echo'</font></span></td></tr>';
     
     echo'<p><tr><td><b><font face="Sylfaen" color="green">year_of_publication:</font></b></td><td><span style="text-transform: capitalize;"><font size="+1" color="blue">';
      echo $year_of_publication;
      echo'</font></span></td></tr>';
     
     echo'<p><tr><td><b><font face="Sylfaen" color="green">press:</font></b></td><td><span style="text-transform: capitalize;"><font size="+1" color="blue">';
      echo $press;
      echo'</font></span></td></tr>';
     
     echo'<p><tr><td><b><font face="Sylfaen" color="green">collation:</font></b></td><td><span style="text-transform: capitalize;"><font size="+1" color="blue">';
      echo $collation;
      echo'</font></span></td></tr>';
     
     echo'<p><tr><td><b><font face="Sylfaen" color="green">pagination:</font></b></td><td><span style="text-transform: capitalize;"><font size="+1" color="blue">';
      echo $pagination;
      echo'</font></span></td></tr>';
     
     echo'<p><tr><td><b><font face="Sylfaen" color="green">size:</font></b></td><td><span style="text-transform: capitalize;"><font size="+1" color="blue">';
      echo $size;
      echo'</font></span></td></tr>';
     
     echo'<p><tr><td><b><font face="Sylfaen" color="green">price:</font></b></td><td><span style="text-transform: capitalize;"><font size="+1" color="blue">';
      echo $price;
      echo'</font></span></td></tr>';
     
      echo'<p><tr><td><b><font face="Sylfaen" color="green">Title page:</font></b></td><td><span style="text-transform: capitalize;"><font face="arial" size="+2" color="blue">';
      echo $title_page;
      echo'</font></span></td></tr>';
     
     echo'<p><tr><td><b><font face="Sylfaen" color="green">Note:</font></b></td><td><span style="text-transform: capitalize;"><font size="+1" color="blue">';
      echo $note;
      echo'</font></span></td></tr>';
     
      echo'<p><tr><td><b><font face="Sylfaen" color="green">Library Name:</font></b></td><td><span style="text-transform: capitalize;"><font size="+1" color="blue">';
      echo $libname;
      echo'</font></span></td></tr>';
     
      echo'<p><tr><td><b><font face="Sylfaen" color="green">Call Number:</font></b></td><td><span style="text-transform: capitalize;"><font size="+1" color="blue">';
      echo $callnumb;
      echo'</font></span></td></tr>';
     
     echo'<p><tr><td><b><font face="Sylfaen" color="green">Status:</font></b></td><td><span style="text-transform: capitalize;"><font size="+1" color="blue">';
      echo $verified;
      echo'</font></span></td></tr>';
      echo'</table>'; 

    }else{
      echo'<div align="center"><font color="red" size="+2">No Book record exist for ID:</font><font color="yellow" size="+3">';echo $b_id ;
     echo'</font><br><br><font color="green" size="+1">Please press prev button to try with previous record</font></div>';
    }
   
  }else{
 echo'<div align="center"><font color="red" size="+1">Please enter a valid id<br><br>Click </<a href="search_by_id_form.php">here</a></font></div>';
    }
   
  echo'
</body>
</html>';
include 'navigation.php';
include 'footer.php';
 ?>


search_next.php

Code:

<? header("Content-Type: text/html; charset=UTF-8"); ?>
<?
include 'menu.php';
include 'connect.php';
  if(!empty($_GET['id'])){
    $book_id=$_GET['id'];
   
    $query2="SELECT *
    FROM bibdata;";
    $result2=mysql_query($query2)or die(mysql_error());
    $num=mysql_num_rows($result2);
    if($book_id >=$num){
    echo'<div align="center"><font color="red" size="+2">YOU HAVE REACHED AT THE END OF THE RECORD, MOVING  FURTHER IS NOT POSSIBLE.</font></div>';
    $book_id==$num;
    ?>
    <pre>                                                    <a href="search_prev.php?id=<?echo $book_id?>"><img src="images/prev.JPG" alt="" width="90" height="34" border="0"></a></pre>
      <?php
   
exit(0);
                }?>
                 
 <?
   
   $book_id=$book_id+1;   
   
    $query="SELECT *
    FROM bibdata
    WHERE b_id='$book_id'";
    $result=mysql_query($query)or die(mysql_error());
    if($result){
      while($row=mysql_fetch_array($result)){
        extract($row);
       
      }
    }
   
   
   
if($b_id!=0){

 echo'<div align="center"><p><span style="text-transform: uppercase;"><u><b><font face="Arial Black" size="+3" color="green">Book record</font></b></u></span></p></div>';
      echo'<table align="center">';
      echo'<p><tr><td><b><font face="Sylfaen" color="green">Book id:</font></b></td><td><span style="text-transform: capitalize;"><font size="+1" color="blue">';
      echo $b_id;
      echo'</font></span></td></tr>';
      echo'<p><tr><td><b><font face="Sylfaen" color="green">subject:</font></b></td><td><span style="text-transform: capitalize;"><font size="+1" color="blue">';
      echo $subject;
      echo'</font></span></td></tr>';
   
   
   echo'<p><tr><td><b><font face="Sylfaen" color="green">series:</font></b></td><td><span style="text-transform: capitalize;"><font size="+1" color="blue">';
      echo $series;
      echo'</font></span></td></tr>';
     
     echo'<p><tr><td><b><font face="Sylfaen" color="green">title:</font></b></td><td><span style="text-transform: capitalize;"><font size="+1" color="blue">';
      echo $title;
      echo'</font></span></td></tr>';
     
     echo'<p><tr><td><b><font face="Sylfaen" color="green">translated_title:</font></b></td><td><span style="text-transform: capitalize;"><font size="+1" color="blue">';
      echo $translated_title;
      echo'</font></span></td></tr>';
     
     echo'<p><tr><td><b><font face="Sylfaen" color="green">author:</font></b></td><td><span style="text-transform: capitalize;"><font size="+1" color="blue">';
      echo $author;
      echo'</font></span></td></tr>';
     
     echo'<p><tr><td><b><font face="Sylfaen" color="green">place_of_publication:</font></b></td><td><span style="text-transform: capitalize;"><font size="+1" color="blue">';
      echo $place_of_publication;
      echo'</font></span></td></tr>';
     
     echo'<p><tr><td><b><font face="Sylfaen" color="green">year_of_publication:</font></b></td><td><span style="text-transform: capitalize;"><font size="+1" color="blue">';
      echo $year_of_publication;
      echo'</font></span></td></tr>';
     
     echo'<p><tr><td><b><font face="Sylfaen" color="green">press:</font></b></td><td><span style="text-transform: capitalize;"><font size="+1" color="blue">';
      echo $press;
      echo'</font></span></td></tr>';
     
     echo'<p><tr><td><b><font face="Sylfaen" color="green">collation:</font></b></td><td><span style="text-transform: capitalize;"><font size="+1" color="blue">';
      echo $collation;
      echo'</font></span></td></tr>';
     
     echo'<p><tr><td><b><font face="Sylfaen" color="green">pagination:</font></b></td><td><span style="text-transform: capitalize;"><font size="+1" color="blue">';
      echo $pagination;
      echo'</font></span></td></tr>';
     
     echo'<p><tr><td><b><font face="Sylfaen" color="green">size:</font></b></td><td><span style="text-transform: capitalize;"><font size="+1" color="blue">';
      echo $size;
      echo'</font></span></td></tr>';
     
     echo'<p><tr><td><b><font face="Sylfaen" color="green">price:</font></b></td><td><span style="text-transform: capitalize;"><font size="+1" color="blue">';
      echo $price;
      echo'</font></span></td></tr>';
     
      echo'<p><tr><td><b><font face="Sylfaen" color="green">Title page:</font></b></td><td><span style="text-transform: capitalize;"><font face="arial" size="+2" color="blue">';
      echo $title_page;
      echo'</font></span></td></tr>';
     
     echo'<p><tr><td><b><font face="Sylfaen" color="green">Note:</font></b></td><td><span style="text-transform: capitalize;"><font size="+1" color="blue">';
      echo $note;
      echo'</font></span></td></tr>';
     
      echo'<p><tr><td><b><font face="Sylfaen" color="green">Library Name:</font></b></td><td><span style="text-transform: capitalize;"><font size="+1" color="blue">';
      echo $libname;
      echo'</font></span></td></tr>';
     
      echo'<p><tr><td><b><font face="Sylfaen" color="green">Call Number:</font></b></td><td><span style="text-transform: capitalize;"><font size="+1" color="blue">';
      echo $callnumb;
      echo'</font></span></td></tr>';
     
     echo'<p><tr><td><b><font face="Sylfaen" color="green">Status:</font></b></td><td><span style="text-transform: capitalize;"><font size="+1" color="blue">';
      echo $verified;
      echo'</font></span></td></tr>';
      echo'</table>'; 

    }else{
      echo'<div align="center"><font color="red" size="+2">No Book record exist for ID:</font><font color="yellow" size="+3">';echo $b_id ;
     echo'</font><br><br><font color="green" size="+1">Please press next button to try with next record</font></div>';
    }
   
  }else{
 echo'<div align="center"><font color="red" size="+1">Please enter a valid id<br><br>Click </<a href="search_by_id_form.php">here</a></font></div>';
    }
  echo'
</body>
</html>';
include 'navigation.php';
include 'footer.php';
 ?>

Please help.
imagefree
everything seems to be fine ( having a birds eye view), i think the problem may be in navigation.php

One more thing, i think you have tried to delete some of the records from the database and now the deleted records are creating problem.

Can you copy the deleting code and navigation.php files!
bukaida
Here the deletion code and navigation.php.

navigation.php
Code:

<?php
echo'
<html>
<head><title></title>
</head>
<body>
<pre>';
 ?>
                                    <a href="search_prev.php?id=<?echo $b_id?>"><img src="images/prev.JPG" alt="" width="90" height="34" border="0"></a>                    <a href="search_next.php?id=<?echo $b_id?>"><img src="images/next.JPG" alt="" width="90" height="34" border="0"></a>
</pre>
</body>
</html>



delete_decision.php
Code:

<?php
include 'connect.php';
include 'menu.php';

if(isset($_POST['submit'])){

if(!empty($_POST['bid'])){
 
  $id=$_POST['bid'];
  $query1="SELECT *
    FROM bibdata
    WHERE b_id='$id'";
  $result1=mysql_query($query1)or die(mysql_error());
  $num1=mysql_num_rows($result1);
$row=mysql_fetch_array($result1);


if($num1>0)
{
$result2=NULL;
extract($row);
$query2="DELETE FROM `bibdata`
             where b_id='$id'";
$result2=mysql_query($query2);


/*Update the recordset */

$query3="UPDATE bibdata
        SET b_id=b_id-1
        WHERE b_id >'$id'";
   
$result3=mysql_query($query3) or die(mysql_error());

$query4="SELECT COUNT(1) FROM bibdata;";
    $result4=mysql_query($query4)or die(mysql_error());
    $row=mysql_fetch_array($result4);
    $num=$row[0];
//echo the maximum record number
   echo'<font color="red" size=+5>TOTAL RECORDS ARE:';echo"$num";echo'</font>';
$query5="ALTER TABLE bibdata AUTO_INCREMENT = $num";
$result5=mysql_query($query5)or die(mysql_error());

if($result2)
{
echo'<br><font color="green" size=+5>RECORD DELETED SUCCESSFULY.</font>';
}
else
{
echo'<font color="red" size=+3>ERROR IN DELETION.</font>';
}

}
else
{
echo'<font color="red" size=+5><b><pre>Warning!!The book id=';echo"$id";echo' does not exist.</pre></b></font>';
}
 
  }
else{

  $id=FALSE;
echo'<font color="red" size=+2>Please enter the Book id.</font>';
 
  }
}
include 'footer.php';
?>


And please suggest if it is possible to combine the search_prev.php and search_next.php into one.
Fire Boar
Aah, my eyes! I'm very sorry but that code is painful to look at. Can we please tackle the problem in a template-based fashion?

First things first: What do you actually need? You need to:
- Open a database.
- Grab a record by id.
- Extract all the variables.
- Figure out which item comes next, and which one comes previously.
- Output those variables onto a template.

Normally we need a few files.

- Database connection file.
- Template file.
- (Optional, but very handy) Template parsing class file.
- Selecting file

We already have the database connection file. Template parsing is a little more advanced, so we won't bother about that. Seperating the presentation from the content is pretty important, but we won't do so by making a new file, we'll have it all in one file.

So, you need 2 files for displaying the list. Let's look at the presentation first. It looks like this is actually what you want to do:

Code:
<div align="center">
  <p>
    <span style="text-transform: uppercase;"><u><b><font face="Arial Black" size="+3" color="green">Book record</font></b></u></span>
  </p>
</div>

<table align="center">
<?php
// Loop through each heading
for ($i = 0; $i < 18; $i++)
{
?>
  <tr>
    <td>
      <b><font face="Sylfaen" color="green"><?php echo $heading[$i]; ?></font></b>
    </td>
    <td>
      <span style="text-transform: capitalize;"><font size="+1" color="blue"><?php echo $row[$i]; ?></font></span>
    </td>
  </tr>
<?php
}
?>
</table>


$heading is an array (set of many variables in one) of headings, and $row is an array taken from the database of the data. Using this code we can loop through $heading and $row, from $heading[0] to $heading[17] and the same with $row. Let's work on the rest of the script now.

- We need to populate a static array of headings.
- We need to populate an array with a row from the database.
- There's a chance of hitting a non-existant entry with the next/previous buttons.
- There's a chance of hitting a non-existant entry with the search feature.

In the error cases, we simply include a different script and die() (same as exit(0)). Okay, let's populate the static array of headings.

Code:
<?php
$headings = array(
  'Book ID:',
  'Subject:',
  'Series:',
  'Title:',
  'Translated Title:',
  'Author:',
  'Place of Publication:',
  'Year of Publication:',
  'Press:',
  'Collation:',
  'Pagination:',
  'Size:',
  'Price:',
  'Title Page:',
  'Note:',
  'Library Name:',
  'Call Number:',
  'Status:'
);
?>


That gives us our headings. Run this and we'll get all the headings in a nice table... with no book. That won't do. Let's do the database bit now.

Code:
<?php
include('menu.php');
include('connect.php');

$headings = array(
  'Book ID:',
  'Subject:',
  'Series:',
  'Title:',
  'Translated Title:',
  'Author:',
  'Place of Publication:',
  'Year of Publication:',
  'Press:',
  'Collation:',
  'Pagination:',
  'Size:',
  'Price:',
  'Title Page:',
  'Note:',
  'Library Name:',
  'Call Number:',
  'Status:'
);

if (empty($_REQUEST['id']))
{
  include('errorpage.php');
  die();
}
$book_id = $_REQUEST['id'];
$query = "SELECT * FROM bibdata WHERE b_id = '$book_id'";
$result = mysql_query($query)or die(mysql_error());
if (mysql_num_rows($result) < 1)
{
  include('errorpage.php');
  die();
}
$row=mysql_fetch_row($result);
?>
<div align="center">
  <p>
    <span style="text-transform: uppercase;"><u><b><font face="Arial Black" size="+3" color="green">Book record</font></b></u></span>
  </p>
</div>

<table align="center">
<?php
// Loop through each heading
for ($i = 0; $i < 18; $i++)
{
?>
  <tr>
    <td>
      <b><font face="Sylfaen" color="green"><?php echo $heading[$i]; ?></font></b>
    </td>
    <td>
      <span style="text-transform: capitalize;"><font size="+1" color="blue"><?php echo $row[$i]; ?></font></span>
    </td>
  </tr>
<?php
}
?>
</table>
<?php
include('navigation.php');
include('footer.php');
?>


That's all! You can expend the bit of code where we do the database stuff to take another request variable, called "action", which decides through a series of if statements what should be done. This approach cuts down on having to write reams and reams of code for a simple or simple-ish task.
bukaida
oops, So many new concepts to learn. Thats look so tidy.I am going slowly through your tutorial(A very nicely written one).Yeah my code is realy painful because the primary intension was to run it.Now it is the time to learn better programming.
One more question-Should the business logic and presentation logic reside in same file? If not, how to link them?
Related topics
PHP, MySQL...
ASP +PHP+MySQL Tutorials
what is your php mysql apache installer package
Need some php/mysql dlls
The Basics (php, mysql etc)
What is useful way in this php+mysql problem?
PHP/Mysql - beginner!
A very good PHP MySQL Tutorial
Setup php,mysql and others...
php, mysql and iis5
 EASY 40 frih$ IF YOU KNOW PHP+MySQL 
Php Mysql security testing
Project to join - php,mysql??
Link PHP/Mysql with Outlook Express
Free PHP/MySQL login script
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.