You are here: Re: PHP and MySQL issue « All PHP « IT news, forums, messages
Re: PHP and MySQL issue

Posted by Giannis Vrentzos on 08/04/06 07:24

mpar612@gmail.com wrote:
> That worked. Thank you so much! If it's not too much trouble, could
> you please explain to me the logic behind what you did?
>
> Thanks!!!

[snip]

>>> foreach ($results as $artist_name) {
>>>
>>> printf('<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>',
>>> htmlentities($results->isbn),
>>> $artist_name->artist_name, $album_title->album_title,
>>> $release_date->release_date, $results->description, $results->price);
>>> }

Inside foreach loop the valid array is $artist_name so
$artist_name->artist_name will work but $album_title->album_title and
$release_date->release_date will not work because $album_title and
$release_date are not arrays.
Check http://www.php.net/manual/en/control-structures.foreach.php for
more info.

Check for print_r also.
http://gr2.php.net/manual/en/function.print-r.php

If you want to have better code, you have to check if $results is array
and has values.

if (is_array($results) && count($results))
{
// array has values
foreach ($results as $res)
{
// code here
}
}
else
{
// array is empty.
// code here
}

Gvre

>>
>> Try to change the last foreach loop with the following. If this won't
>> work, try print_r($results) to see array's values.
>>
>> foreach ($results as $res) {
>> printf('<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>',
>> htmlentities($res->isbn),
>> $res->artist_name,
>> $res->album_title,
>> $res->release_date,
>> $res->description,
>> $res->price
>> );
>> }
>>
>> Gvre

 

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

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