Forum Moderators: coopster
A couple of things for you to be aware of, though, is that your for loop will only count up to 197 unless you change "$i < $num_items;" to "$i <= $num_items;" or initially set "i = 0;".
Also, if you mean for the value of $id to remain a constant 103, as it is now, you ought to put the assingment before your for loop. As it is, you are unnecessarily assigning the value "$id = 103;" over and over again, 197 times.
To see just what's in your array after you've built it with your for loop, try temporarilly adding this line after you close the loop:
?><pre><?php echo $print_r($cat_id);?></pre><?php
Sorry I couldn't answer your specific question, but I hope this helps.
Salsa
Salsa
bool print_r [php.net] ( mixed expression [, bool return] )
print_r() will return a boolean (
TRUE/FALSE) value. So when you echo the value returned by this function it is showing you the "1" or
TRUEvalue returned upon success.
for ($i = 1; $i <= $num_items; $i++) {
$query2 = "SELECT cat_id FROM tbl_category WHERE cat_name = '$cat_name[$i]'" ;
$result2 = mysql_query($query2) or die("Query Error: ".mysql_error());
$row2 = mysql_fetch_array($result2);
if (mysql_num_rows($result2) > 0) {
extract($row2);
$id = $cat_id;$print $id; // this returns '103 1' (I don't know why, the value of that field in the DB is 103)
$print $id; // this returns '103'
$cat_id[$i] = $id;
print $cat_id[$i]; // this returns '1'$query2= "..."; // I ain't gonna write it becouse it's irelevant, but I use the $cat_id[$i] in here
mysql_query($query2) ;
I already solved the problem by not using an array anymore ... i just used the $id variable in the second query.
eventhough ... i still don't get it what the problem was ...
for ($i = 1; $i <= $num_items; $i++) {
$query2 = "SELECT cat_id FROM tbl_category WHERE cat_name='$cat_name[$i]'" ;
$result2 = mysql_query($query2) or die("Query Error: ".mysql_error());if (mysql_num_rows($result2)!="0") {
while ($row2=mysql_fetch_array($result2)){
$id=$row2[cat_id];
print $id;// SIMPLY USED ID IN YOUR QUERY3 (NOTE THAT YOU BETTER
// CHANGE NAME TO QUERY3, RESULT3 AND ROW3 SO THAT YOU
// DO NOT OVERWRITE THE FIRST QUERY
$query3 = "SELECT * FROM #*$!x WHERE #*$!xx='$id'" ;
}}}