Reply to Re: Using mysql_result() Deletes Row From Result

Your name:

Reply:


Posted by Jerry Stuckle on 09/11/06 00:41

Steve wrote:
>
>> 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?
>>
>
> Here you go.
>
> <?
> if (isset($_POST['parts_choice']))
> {
> $parts_choice = $_POST['parts_choice'];
> if (substr($parts_choice,0,6) != "Choose")
> {
> if (db_connect())
> {
>
> $query2 = "select parts.category,
> parts.part_number,parts.years, parts.description, parts.price,
> parts.graphic, categories.description AS Category";
> $query2 = $query2." FROM parts INNER JOIN categories on
> parts.category = categories.code";
> $query2 = $query2." where parts.category = '$parts_choice'";
>
> //echo("<p class=\"text\" align=\"center\">\$query2=
> $query2</p>");
>
> $result2 = mysql_query($query2) or die(mysql_error());
> $num_results2 = mysql_num_rows($result2) or die(mysql_error());
>
> if ($_POST['get_parts'] == "Display Parts")
> {
> $category_name = mysql_result($result2,0,6);
> ?>
> <center>
> <h2><?php echo $category_name ?></h2>
> <table border="1" cellpadding="5">
> <tr>
> <th>Part Number</th>
> <th>Years</th>
> <th>Description</th>
> <th>Price</th>
> <th>Picture</th>
> </tr>
> <?
> }
> else
> {
> echo("<p class=\"text\" align=\"center\">There was an
> error.</p>");
> }
>
> 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>
> <?
> }
> ?>
> </table>
> <br>
> <br>
>
> <?
> }
> }
> }
> do_html_footer();
> ?>

Are you sure it's the last row you're not getting, and not the first?

I think your problem is you're trying to fetch the category with
mysql_result, then using mysql_fetch_array() to get the data.

From the PHP manual on mysql_result():

"Calls to mysql_result() should not be mixed with calls to other
functions that deal with the result set."

Perhaps you should get your category description after you fetch the
contents for the first row.

Another option would be to run a query to fetch just the category
description, rather than return it in every single row (just to save a
query). At some point the extra data returned will take longer than a
second select statement.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[Back to original 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

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