Jump to content

How To Display Specific Record


marukochan

Recommended Posts

Normally this would be done with MySQL.  Is that what you are using currently?

Can you post the code you have now (if any)?  Otherwise, can you tell us where you are at (eg, still desigining the script) so we can better help you?

Thanks!
Link to comment
Share on other sites

OK. Here is the code. Current code will only display the Company Name (at // Display Area). What I want to do is to have a view button at each record and when the user click that button, it will display full details of that particular record.

TQ

Code

<?php
$title = "Project Database Page";
include ("page_function.php");

header_start();
header_user();
echo ("<p><b>Company List List</b></p>");

connect_database();

// Set page to zero if no current page

if(!isset($_GET['page'])){
    $page = 1;
} else {
    $page = $_GET['page'];
}

// Set number of records per page
$max_results = 10;

// Limit for current page
$from = (($page * $max_results) - $max_results);

// Query on current page
$sql = mysql_query("SELECT * FROM company LIMIT $from, $max_results");

// Display Area
if(mysql_num_rows($sql) == 0){
        echo("Nothing to Display!");
    }

    $bgcolor = "#E0E0E0"; // light gray

    echo("<table>");
   
    while($row = mysql_fetch_array($sql)){
        if ($bgcolor == "#E0E0E0"){
            $bgcolor = "#FFFFFF";
        }else{
            $bgcolor = "#E0E0E0";
        }

    echo("<tr bgcolor=".$bgcolor."><td width=60%>");
    echo($row["company_name"]);
    echo("</td></tr>");
    }

    echo("</table>");
echo("</br>");

// End Display Area

// Find out total number of records
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM company"),0);

// Find out total number of pages
$total_pages = ceil($total_results / $max_results);

if ($page < 1)
{
$page = 1;
}
elseif ($page > $total_pages)
{
$pagenum = $total_pages;
}

//Set query range
$max = 'limit ' .($page - 1) * $max_results .',' .$max_results;

$data_p = mysql_query("SELECT * FROM company $max") or die(mysql_error());

while($info = mysql_fetch_array( $data_p ))
{
}

// Link for previous page
if($page > 1){
    $prev = ($page - 1);
    echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$prev\"><b>Previous  </b></a> ";
}

for($i = 1; $i <= $total_pages; $i++){
    if(($page) == $i){
        echo "$i ";
        } else {
            echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$i\">$i</a> ";
    }
}

// Link for next page
if($page < $total_pages){
    $next = ($page + 1);
    echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$next\"><b>  Next</b></a>";
}
echo "</center>";
footer();
?>
Link to comment
Share on other sites

Ok, to start with you need to make this parts here:

echo($row["company_name"]);

A link. If you have a unique ID, then pass that in the query string, if not, then use the company:

[code]
<?php
echo "<a href='viewcompany.php?id=".$row["id"]."'>".$row["company_name"]."</a>");
?>
[/code]

Then, on your new page, which ive called viewcompany.php:

[code]
<?php

$id = mysql_real_escape_string($_GET['id']);
$sql = "SELECT * FROM `company` WHERE `id`='$id'";
$result = mysql_query($sql) or die(mysql_error());
?>
[/code]

Ive not added anything about outputting the code because ive no idea how you were planning on layout it out or what information you have. But thats the gerneral idea. Also, if you do need to change it to using the company name rather than an ID, then you'll have to modify it accordingly.



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.