Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 12-12-2002, 08:32 AM   #1 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,444
sde is on a distinguished road
returning functions

i'm working on a new project that has many db functions. Before i ask the question, i'll show an example of some code:
PHP Code:
<?
deleteAgent
($agent_id)
{
  
$result=mysql_query("delete from agents where agent_id='$agent_id'");
  
$num=mysql_numrows($result);
  
  if(
$num == 0)
  {
    return 
0;
  }
  else
  {
    return 
1;
  }
}
?>
is this the best way to return 1 if the query actually executed something? for example, i want to use the function like this:
PHP Code:
<?
if(deleteAgent($agent_id))
{
  echo 
"Agent delted successfully.";
}
else
{
  echo 
"There was an error deleting this agent.";
}
?>
it seems like a simple thing to do, .. i'm just making sure this is the best way to do it.
sde is offline   Reply With Quote
Old 12-18-2002, 02:14 AM   #2 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,693
redhead is on a distinguished road
Why not just return $num ??

Then just have:

if(!deleteAgent($someAgent))
echo "Error deleting";
else
echo "Deleted";

--Edit---
I would go for this, since the code itself is explaining just what it does..
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Accessing functions from base class dirs Standard C, C++ 80 05-20-2004 04:47 AM
writing basic functions? Admin PHP 4 11-25-2003 12:43 PM


All times are GMT -8. The time now is 12:08 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting