Jump to content

For loop...not working...why?


The14thGOD

Recommended Posts

I can't seem to figure out why this won't work and no one else I've shown it too can either (a whole 2 other ppl). Any help would be nice, thanks in advance =D.

 

Edit-----

I should explain what's not working! HA!

Basically it just goes through the first data1 entry, it doesn't hit the others.

So it basically loops through one table and stops, it never goes to data2 etc etc.

---edit done

 

Some things have been removed like specific names.

 

Basically I'm taking data from multiple tables and putting it into one giant table (the way it should have been set up but

for a specific reason I set it up differently and then never did what I was going to do.)

 

<?php
    include("old_connect.php");
    $array = array('data1','data2','data3','data4','data5','data6','data7','data8');
    for($i=0;$i<8;$i++) {
        $select_table = 'table_'.$array[$i];
        $query = "SELECT * FROM $select_table";
        $results = mysql_query($query);
        $description = addslashes($row[description]);
        while($row = mysql_fetch_array($results)) {
            include("connect.php");
            $add_date = "INSERT INTO art (abc,def,ghi,jkl,lmn,opq,rst,uwv,xyz,status) ";
            $add_data.= "VALUES ('$row[abc]','$array[$i]','$row[def]','$row[ghi]','$row[jkl]','$row[lmn]','$row[opq]','$row[rst]','$description','$row[status]')";
            mysql_query($add_data);
            if(mysql_error() != "") {
                echo(mysql_error());
                exit(0);
            }
        }
    }
    header("Location: http://www.google.com");
?>

 

Thanks Again,

 

Justin

Link to comment
https://forums.phpfreaks.com/topic/97744-for-loopnot-workingwhy/
Share on other sites

Well, it doesnt hit me right now, why exactly your loop doesnt work, but heres a few ideas.

 

$description = addslashes($row[description]);

Shouldnt that be AFTER you define what $row holds?

 

and try taking the if sentence away from the end, see if it works then? Though it should give up an error...

 

make sure that you have all the tablenames and such correct.

Ah, yea sorry I copied the wrong version, it's actaully after that (that was one thing that we tried just for ****s and giggles). It's actually after the while. I'll try taking out the if too and get back to you, going to bed right now though.

 

If anyone else has any ideas please let me know, ty again =D

 

Justin

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.