You are here: Using mysql_result() Deletes Row From Result « PHP Programming Language « IT news, forums, messages
Using mysql_result() Deletes Row From Result

Posted by Steve on 09/10/06 05:11

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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация