开发者

Unusual Issue with PHP/MYSQL-- Names are getting cut off

开发者 https://www.devze.com 2023-03-06 15:23 出处:网络
For certain products in my Database, The name of the product will get cut off between the <a href=\" RIGHT HERE\"></a>

For certain products in my Database, The name of the product will get cut off between the <a href=" RIGHT HERE "> </a>

It will display correctly via the HTML visual side. But, the link will sometimes render a shortened name.

Does anybody have any idea why this could be?

I cant seem to even think what the problem could be?

            $result = mysql_query($query);
            while($row = mysql_fetch_row($result))
                {


        $namelink = str_replace(" ","_",$row[1]);



print <<< PRODUCT_RESULTS
    <table  cellpadding="5" cellspacing="5" id="vProducts">
        <tr>
                <td><img src="$row[3]"/></td>
                <td id="prod开发者_运维技巧uctTitle"><a href="/view_product1.php?name=$namelink&model=$row[0]">$row[1]</a><br />
                <li>Model: $row[0]</li>
                </td>
        </tr>
    </table>
    <div style="width:749px; height:1px; background:#CCC;"></div>

PRODUCT_RESULTS;
}

Table Structure:

   CREATE TABLE `products` (
  `modelNumber` varchar(100) NOT NULL DEFAULT '',
  `name` varchar(400) DEFAULT NULL,
  `shortDescription` varchar(500) DEFAULT NULL,
  `image` varchar(400) DEFAULT NULL,
  `largeImage` varchar(400) DEFAULT NULL,
  `url` varchar(400) DEFAULT NULL
  )


This might sound crazy, but do you have >, ", or some other character which would make for invalid HTML in that entry? What happens when you use "view source"? Is it still cut off?

As an aside, I don't know if you realize this, but you're doing a double-lookup on those variables. This is not only slower, but it is harder to debug. Instead of doing this:

             <td id="productTitle">
                  <a href="/view_product1.php?name=$namelink&model=$row[0]">
                      $row[1]
                  </a>
                  <br />
                  <li>Model: $row[0]</li>

Set variables before the print equivalent to each of the array indexes and then output that result.

You could also get rid of the call to print and simply use ?> <?php. Obviously, you would need to output the contents of the variables manually once you did that, but it would, arguably, be cleaner and clearer.


Change $row[3] to $row[image] and $row[0] to $row[modelNumber] etc.. And if that didn't work i would need to see the $query.

Edit: Krinkle (comment below), suggests using $row["image"] and $row["modelNumber"] which is a better practice.

0

精彩评论

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