Hello again

Well I followed Jim recomendation but it didn't work either, I think I'd 
better send the full code to you (don't worry is very short), so you can have 
a broader idea of what I'm intending to do, which is actually quite a simple 
thing, just to retrieve results from a database according to a selection made 
by the user.  Any help will be highly appreciated.

Well here is the code:

Note:  If you have a look to the part where the main IF condition is false 
(when the $code variable doesn't exist) you'll see that I'm doing something 
pretty simmilar but with a different mysql query.  That part works alright.  
So, what am I missing in the second part? (when the $code variable exists)

        //Create an instance of the class
        $colecciones = new Page();
        $content = "<tr>
                                <td bgcolor=\"#000000\" class=\"font-
small\"><a href=\"index.php\">&nbsp;&nbsp;Página principal</a></td>
                                <table width=\"100%\" border=\"0\" 
cellpadding=\"0\" cellspacing=\"0\">
                                        <td align=\"center\" 
        $query = "select * from categories order by cat_name";
        $result = mysql_query($query);
        $num_results = mysql_num_rows($result);
$query_cat = "select author.author_names || ' ' || author.author_surnames 
                from author, authorxcat                                 
                where authorxcat.cat_code = $code
                and author.author_code = authorxcat.author_code"
                or die($mysql_error());
        $result_cat = mysql_query($query_cat) or die($mysql_error());
        $num_results_cat = mysql_num_rows($result_cat) or die($mysql_error());
        for ($i=0; $i < $num_results_cat; $i++)
        $row = mysql_fetch_array($result_cat) or die($mysql_error());
               $num_cols = count($row); //As suggested by Jim
                for($j=0; $j < $num_cols; $j++){
                    $content .= $row[$j];
        $content .= $num_results_cat."</td></tr></table></td></tr>";
        } else {                
                for ($i=0; $i < $num_results; $i++)
                        if ($i==$num_results/2){
                                $content .= "</td>
src=\"../images/colecciones/central_image.gif\" width=\"250\" height=\"2\">
                                                        <td align=\"center\" 
                        $row = mysql_fetch_array($result);
                        $content .= "<a href=".$PHP_SELF."?code=".$row 
                $content .= "</td></tr></table></td></tr>";
        //Send values
        $colecciones -> SetTitle("Colecciones");
        $colecciones -> SetContent($content);
        $colecciones -> Display();

Jim wrote:

Your problem seems to stem from the $content .= $row; $row is an Array and 
you must use an index to get at any given value it holds. If you need all of 
the values in $row, use the count() function to get the number of elements 
(columns in this case), then loop through them adding them to $content along 
with any separators (IE: commas or semi colons or spaces) etc. the code might 
look like this:
$content = ""; // I like to make sure that the variable is always initialized 
to something before I use it.
$num_results_cat = mysql_num_rows($result_cat);

for ($i=0; $i < $num_results_cat; $i++)
$row = mysql_fetch_array($result);
  $num_of_cols = count($row);
  for ($x=0; $x<$num_of_cols; $x++)
      $content .= ", ".$row[$x];
This will allow you to loop through every row in the query and add every 
column to the $content variable.

                         Wilmar Pérez
                     Network Administrator
                       Library System
                      Tel: ++57(4)2105145
                    University of Antioquia
                       Medellín - Colombia

PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to