|
Posted by Jerry Stuckle on 09/10/06 14:32
Steve wrote:
> Trying to do a pretty simple page where I display car parts on a page
> based on the category selected from a drop down list. Here's my tables
> setup:
>
> categories
> code CHAR(3)
> description (25)
>
> parts
> category CHAR(3)
> part_number CHAR(15)
> years CHAR(9)
> description CHAR(35)
> price DECIMAL(6,2)
> graphic CHAR(15)
>
> What I try to do is pretty simple:
>
> 1)Query db to get items in category based on what is chosen in the drop
> down list
> 2) Write header of table for displaying data, including category name as
> title
> 3) Cycle through returned result using mysql_fetch_array().
>
> Pretty simple. The problem I'm having is with getting the category
> name. I use one query to get everything:
>
> SELECT parts.category, parts.part_number,parts.years, parts.description,
> parts.price, parts.graphic, categories.description AS Category";
> FROM parts INNER JOIN categories on parts.category = categories.code
> WHERE parts.category = '$parts_choice'
>
> I then use mysql_result() to get the category name from the first row
> (since it will be the same in all rows). The problem I'm having is that
> when I use mysql_result(), the data from the last row in the result set
> is not displayed, even though the HTML for that row is written out, and
> the "No parts found for this category" message is written to the page
> (see below).
>
>
> for ($i = 0;$i < $num_results2; $i++)
> {
> $row2 = mysql_fetch_array($result2);
>
> if (!$row2)
> {
> echo "No parts found for this category.";
> }
> ?>
> <tr>
> <td><?php echo $row2["part_number"]?></td>
> <td><?php echo $row2["years"]?></td>
> <td><?php echo $row2["description"]?></td>
> <td>$<?php echo $row2["price"]?></td>
> <?php
> if (strlen($row2["graphic"]) > 0)
> {
> ?>
> <td align="center"><img src="graphics/<?php echo
> $row2["graphic"].".jpg"?>" border="0"></td>
> <?php
> }
> else
> {
> ?>
> <td>No picture available</td>
> <?php
> }
> ?>
> </tr>
> <?
> }
>
> So it's like for some reason, reading the Category name from the first
> row causes the last row from the result to be deleted. Has anyone seen
> this before, or can someone explain why this might be happening?
>
> Thanks.
>
> Steve
Steve,
The code you've posted shouldn't do that. Mind posting ALL of you
rcode? For instance - where do you fetch the data and retrieve the
category?
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Navigation:
[Reply to this message]
|