PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
Steveo31
Forum Contributor
Posts: 416 Joined: Sun Nov 23, 2003 9:05 pm
Location: San Jose CA
Post
by Steveo31 » Fri Apr 16, 2004 8:59 pm
I'm inserting a bunch of actors/actresses to a DB by splitting the input with the delimiter "|". Then it inserts to the DB like so:
Code: Select all
<?php
mysql_connect('localhost', 'root');
mysql_select_db('people');
$actors = "John Wayne | Bruce Lee | Steven Segall | Tim Meadows";
$indiv = explode("|", $actors);
foreach($indiv as $key=>$value){
echo $key.': '.$value.'<br />';
$get = "SELECT name FROM people_table";
$get_query = mysql_query($get);
#######
### Not working:
#######
while($row = mysql_fetch_assoc($get_query)){
if($value == $row['name']){
break;
}
}
## end "not working"
$sql = "INSERT INTO `people_table` (`name`) VALUES ('$value')";
$query = mysql_query($sql) or die(mysql_error());
?>
So yea.. the "while" part is what isn't working. Basically I need it to stop the loop, thus not inserting the name if it is found in the database.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Apr 16, 2004 9:31 pm
change
to
should take care of it.
Steveo31
Forum Contributor
Posts: 416 Joined: Sun Nov 23, 2003 9:05 pm
Location: San Jose CA
Post
by Steveo31 » Fri Apr 16, 2004 10:45 pm
That... or should I trim() them?
Thanks for the reply though.