New users ask questions about how to display product names and corresponding images properly when calling images from databases on mysql + php pages.
1. index. php
... Omitted above
"Width =" 120 "height =" 135 "border =" 3 ">
Product Name:
<{$ Myrow [data]. tb_commodity_id}>
<{$ Myrow [data]. tb_commodity_name}>
2, head_picture.php
$ Query = "select * from tb_commodity where tb_commodity_id =". $ recid;
$ Result = mysql_query ($ query );
If (! $ Result) die ("error: mysql query ");
$ Num = mysql_num_rows ($ result );
If ($ num <1) die ("error: no this recorder ");
$ Data = mysql_result ($ result, 0, "tb_commodity_picture ");
Mysql_close ($ conn );
Echo $ data;
?>
3. the database table contains the tb_commodity_id, tb_commodity_name, and tb_commodity_picture fields.
On the index page, the product name can display 5 pieces of data in the database, including tb_commodity_id and tb_commodity_name. only images cannot be displayed normally, if you set $ query = "select * from tb_commodity where tb_commodity_id =" in head_picture.php ". $ recid; directly changed to: $ query = "select * from tb_commodity where tb_commodity_id = 1"; (or 2, 3, 4, 5, that is, the corresponding value of tb_commodity_id in the database) to display images normally, there are currently 5 data records in the database;
Change to: $ query = "select * from tb_commodity where tb_commodity_id =". $ myrow [data]. tb_commodity_id; display the tb_commodity_id = 5 image;
Click the image that cannot be displayed on the index page and open the image in the new tab. the URL in the address bar is: local name/head_picture.php? Recid = 5 (the corresponding recid is displayed in the image corresponding to the recid). the error: mysql query is displayed on the page.
Reply to discussion (solution)
Local name/head_picture.php? Recid = 5 (the corresponding recid is displayed in the image corresponding to the recid). the error: mysql query is displayed on the page.
The key point is to print the SQL statement display here.
Local name/head_picture.php? Recid = 5 (the corresponding recid is displayed in the image corresponding to the recid). the error: mysql query is displayed on the page.
The key point is to print the SQL statement display here.
The result is as follows: the. $ recid value is not taken to $ query = "select * from tb_commodity where tb_commodity_id =". $ recid.
Error: mysql query: select * from tb_commodity where tb_commodity_id =
$ Query = "select * from tb_commodity where tb_commodity_id =". $ _ GET ['recid'];
Find the crux of the problem.
$ Recid; change to $ _ GET ['recid'];
Or first extract ($ _ GET );
OK. Thank you @ xuzuning and @ anyilaoliu.