Only first character of string displayed instead of whole string

I am using a borrowed piece of code to display some pictures and their descriptions in a web page, at least that is the goal. The problem is that only the first character of the string is being displayed. I have inserted the “print_r()” function at the end of my code to try to help debug but am not seeing the coding malfunction. I can see as the result of “print_r()” that the array is what I expect which leads me to look in the second “echo” argument of the “foreach ($files as $file)” loop but cannot see what or where the problem is. While a direct answer would solve my issue a more useful answer would be what to look at or for so I can better learn the error and (hopefully) how to aviod it in the future. Below is the portion of the code in question.

Thank you

ikan
[php]<?php
$thumbs = “…/illustrations/Origional_Photos_Here/a_bunch_of_cut_ups/TH_cu_set_1/”; # location of small images used
$pics = “CU_set_1/”; # subdir of TH_cu_set_1, location of full size images
$cols = 5;
$pic_text = “C:/Theme_Time_Web_Pages/htdocs/illustrations/Origional_Photos_Here/a_bunch_of_cut_ups/CU_names_1.txt”; # a CSV of image names and their descriptions in the format of “picture_name.jpg,picture description as repeate of picture name”

$fh=fopen($pic_text, “r”);
while(!feof($fh))
{
$line=fgets($fh);
$temp = explode(",", $line);
$description [$temp[0]] = $temp[1];

unset($temp); 

}

if ($handle = opendir($thumbs))
{
while (false !== ($file = readdir($handle)))
{
if ($file != “.” && $file != “…” && $file != $pic_text && $file != rtrim($pics,"/" ))
{
$files[] = $file;
}
}
closedir($handle);
}
$colCtr = 0;
echo ‘

’;
foreach($files as $file)
{
if($colCtr %$cols == 0)
echo ‘’;
echo ‘’;
$colCtr++;
}
echo ‘


’ . $description[$file][0] . ‘
’ . “\r\n”;
print_r ($description)."
";
?>[/php]

This would be 100% easier if it was stored in a database. In the foreach loop, do a print_r on $file, all it should contain is the filename. Also take a look at the html source output (right click on screen, view source) and make sure the table is being properly made, i have a feeling its not.

You are very correct richie. The table is now not being created at all (two days ago at least i got the pictures and the first lettter of the description). As for the database thing I’m sure your correct there as well but I’m not there yet…that is much deeper into the iceburg. I did try looking at the source code and where the table should be there are the expected opening and closing tags for “table,div, tr, and td”. I am treating the table generated by the imbeded PHP as a single cell single row table as far as the html is concerned but instead of the neat rows and colums of pics there is one line “

” that comes from nowhere . This line sits dead center between the open and closing set of tags listed above and has no visible origion. Just to be sure I reread the rest of th code on the page as well as the css style sheet called and the two navigation pages included further up the page. None of them have any referance to cellspaceing what so ever. Is it possible that a line supposedly deletd from an earlier version of the code block remains and is rearing its ghostly head? I do remember playing with cellspacing in an early version of the page but deleted the line long ago. Now I am really shaking my head in wonder.

ikan

I use the concept to display some stats, I’ll post that code when I get home. MySQL is actually ptetty simple to use. Ill post both examples so you can see the difference.

ok, here you go, just keep in mind that my data is coming from a database, but its the same methods either way.

[php]echo “

\n\n”;

$fco = mysql_query(“SELECT DISTINCT(country) country FROM venzo_clients ORDER BY country”);
while($c = mysql_fetch_array($fco)) {
$co[] = $c[‘country’];
}

$counter = 0;
$col = 4; // sets the number of columns needed

foreach($co as $type){
$q = mysql_query(“SELECT COUNT(username) AS user, country FROM venzo_clients WHERE country = ‘$type’ GROUP BY country”) or die(mysql_error());
$r = mysql_fetch_array($q);
$ct = $r[‘user’];

if($counter != 0 && $counter%$col == 0) {
	echo "\n</tr>\n<tr>";
}?>
<td><?=$type?></td>
<td><?=$ct?></td>
<?php
$counter++;

}
echo "

";[/php]

The code is great richei, thank you. I guess my core problelm lies in the fact that I don’t know enough to to understand what your code either means or does. You mention two methods. I think I can see the division between them but recognize neither the similarities nor the differences between them nor the similitaries nor differences between your code and mine. At this point I think the best action I can take is to go back to the tutorials and start over and work them more thouroughly to get a better handle on the core language constructs before I try to dive into taking someone else’s code and making it work for me. Obviously PHP is not as simple as HTML to learn or use and I am not going to just pick it up in a few hours reading and tinkering.
I would very much like to find an answer to another question I have posted in the “Installation and Configuration Forum” if you are able. Not receiving any feedback from PHP as to what errors are being commited in the code I am trying to construct feels like I am trying to pin the tale on the donkey without the bennifit of ever taking my blindfold off. It is infinitely difficult to learn something new when you cannot see your errors or successes.
That being said I think I shall spend some time with as many tutorials as I can before class this afternoon.

ikan

All you had to do was replace my stuff for yours, not all that difficult to do :slight_smile:

Sponsor our Newsletter | Privacy Policy | Terms of Service