Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8662903
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:50:52+00:00 2026-06-12T16:50:52+00:00

Possible Duplicate: PHP file cannot enter some part of code I am building a

  • 0

Possible Duplicate:
PHP file cannot enter some part of code

I am building a news website and I have a function file, for all functions but, nearly all the functions made the same way as the below example:

function one(){
$query  = "SELECT * FROM table WHERE id='$id'....";
$result = mysql_query($query);
while($row=mysql_num_rows($result))
{echo "$row[data]";}  }

So, basically there are many functions that serve different purpose, but have the same exact template as the above, So, to save time, codding I was thinking if is would be possible, to simplify the 5 lines? to one with function like:

function(something here, and here){then the result here?}

Since the only thing that may change from the first code are: Select, table names, id,
and the $row[data], and everything will remain the same what if I assign those to variables and the rest structure will stay as it is in a function:

check this idea.

function simplify() {

$query = "$crud * FROM $table WHERE id= '$id' ";
$result = mysql_query($query);
while($row=mysql_fetch_array($result)) {echo "$row[data]";}


} 

So anytime, I need to create the first code, I could just do

echo simlify(and here would be table name, id, select, create, update...) {

and here the result}

So sorry, for asking this complex question, or asking it with complexity but If anyone has any idea, about what I am talking about, I need your help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T16:50:53+00:00Added an answer on June 12, 2026 at 4:50 pm

    How about this, for a simple database call:

    $db = new DBAdapter(array('host' => 'localhost'));
    $results = $db->Select('mytable')->Where('id > 2')->Execute();
    

    You can achieve this by building your own database class. Put the class in a separate file and reuse it many times.

    class DBAdapter extends PDO
    {
      public function __construct( array $params)
      {
         // construct the connection
      }
    
      public function Select ($table)
      {
        // do stuff for a table select
        return $this;
      }
    
      public function Count ($table)
      {
        // do stuff for a table count
        return $this;
      }
    
    
      public function Where ($condition)
      {
        // do stuff for a where
        return $this;
      }
    
      public function Execute ()
      {
        // execute stuff
        return $result;
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Including PHP functions from another file I'm building code that use function
Possible Duplicate: How to use include within a function? i have two file inc.php
Possible Duplicate: Calling PHP Function within Javascript I have a small JavaScript code in
Possible Duplicate: Minify / Obfuscate PHP Code I have a php file. Anyone knows
Possible Duplicate: Parse a JavaScript file through PHP I have some pretty long string
Possible Duplicate: How to check file types of uploaded files in PHP? I have
Possible Duplicate: Simple PHP Mailer Script i run a small website and we have
Possible Duplicate: Removing a function at runtime in PHP I have a script that
Possible Duplicate: How to find out where a function is defined? included php file
Possible Duplicate: PHP - send file to user I have written a script that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.