Hi
you are using mysql_fetch_array which returns an array indexed by field name
eg
$row = mysql_fetch_array($result)
$row["Author"] will be 'fred bloggs'
you are indexing using a number which needs mysql_fetch_row
suggested simplified code is
I have named the resulting field as 'author_full_name' for clarity
If $code is not a number then it shold be quoted.
$query_cat = "select author.author_names || ' ' || author.author_surnames
AS author_full_name
from author, authorxcat
where authorxcat.cat_code = $code
and author.author_code = authorxcat.author_code"
;
$result_cat = mysql_query($query_cat) or die($mysql_error());
while($row = mysql_fetch_array($resultID))
{
$content .='html code......'
$content .= $row["author_full_name"]
$content .='html code......'
}// end while
**you could also do as Jim suggested
$result_cat = mysql_query($query_cat) or die($mysql_error());
while($row = mysql_fetch_row($resultID))
{
$content .='html code......'
$content .= $row["0"]
$content .='html code......'
}// end while
-----------------------------------------------
Excellence in internet and open source software
-----------------------------------------------
Sunmaia
www.sunmaia.net
tel. 0121-242-1473
-----------------------------------------------
-----Original Message-----
From: Wilmar Perez [mailto:[EMAIL PROTECTED]]
Sent: 07 September 2002 00:38
To: [EMAIL PROTECTED]
Subject: Re: [PHP-DB] Can't see the results
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)
<?php
require("../common/main_page_generator.php");
//Create an instance of the class
$colecciones = new Page();
$content = "<tr>
<td bgcolor=\"#000000\" class=\"font-
small\"><a href=\"index.php\"> P�gina principal</a></td>
</tr>
<tr>
<td>
<table width=\"100%\" border=\"0\"
cellpadding=\"0\" cellspacing=\"0\">
<tr>
<td align=\"center\"
background=\"../images/layout/background_left_column.gif\"><br>";
//Operations
$query = "select * from categories order by cat_name";
$result = mysql_query($query);
$num_results = mysql_num_rows($result);
if($code){
$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>
<td>
<img
src=\"../images/colecciones/central_image.gif\" width=\"250\" height=\"2\">
</td>
<td align=\"center\"
background=\"../images/layout/background_right_column.gif\">
<br>";
}
$row = mysql_fetch_array($result);
$content .= "<a href=".$PHP_SELF."?code=".$row
[cat_code].">".htmlspecialchars(stripslashes($row
["cat_name"]))."</a><br><br>";
}
$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.
Jim
***************************************************************************
*******************************************************
Wilmar P�rez
Network Administrator
Library System
Tel: ++57(4)2105145
University of Antioquia
Medell�n - Colombia
2002
*******************************************************
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php