Jump to content

Reading an ID onto another page


JayLewis

Recommended Posts

I want to set up a profile for each ID..

 

So there is a list of sold items on a webpage with a "Reciept" link.

 

I want to click that and it will take me to the reciept of the ID i click.

 

So i click "Nokia 3310" and on the new page it give me all the details on another page from everything in the nokia 3310 row in the database.

 

Thanks,

 

Jay

 

heres my code:

<html>

<head>
<meta http-equiv="Content-Language" content="en-gb">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>New Page 1</title>
</head>

<body bgcolor="#D0E0F0">
<font face="Arial" size="2">

<table width="100%" border="1" cellspacing="0" cellpadding="3" bordercolor="#000000" height="52">
<tr>
<td width="100%" bordercolorlight="#000000" bordercolordark="#000000" bgcolor="#8DA3BA" align="center">
<p align="center">
<font face="Arial" size="2">
<b>Control Panel<br>
You are currently on page: "View Client List"<br>
<br>
Move to Pages:<br>
<a href="insert.php" style="text-decoration: none"><font color="#000000">Add A 
Client</font></a> -</b> View Client List</font></td>

</tr>

<table width="100%" border="1" cellspacing="0" cellpadding="3" bordercolor="#3C79BD">
<tr>
<td width="16" bordercolorlight="#000000" bordercolordark="#000000" bgcolor="#8DA3BA">
<p align="center"><font face="Arial" size="2">ID</font></td>
<td width="76" bordercolorlight="#000000" bordercolordark="#000000" bgcolor="#8DA3BA">
<p align="center"><font size="2">Client Name</font></td>
<td width="186" bordercolorlight="#000000" bordercolordark="#000000" bgcolor="#8DA3BA">
<p align="center"><font face="Arial" size="2">Address</font></td>
<td width="114" bordercolorlight="#000000" bordercolordark="#000000" bgcolor="#8DA3BA">
<p align="center"><font face="Arial" size="2">Telephone Number</font></td>
<td width="93" bordercolorlight="#000000" bordercolordark="#000000" bgcolor="#8DA3BA">
<p align="center"><font face="Arial" size="2">Phone/Model</font></td>
<td width="171" bordercolorlight="#000000" bordercolordark="#000000" bgcolor="#8DA3BA">
<p align="center"><font face="Arial" size="2">Repair Comments</font></td>
<td width="86" bordercolorlight="#000000" bordercolordark="#000000" bgcolor="#8DA3BA">
<p align="center"><font face="Arial" size="2">Start Date</font></td>
<td width="33" bordercolorlight="#000000" bordercolordark="#000000" bgcolor="#8DA3BA">
<p align="center"><font size="2">Cost</font></td>
<td width="58" bordercolorlight="#000000" bordercolordark="#000000" bgcolor="#8DA3BA" align="center">
<font size="2">Receipt </font></td>
<td width="76" bordercolorlight="#000000" bordercolordark="#000000" bgcolor="#8DA3BA" align="center" valign="middle">
<font size="2">Fixed?</font></td>
</tr>
<?php

$host="localhost"; // Host name 
$username="customcl_jay"; // Mysql username 
$password="123456"; // Mysql password 
$db_name="customcl_elitephones"; // Database name 
$tbl_name="test_mysql"; // Table name 

// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

// Retrieve data from database 
$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);

