Jump to content

anyone know how to put this in a while loop


rickyj

Recommended Posts

anyone got an idea how to complete the following while loop. I want to set a database column (LT_URL) to a sting ($ltURLarray),

but 1st i want to check if it already exist in the db, if it does exist, then I want to test the next sting exist in the db, if it doesnt set LT_URL to $ltURLarray on the i'th attempt.

 

$ltURLarray[0] = 'string0';
$ltURLarray[1] = 'string1'; //.......
$ltURLarray[100] = 'string100';

// some how put the follwing in a while loop while i<100:
i = 0;
URLdata = mysql_query("SELECT LT_URL FROM lt_Users WHERE LT_URL = '$ltURLarray[i]' LIMIT 1")or die(mysql_error()); 
if (!mysql_num_rows($URLdata)){
$ltURL =$ltURLa[0];
} 

<?php
  foreach ($ltURLarray as $ltURL) {
    $fetch=mysql_fetch_assoc(mysql_query("SELECT `LT_URL` FROM `lt_users` WHERE `LT_URL`='".$ltURL."'"));
    if (empty($fetch['LT_URL'])) {
      mysql_query("INSERT INTO `lt_users` (`LT_URL`) VALUES ('".$ltURL."')");
    }
  }
?>

 

Something like that I guess is what you're looking for.

I have something else that does the inserting, so the follwing code should work?

 

  foreach ($ltURLarray as $ltURL) {
    $fetch=mysql_fetch_assoc(mysql_query("SELECT `LT_URL` FROM `lt_users` WHERE `LT_URL`='".$ltURL."'"));
    if (empty($fetch['LT_URL'])) {
      break;
    }
  }

 

// so now $ltURL is set to  $ltURLarray (where ltURLarray is not found)

 

(sorry for me being a bit dumb and spelling it out in full), do you think this will work?

the above didnt work, it just set it to the first one, regardles of it already being present in the database! but I used:

 

  foreach ($ltURLarray as $ltURL) {

    $fetch=(mysql_query("SELECT `LT_URL` FROM `lt_users` WHERE `LT_URL`='".$ltURL."'"));

    if (empty($fetch['LT_URL'])) {

      break;

    }

  }

 

why dont these posts merge :(

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.