Page 1 of 1
Variable loses its value
Posted: Wed Apr 05, 2006 5:50 pm
by AYYASH
Code: Select all
for ($j=0; $j < $rows; $j++) {
for ($i=0; $i < 6; $i++) {
$row = mysql_fetch_array($query);
$array[$j][$i] = $row['thumb'];
$project[$j][$i] = $row['id'];
}
}
This code works fine in my pc where I have php5 with apache 1.3.
When I uplaod it to the site and click the link that contains $project[$j][$i], it loses its value. When I print out its value only ($row['id']) it shows up.
see it here
http://www.mohtaraf.com/portfolio/photo ... 10&img=101
click on one of the thums in the page and you'll that "project" will be= ''. Click on it again, it will get back the value. Doesn't make sence to me.
The other thing that make me out of my mind is that $array[$j][$i] is working fine with no probelms at all.
Any idea why?
Posted: Wed Apr 05, 2006 7:40 pm
by pennythetuff
Could you post more code please?
Posted: Wed Apr 05, 2006 10:35 pm
by josh
Usually you iterate over query results like this
Code: Select all
while($curr_row=mysql_fetch_assoc($result)) {
echo $row['id'];
echo $row['whatever'];
/* or
foreach($row as $field_name => $field_value) {
} */
}
Posted: Thu Apr 06, 2006 1:32 am
by AYYASH
this is the part of the code that comes before the one I posted
Code: Select all
$select = "SELECT * FROM projects WHERE category='".$_REQUEST['category']."'";
$query = mysql_query($select);
$nums = mysql_num_rows($query);
// define number of thumbs rows
if ($nums <= 6) {
$rows = "1";
} elseif ($nums <= 12) {
$rows = "2";
} elseif ($nums <= 18) {
$rows = "3";
} elseif ($nums <= 24) {
$rows = "5";
} elseif ($nums <= 30) {
$rows = "6";
} else {
$rows = "7";
}
for ($j=0; $j < $rows; $j++) {
for ($i=0; $i < 6; $i++) {
$row = mysql_fetch_array($query);
$array[$j][$i] = $row['thumb'];
$project[$j][$i] = $row['id'];
}
}
The next code is the part inside the HTML page:
Code: Select all
<table border="0" cellpadding="0" cellspacing="4" bgcolor="4E4E36">
<?php for ($j=0; $j < $rows; $j++) { ?>
<tr>
<?php for ($i=0; $i < 6; $i++) { ?>
<?php if ($array[$j][$i]=='') { print ""; } else { ?>
<td valign="middle"><a href="photo.php?album=by_category&category=<?php print $_REQUEST['category']; ?>&project=<?php print $project[$j][$i]; ?>&img=<?php print $project[$j][$i]."1"; ?>"><img border="0" src="<?php print $array[$j][$i]; ?>" /></a></td>
<?php } ?>
<?php } //if ?>
<?php } //$i ?>
</tr>
<?php } //$j ?>
</table>