// Start looping rows in mysql database.
while($rows=mysql_fetch_array($result)){
?>
</font>

<tr>
<td width="16" bordercolorlight="#000000" bordercolordark="#000000" bgcolor="#B6CCE4" align="center"><font face="Arial" size="2"><? echo $rows['id']; ?></font></td>
<td width="76" bordercolorlight="#000000" bordercolordark="#000000" bgcolor="#B6CCE4" align="center"><font face="Arial" size="2"><? echo $rows['name']; ?> <? echo $rows['lastname']; ?></font></td>
<td width="186" bordercolorlight="#000000" bordercolordark="#000000" bgcolor="#B6CCE4" align="center"><font face="Arial" size="2"><? echo $rows['email']; ?></font></td>
<td width="114" bordercolorlight="#000000" bordercolordark="#000000" bgcolor="#B6CCE4" align="center"><font face="Arial" size="2"><? echo $rows['tel']; ?></td>
<td width="93" bordercolorlight="#000000" bordercolordark="#000000" bgcolor="#B6CCE4" align="center"><font face="Arial" size="2"><? echo $rows['model']; ?></td>
<td width="171" bordercolorlight="#000000" bordercolordark="#000000" bgcolor="#B6CCE4" align="center"><font face="Arial" size="2"><? echo $rows['repair']; ?></td>
<td width="86" bordercolorlight="#000000" bordercolordark="#000000" bgcolor="#B6CCE4" align="center"><font face="Arial" size="2"><? echo $rows['dropoff']; ?></td>
<td width="33" bordercolorlight="#000000" bordercolordark="#000000" bgcolor="#B6CCE4" align="center">
<p align="center"><font face="Arial" size="2"><? echo $rows['price']; ?></font></td>
<td width="58" bordercolorlight="#000000" bordercolordark="#000000" bgcolor="#B6CCE4" align="center">
<font face="Arial" size="2">Receipt</font></td>
<td width="76" bordercolorlight="#000000" bordercolordark="#000000" bgcolor="#B6CCE4" align="center" valign="middle">
<form method="POST" action="--WEBBOT-SELF--">
<!--webbot bot="SaveResults" U-File="fpweb:///_private/form_results.csv" S-Format="TEXT/CSV" S-Label-Fields="TRUE" -->
<p><font face="Arial">
<select size="1" name="D1" style="border: 1px solid #000000; padding-left: 4px; padding-right: 4px; padding-top: 1px; padding-bottom: 1px; background-color: #8DA3BA">
<option>Yes</option>
<option>BER</option>
<option selected>Pending</option>
</select></font></p>
</form>
</td>
</tr>


<font face="Arial" size="2">

<?
// close while loop 
}

// close connection 
mysql_close();
?>

</font>

</body>

</html>

Link to comment
Share on other sites

Here is a quick run down on what you need to do:

 

1. Create a page that queries and lists all the sold items (example: sold_items.php)

 

2. The receipt link that is clicked on, use a variation of the following:

 

receipt.php?id=<?php echo $row_items['item_id']; ?>

 

3. Create a page that queries the database and selects the info that matches the item_id in the above link (receipt.php)

 

It really is one of the more basic aspects of PHP and you can probably find dozens of tutorials to grab the code from.

Link to comment
Share on other sites

I'm going to assume the following DB schema:

table name 'orders',

id int auto-increment,

item_id int,

quantity int,

order_time int

 

Then you could do something like

 

//pretend you have a sql conn open
$q = mysql_query("SELECT * FROM 'orders' ORDER BY id DESC"); //this would select all the rows from the orders table.... the newest ones first ;p

while($r = mysql_fetch_assoc($q)) { \\while there are results
echo '<a href="detail.php?id='.$r['id'].'">Order Number '.$r['id'].'</a><br />\r\n'; \\echo the link
}

 

That script would simply have a page with a link for each order saying "Order Number X" which would take you to a details page:

 

//one again pretend you have a mysql conn open 

if(is_numeric($_GET['id'])) { //if GET['id'] is numeric
$id = (int) $_GET['id']; //set $_GET['id'] to $id.... the type casting is mainly because I'm OCD
$q = mysql_query("SELECT * FROM orders WHERE id = '{$id}'");
if($q) { //i usually do this to avoid weird errors with num_rows, but it's not necessary really.
if(mysql_num_rows($q) > 0) { //if theres more than 0 rows
$r = mysql_fetch_assoc($q);
echo "Order ID: {$id}<br />\r\n"; //echo out some info... this is all unstyled and very basic, but I'm just trying to communicate the idea ;p
echo "Item ID: {$r['item_id']}<br />\r\n";
echo "Quantity: {$r['quantity']}<br />\r\n";
echo "Time Ordered: ".date("F j, Y, g:i a", $r['order_time']); //take from php.net/date ... it would look something like "March 10, 2001, 5:16 pm"
}
else {
echo "incorrect order id"; //no record existed for it
}
}
else {
echo "Incorrect order id";
}
}
else {
echo "Incorrect order id"; //if it's not numeric, you know it cannot be correct ;p
}

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.