The display method of the product list is finished in the previous example. Next we will talk about how to display the details of a product, which is similar to the methods we commonly use to display posts in forums.
* ******* The file that displays detailed information ***********
Detail. php
<? Php
Include "config. inc. php ";
// Display product details
// Use global variables to obtain the values of multiple fields.
// There are IDs, names, prices, descriptions, current prices, units, images, and end times.
Function ReadDetail (){
Global $ WARE_TABLE;
Global $ id, $ name, $ price, $ description, $ cprice, $ unit, $ image, $ endtime;
$ SQL = "select id, name, description, price, unit, endtime, reply, curprice, photo from $ WARE_TABLE where id = '$ id '";
$ Result = mysql_query ($ SQL) or die (mysql_error ());
// You can also use list (...) but I am used to this separation, which seems troublesome, but it is clear that this is necessary, especially when there are fields to be processed.
$ Row = mysql_fetch_array ($ result );
$ Name = $ row [name];
$ Price = $ row [price];
$ Description = $ row [description];
$ Unit = $ row [unit];
$ Cprice = $ row [curprice];
$ Endtime = date ("Y-m-j", $ row [endtime]);
If ($ row [photo] = 1) $ image = $ row [id]. ". jpg ";
Else $ image = "";
}
// Read the latest 10 buyers
Function ReadBuyer (){
Global $ BID_TABLE;
Global $ id, $ buyer, $ buyprice, $ date, $ num;
$ SQL = "select id, buyer, email, price from $ BID_TABLE where parentid = '$ id' order by id desc ";
$ Result = mysql_query ($ SQL) or die (mysql_error ());
$ K = mysql_num_rows ($ result );
$ Num = ($ k> 10 )? 10: $ k; // check whether there are more than 10.
For ($ I = 0; $ I <$ num; $ I ++ ){
$ Row = mysql_fetch_array ($ result );
$ Buyer [] = $ row [buyer];
$ Buyprice [] = $ row [price];
$ Date [] = date ("Y-m-j H: I: s", $ row [id]);
}
}
// Display 10 buyers.
Function ShowBuyer (){
Global $ buyer, $ buyprice, $ date, $ num;
For ($ I = 0; $ I <$ num; $ I ++ ){
Echo "<tr> <td width = 25%>". $ date [$ I]. "</td> ";
Echo "<td width = 40%>". $ buyer [$ I]. "</td> ";
Echo "<td width = 35%>". $ buyprice [$ I]. "</td> </tr> ";
}
}
ReadDetail ();
ReadBuyer ();
?>
After the above processing is completed, you can use <? Echo $ name?> Or <? Echo $ price;?> I will not detail the information to be displayed.
This statement is used to display text or images based on whether there are images.
<? If ($ image = "") echo "no photo"; else echo "
When displaying product details, users should also be allowed to make bids. Therefore, I am relatively lazy to make a judgment on the new price of the user, deamweaver is used directly to verify the form, and only the English description is changed to Chinese. However, it is a bit special in judging the new bidding price, so we made some changes to the function generated by dw.
<Script language = "JavaScript">
<! --
Function MM_findObj (n, d) {// v3.0
Var p, I, x; if (! D) d = document; if (p = n. indexOf ("? ")> 0 & parent. frames. length ){
D=parent.frames[n.substring(p%1%].doc ument; n = n. substring (0, p );}
If (! (X = d [n]) & d. all) x = d. all [n]; for (I = 0 ;! X & I <d. forms. length; I ++) x = d. forms [I] [n];
For (I = 0 ;! X & d. layers & I <d. layers. length; I ++) xw.mm_findobj(n,d.layers+ I }.doc ument); return x;
}
Function MM_validateForm () {// v3.0
Var I, p, q, nm, test, num, min, max, errors = '', args = MM_validateForm.arguments;
For (I = 0; I <(args. length-2); I + = 3) {test = args [I + 2]; val = MM_findObj (args [I]);
If (val) {nm = val. name; if (val = val. value )! = ""){
If (test. indexOf ('ismail ')! =-1) {p = val. indexOf ('@');
If (p <1 | p = (val. length-1) errors + = '-' + nm + 'must be the correct email address. n ';
} Else if (test! = 'R') {num = parseFloat (val );
If (val! = ''+ Num) errors + = '-' + nm + 'must be a value. n ';
If (test. indexOf ('range ')! =-1) {p = test. indexOf (':');
Min = test. substring (8, p); max = test. substring (p + 1 );
*********
Var k = (num-min)/max;
// Determine whether the value is greater than the current price and an integer multiple of the current price + markup Unit
If (num <min | k! = Math. ceil (k) errors + = '-' + nm + 'must be an integer multiple of' + max + 'and greater than' + min +. n ';
}}} // ********* End change ********
Else if (test. charAt (0) = 'R') errors + = '-' + nm + 'Fill in complete. n ';}
} If (errors) alert ('found error: n' + errors );
Document. MM_returnValue = (errors = '');
}
// -->
</Script>
The following is simple. What else do you need? Show the items that have ended the bidding. The implementation of this function is the same as that of displaying unfinished products. The only difference is that the SetCondition () condition is different and there is no user bidding form when displaying the detail of the product that ends the bidding.
In addition, I will discuss how to add new products.
<? Php
Include "config. inc. php ";
Include "tview. class. php ";
Function AddRecord (){
Global $ view;
// The following variables are obtained from the form on the previous page.
Global $ name, $ price, $ unit, $ year, $ month, $ day, $ photofile, $ intro;
$ T = time ();
$ C = nl2br ($ intro );
$ Et = mktime (24, 0, 0, $ month, $ day, $ year );
// Determine whether a graph has been uploaded.
$ Ph = ($ photofile! = "None" and! Empty ($ photofile ))? '1': '0 ';
// Call the add () parameter of the member function, which is the string in the value () of the SQL statement.
$ View-> Add ("'$ t',' $ name', '$ C',' $ price', '$ unit', '$ et ', '0', '$ price',' $ ph '");
// Copy an image to a specified directory.
If ($ ph = '1 ')
Copy ($ photofile, "photo/$t.jpg ");
}
If ($ Submit ){
$ View = new TViewPage ($ WARE_TABLE, 20 );
AddRecord ();
Header ("Location: manager.htm ");
}
?>
Well, Luo luochao wrote two articles. I don't know if I can add a few more. :)
If you have any questions, please come up and discuss them. I just took out the program. If you see anything inappropriate, never be stingy. Please let me know.
My email: ycshowtop@21cn.com
In addition, if you want the complete code of this program, you can also send an email to me.