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];
} 

Link to comment
Share on other sites

<?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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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 :(

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.