echoId (function)

Last updated: Mon, Apr 17, 2023 8:09 am
Return to Knowledgebase


Simplifies the process of retrieving a specific value from a table in the database by providing a convenient wrapper function.




# Parameter Data Type Required Description
1 $id integer Yes represents the ID of the record to retrieve from the database
2 $table string Yes represents the name of the table from which to retrieve the record
3 $column string Yes represents the name of the column from which to retrieve the value of the record


Data Type Description of Returned Data

Further Documentation:

The function first creates an instance of the UserSpice database class (DB::getInstance()) and then executes a SQL query to select the value from the specified table where the ID matches the given $id. The function then checks if any results were returned, and if so, it outputs the value using the echo statement. If no results were returned, it outputs a message stating that the ID was not found and returns false.

Here is an example of how to use the echoId function:

Suppose you have a table named users that contains the columns id, name, and email. You want to retrieve the email address of the user with ID 5 and display it on the page. You can use the echoId function like this:

echoId(5, 'users', 'email');

This will output the email address of the user with ID 5, assuming that the ID exists in the users table. If the ID does not exist, the function will output the message "Not in database" and return false.

This function can be useful in situations where you need to retrieve a specific value from the database and display it on the page. It saves you from having to write the SQL query manually and handles the error checking for you. Additionally, since the function is part of the UserSpice framework, it is already included in the codebase and can be used without requiring any additional setup.