Results 1 to 6 of 6

Thread: Link on each record

  1. #1

    Thread Starter
    Addicted Member nyah_RMC's Avatar
    Join Date
    Jan 2002
    Location
    citadel
    Posts
    160

    Link on each record

    nyone can tell me how can i put a link on my AuthorName results so when i try to click it and call another .php file it will display the whole contents of that particular record?

    PHP Code:
    $result mysql_query ("SELECT * FROM tblAuthor WHERE AuthorName LIKE '%$bsearch%'"); 
      
    $total_records mysql_num_rows($result);
      echo 
    "<table>";
      echo 
    "<tr><td><B>Author Name</B><td><B>Author ID</B></tr>";
      while (
    $row mysql_fetch_array($result))
      {
      echo 
    "<tr><td>";
      echo 
    $row["AuthorName"];
      echo 
    "<td>";
      echo 
    $row["AuthorID"];
         }
      echo 
    "</table>";
      }
      echo 
    "<p>";
      echo 
    "Total records found!:  ".$total_records."</p>"
    robee

    There's nothing wrong in asking, it proves only one thing. That you are Ignorant! but willing to dig on facts!

  2. #2
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Code:
      $result = mysql_query ("SELECT * FROM tblAuthor WHERE AuthorName LIKE '%$bsearch%'"); 
    
      $total_records = mysql_num_rows($result);
    
      echo "<table>";
      echo '<tr>
          <td>
              <B>Author Name</B>
          </td>
          <td>
              <B>Author ID</B></td>
      </tr>';
    
      while ($row = mysql_fetch_array($result))  {
          echo '<tr>
              <td><a href="page.php?id=' . $row["authorID"] . '">' . $row["AuthorName"] . '</a></td>';
          echo '<td>' . $row["AuthorID"]. '</td>';
      }
      echo "</table>";
      }//Where does this come from?
    
      echo "<p>";
      echo "Total records found!:  ".$total_records."</p>";
    Then in your page.php, have it run a sql query like this:

    Code:
    $result = mysql_query ("SELECT * FROM tblAuthor WHERE AuthorID='$id'");
    And run through the info like you are above.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  3. #3

    Thread Starter
    Addicted Member nyah_RMC's Avatar
    Join Date
    Jan 2002
    Location
    citadel
    Posts
    160
    hey thanks hobo it works!...but ive come to change the whole code...i just download this code...i hope you can help me out too..

    {who ever owns the code please inform me so I can give u the credit you deserve}

    PHP Code:
    <?php
    /// connect to database
        
    $global_db mysql_connect('localhost''scidev''scidev');
        
    mysql_select_db('scidev'$global_db);
        
    // query to get the number of records
        
    if ($select == "Author") {
        
    $query "SELECT AuthorName FROM tblAuthor WHERE AuthorName LIKE '%$bsearch%'";
        
    $result mysql_query($query) or die("MYSQL Connection Failed!");
        
    $num_record mysql_num_rows($result);
        if(
    $num_record $display) { // Only show 1,2,3,etc. when there are more records found that fit on 1 page
        // when the page is loaded first...
        
    if(empty($page)) { 
        
    $page 1;
        }
        
    // some variables
        
    $display 10// number of records to display per page
        
    $max_pages_to_print 7// number of pages to show, if you change this you also have to change the variable 'middlenumber', for example:increase this one with two, increase middlenumber with one
        
    $startrecord $page $display// first record to show from the queryresult
        
    $num_pages intval($num_record $display) + 1// total number of pages
        
    $loopcounter 0// counter for whileloop
        
    $currentpage $page// Page where we are at the moment
        
    $middlenumber 3// Number will be decreased from variable currentpage in order to get the currentpage always in the middle
        
    $colourcounter 0// Variable to change the background-color of the <td>
        
    $i 1// variable that will print 1,2,3,etc..
        
    $x 0// variable i use to put always the current, marked page in the middle
        // actual stuff starts here
        
    print("<table border=0 align=center><tr>");
        if(
    $currentpage >= $max_pages_to_print) {
        print(
    "<td><a href=\"$PHP_SELF?page=1\">First</a>...</td>");
        }
        
    //BEGIN LOOP
        
    while($loopcounter $max_pages_to_print) { 
        if(
    $currentpage >= $max_pages_to_print) { // If user clicks om page higher than $max_pages_to_print
        // Mark current page
        
    if($currentpage == $i) {
        print(
    "<td>$i  </td>"); // print pagenumbers
        
    $i += 1//increase pagenr
        
    $loopcounter += 1// increase loopcounter
        
    }
        
    // End marking
        
    if($i $num_pages) { // if last page has been printed, exit loop
        
    break;
        }
        if(
    $x == 0) {
        
    $i $currentpage $middlenumber// current page will always be printed in the middle
        
    }
        print(
    "<td><a href=\"$PHP_SELF?page=$i\">$i</a>  </td>"); // print pagenumbers
        
    $x $x 1;
        
    $i += 1//increase pagenr
        
    $loopcounter += 1// increase loopcounter
        
    }
        else { 
    // Else user clicks on a pagenumber lower $max_pages_to_print
        // Mark current page
        
    if($currentpage == $i) {
        print(
    "<td>$i  </td>"); // print pagenumbers
        
    $i += 1//increase pagenr
        
    $loopcounter += 1// increase loopcounter
        
    }
        
    // End marking
        
    if($i $num_pages) { // if less than $max_mages_to_print, exit loop
        
    break;
        }
        print(
    "<td><a href=\"$PHP_SELF?page=$i\">$i</a></td>"); // print pagenumbers
        
    $i += 1//increase pagenr
        
    $loopcounter += 1// increase loopcounter
        
    // End if
        

        
    // END LOOP
        
    if(($num_pages $max_pages_to_print AND // notice the user that there are more pages
            
    $i <= $num_pages)) {
        print(
    "<td>...<a href=\"$PHP_SELF?page=$num_pages\">Last</a></td>");
        }
        print(
    "</tr></table>");
        
    $startrecord $startrecord $display// Set startrecord to the right position
        // Some calculation for the lastrecord
        
    if($currentpage == $num_pages) { // Last page...
        
    $lastrecord $num_record// so $lastrecord = $num_record
        
    }
        else {
        
    $lastrecord = ($currentpage $display);
        }
        } 
    // End of the first if-statement
        // Some info
        
    print("<table align=center>
        <tr><td>You are now on page 
    $currentpage</td></tr>
        <tr><td>There are 
    $num_pages pages in total</td></tr>
        <tr><td>
    $num_record records are spread over $num_pages pages</td></tr>
        <tr><td>Current display : 
    $startrecord - $lastrecord</td></tr>
        </table>"
    );
        
    // End info
        // actual query, watch the end($startrec
        //     ord, $display)
        
    $query2 "SELECT AuthorName FROM tblAuthor WHERE AuthorName LIKE '%$bsearch%' LIMIT $startrecord$display";
        
    $result2 mysql_query($query2) or die("ERROR");
        
    // print results on screen
        
    print("<table border=0 align=center width=300 bgcolor=#0E711D cellpadding=\"2\" cellspacing=\"1\"><tr><td><font color=#FFFFFF><b>Author Name</b></font></td></tr>

        while(list(
    $AuthorName) = mysql_fetch_row($result2)) {
        if (
    $colorcounter == 0) {
        
    $colorbg = "#ECE28B";
        
    }
        else {
        
    $colorbg "#F4EFC1";
        
    $colorcounter $colorcounter 2;
        }
        print(
    "<tr><td bgcolor=$colorbg>$AuthorName</td></tr>           $colorcounter = $colorcounter + 1;
        }
        print("
    </table>");
     }
        ?>
    could you help me how can I put links on the AuthorName query results? i tried ur code here too, but i really dont know how to revised it..im just new to php...hope u can help me out
    robee

    There's nothing wrong in asking, it proves only one thing. That you are Ignorant! but willing to dig on facts!

  4. #4
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Just to let you know, code is A LOT easier to read when it's properly spaced out. And it would make me more anxious to help...but since I'm a nice guy, I'll give it a try anyways:

    Code:
    while(list($AuthorName) = mysql_fetch_row($result2)) {
        if ($colorcounter == 0) {
            $colorbg = "#ECE28B";
        } else {
            $colorbg = "#F4EFC1";
            $colorcounter = $colorcounter - 2;
        }
        print('<tr><td bgcolor=$colorbg><a href="YOUR_PAGE.PHP?id=' . $AuthorID . '>' . $AuthorName . '</a></td></tr>');
        $colorcounter = $colorcounter + 1;
    }
    My evil laugh has a squeak in it.

    kristopherwilson.com

  5. #5

    Thread Starter
    Addicted Member nyah_RMC's Avatar
    Join Date
    Jan 2002
    Location
    citadel
    Posts
    160
    oopppss..sorry about that! hey it works, but i got some problem...the row colors turned to blue! and as i query the 4th record shows this:

    <a href="basic_view.php?Authorid=>wilkins
    and also it didnt return the correct record searched!

    let me show it:

    this is my previous code. this is wat it shows after i execute my query (without the links)..
    1
    You are now on page 1
    There are 1 pages in total
    7 records are spread over 1 pages
    Current display : 0 - 7
    Author Name
    jollibee
    Koala
    Leah
    Leny
    Leon
    lola
    wilkins
    and this is wat it returned after i adopted ur print code:
    1
    You are now on page 1
    There are 1 pages in total
    7 records are spread over 1 pages
    Current display : 0 - 7
    Author Name
    Koala
    Leny
    lola
    <a href="basic_view.php?id=>wilkins
    wats wrong with this?
    Last edited by nyah_RMC; Nov 22nd, 2002 at 12:46 AM.
    robee

    There's nothing wrong in asking, it proves only one thing. That you are Ignorant! but willing to dig on facts!

  6. #6

    Thread Starter
    Addicted Member nyah_RMC's Avatar
    Join Date
    Jan 2002
    Location
    citadel
    Posts
    160
    mmmm...nobody seems to know what's wrong!
    robee

    There's nothing wrong in asking, it proves only one thing. That you are Ignorant! but willing to dig on facts!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width