RE: [PHP-DB] Can't see the results

2002-09-09 Thread Wilmar Perez


Hi guys, it's me again.

Well, I did as Peter suggested and changed my code for this:

$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());

$num_results_cat = mysql_num_rows($result_cat) or die
($mysql_error());

while($row = mysql_fetch_array($result_cat))
{
$content .= $row[author_full_name].br;
}


Well, it should give me the full name of 22 people but all I'm getting is a 
row of 22 zeros.  I checked the database and in fact the data is there.

Any idea of what I could be missing?

Thanks a lot for your help


***
 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




RE: [PHP-DB] Can't see the results - It works now!!!

2002-09-09 Thread Wilmar Perez

Hello guys (again)

Well, just wanted to let you know that my code is working now, at the end it 
worked thanks to the help of Jim and Peter.  The following is the resulting 
code just in case anyone can make use of it.

Thankyou so much.

$query_cat = select concat(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());
$num_results_cat = mysql_num_rows($result_cat) or die
($mysql_error());

while($row = mysql_fetch_array($result_cat))
{
$content .= $row[author_full_name].br;
}


***
 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




RE: [PHP-DB] Can't see the results

2002-09-07 Thread Peter Lovatt

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=\#00\ class=\font-
small\a href=\index.php\nbsp;nbsp;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]))./abrbr;
}

$content .= /td/tr/table/td/tr;
}

//Send values
$colecciones - SetTitle(Colecciones);
$colecciones - SetContent($content);
$colecciones - Display

[PHP-DB] Can't see the results

2002-09-06 Thread Wilmar Perez

Hello guys

Thanks to all those you helped me with y the question I made before (not a 
valid MySQL result) it's working now.  

Now, I want to display the result of my search with the following code:

if($code){

$query_cat = select author.author_names || ' '|| author.author_surnames 
 as full_name 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);

$num_results_cat = mysql_num_rows($result_cat);

for ($i=0; $i  $num_results_cat; $i++)
{
 $row = mysql_fetch_array($result);
 $content .= $row;
 /*
 $content .= htmlspecialchars(stripslashes($row[author_names]))
   . .htmlspecialchars(stripslashes($row [author_surnames])).br;*/
}

}   

But I just get the following:

ArrayArrayArrayArrayArrayArrayArrayArrayArrayArrayArrayArrayArrayArrayArray

I also tried to do it commenting the $content .= $row;  and uncommenting 
the lines that are commented in the code but I just get a blank page.  

What am I doing wrong?  

Thanks a lot for your help.
***
 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




Re: [PHP-DB] Can't see the results

2002-09-06 Thread Jim Hunter

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

---Original Message---

From: Wilmar Perez
Date: Friday, September 06, 2002 14:50:44
To: php-db mailing list
Subject: [PHP-DB] Can't see the results

Hello guys

Thanks to all those you helped me with y the question I made before (not a 
valid MySQL result) it's working now. 

Now, I want to display the result of my search with the following code:

if($code){

$query_cat = select author.author_names || ' '|| author.author_surnames 
as full_name 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);

$num_results_cat = mysql_num_rows($result_cat);

for ($i=0; $i  $num_results_cat; $i++)
{
$row = mysql_fetch_array($result);
$content .= $row;
/*
$content .= htmlspecialchars(stripslashes($row[author_names]))
. .htmlspecialchars(stripslashes($row [author_surnames])).br;*/
}

} 

But I just get the following:

ArrayArrayArrayArrayArrayArrayArrayArrayArrayArrayArrayArrayArrayArrayArray

I also tried to do it commenting the $content .= $row; and uncommenting 
the lines that are commented in the code but I just get a blank page. 

What am I doing wrong? 

Thanks a lot for your help.
***
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

.