开发者

Losing speech marks on page refresh

I have built a category navigation system using php and mysql.

$query = "SELECT category_name, category_desc FROM categories";
$result = mysql_query($query, $dbc)
or die (mysql_error($dbc));

while($row = mysql_fetch_array($result)) {

$catname = $row["category_name"];
$catdesc = $row["category_desc"];

echo "<li><a href='getsubs.php?category=$catname'>$catname<br /><span>$catdesc</span></a></li>";

This code provides me with a list of categories from my database.

When these categories are clicked and the getsubs.php file is requested:

$category= $_GET['category'];

$query = "SELECT subcategory_name FROM subcategories WHERE subcategory_parent = '$category'";
$result = mysql_query($query, $dbc)
or die (mysql_error($dbc));

while($row = mysql_fetch_array($resu开发者_JAVA技巧lt)) {

$subcatname = $row["subcategory_name"];

echo "<li><a href='getsubsubs.php?category=$subcatname'>$subcatname</a></li>";

$category = mysql_real_escape_string($_GET['category']);

}

the text on the rest of the page (which is not database driven) loses any speech marks/quotation marks (") which were present at the base level. Does any one have any idea why this might be?

Many thanks in advance.

EDIT: Before and after:

Losing speech marks on page refresh

Losing speech marks on page refresh


Those ? often show up because of unicode encoding issues. Your tables subcategories and categories probably have different collations. One is probably one of the unicode varieties and the other has fewer options. Try this for a quick fix:

-- in the top query:
SELECT 
    category_name COLLATE latin1_swedish_ci, 
    category_desc COLLATE latin1_swedish_ci
FROM categories

-- in the bottom query
SELECT subcategory_name COLLATE latin1_swedish_ci 
   FROM subcategories WHERE subcategory_parent = '$category'"

A more correct approach would be to change both tables to use the same collation and/or adjust the encoding output with a <meta> tag. (something like <meta http-equiv="content-type" content="application/xhtml+xml; charset=UTF-8" /> would probably do it)

(As an aside, I more or less have to remark that you should be using mysql_real_escape_string around your DB inputs)


The problem was nothing to do with my character encoding which upon checking were all correct. The problem was that I had been using a different type of quotation mark which I still cannot find on my keyboard.

Quote type 1 = “ (this one was causing the problem)
Quote type 2 = " (this can be found above the right shift key on a mac)

The text had been copied and pasted from another file which contained these weird quotation marks. If anyone knows where this alternative mark came from it would be useful to know for the future.

Many thanks for all your input guys.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