Jump to content

Better way to reword code?


duezy

Recommended Posts

I know most of you guys hate to hear this but I'm relatively new to php, i'm working on a personal site and have created this code that basically removes all members of a softball team.  The code works like a charm for me, as it updates all members of a given team id and sets there team and team_id to NULL.  This is my question, am I doing this the PHP correct way?  Is there another way I could do this that is PHP correct?  I could sit on here for light years and ask you experts questions that I have about PHP but i'll spare you guys tonight.

 

Thanks in advance and any help any guidance is appreciated.. 

 

   $query = "select username, team_id, team FROM tgl_users WHERE team_id = '".$_GET['team_id'] ."'";
   $result = mysql_query($query, $dbc); 
   //run the while loop 
   while($r=mysql_fetch_array($result)) {
//delete info from all users of team_id
$query_update = "UPDATE tgl_users SET team=NULL, team_id=NULL, coach=NULL WHERE team_id = '".$_GET['team_id'] ."'"
or die(mysql_error());
mysql_query($query_update, $dbc)
or die(mysql_error());
   }
   	echo 'team has been deleted and all users have been removed';

} 

Link to comment
https://forums.phpfreaks.com/topic/194080-better-way-to-reword-code/
Share on other sites

One thing i know is that

 

$query = "select username, team_id, team FROM tgl_users WHERE team_id = '".$_GET['team_id'] ."'";
$result = mysql_query($query, $dbc); 

 

can be shortened to

 

   $result = mysql_query("select username, team_id, team FROM tgl_users WHERE team_id = '".$_GET['team_id'] ."'", $dbc); 

 

and same with

 

mysql_query("UPDATE tgl_users SET team=NULL, team_id=NULL, coach=NULL WHERE team_id = '".$_GET['team_id'] ."'", $dbc) or die(mysql_error());

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.