954,587 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

For loop

I am really not sure what kind of problem this is but my guss is that it has to do something with php here is the code:

[PHP]echo ""; for ($I=0;$I<$nrow;$I++) { $row1 = mysql_fetch_array($result); extract($row1); echo "$Picture\"";

if ($I == 4)
{
echo "";
}
elseif ($I == 8)
{
echo "";
}
elseif ($I == 12)
{
echo "";
}
elseif ($I == 16)
{
echo "";
}
else
{
echo "     ";
}
}
echo "";[/PHP]
The problem is that when ever it displays the picture with link the picture is one for all the diffrent pictures that were suppose to display and same goes with the link so is it something wrong with the php or what also there is something above this code too and it is :

[PHP]$query = "SELECT * FROM `Catalog` WHERE `ED` = 'E'";
$result = mysql_query($query)
or die("DB Error Please try again later");
$nrow = mysql_num_rows($result);
//to echo out links
echo "Categories";

for ($i=0;$i<$nrow;$i++)
{
$row = mysql_fetch_array($result);
extract($row);
echo "
$Name";
}
echo "
";[/PHP]
I am gussing there could be something wrong here too.w

ashneet
Junior Poster
147 posts since Jun 2005
Reputation Points: 10
Solved Threads: 1
 

the line [php] echo "$Picture\""; [/php] displays and links the picture.

over here you need to make sure $TBL and $Picture that are used are changed everytime. otherwise it will just display the same link/picture each time.


inside the for loop, have something like:-

$TBL = $i;
$Picture = $i.".jpg";

modify the above statements to suit your needs.

jayant
Junior Poster in Training
95 posts since Nov 2003
Reputation Points: 46
Solved Threads: 1
 

Wouldn't the
[PHP] extract($row1); [/PHP]
overwrite the variable every single time the loop repeats as this code works fine:
[PHP]$query = "SELECT * FROM `Catalog` WHERE `ED` = 'E'";
$result = mysql_query($query)
or die("DB Error Please try again later");
$nrow = mysql_num_rows($result);
//to echo out links
echo "Categories";

for ($i=0;$i<$nrow;$i++)
{
$row = mysql_fetch_array($result);
extract($row);
echo "
$Name";
}
echo "
"; [/PHP]

ashneet
Junior Poster
147 posts since Jun 2005
Reputation Points: 10
Solved Threads: 1
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You