Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Server Side Programming Articles
Page 995 of 2109
How to select count with Laravel's fluent query builder?
Laravel's fluent query builder provides an elegant interface for creating and running database queries. It includes built-in protection against SQL injection attacks through PDO parameter binding and supports aggregate methods like count(), min(), max(), avg(), and sum(). To use the fluent query builder, import the DB facade class − use Illuminate\Support\Facades\DB; Let's explore different methods to get count values using Laravel's query builder. We'll use a students table with the following structure and data ? CREATE TABLE students( id ...
Read MoreConvert a floating point number to string in C
In C, converting a floating point number to a string is accomplished using the sprintf() function. This function works similarly to printf(), but instead of printing to the console, it writes the formatted output to a string buffer. Syntax int sprintf(char *str, const char *format, ...); Parameters: str − Pointer to the destination string buffer format − Format string specifier (e.g., "%f" for float) ... − Variable arguments to be formatted Example 1: Basic Float to String Conversion The following example demonstrates converting a floating point number to a string using ...
Read MoreC/C++ Macro for string concatenation
In C programming, macros provide a powerful way to concatenate strings at compile-time using the preprocessor. This technique allows for efficient string manipulation without runtime overhead, making it particularly useful for creating constants, debug messages, and code generation. Syntax /* String literal concatenation */ #define STRING1 "First part" #define STRING2 "Second part" #define CONCATENATED STRING1 STRING2 /* Token concatenation using ## operator */ #define CONCAT_TOKENS(a, b) a##b Understanding Macros in C In C, macros are preprocessor directives defined using #define. They are expanded before compilation, replacing every occurrence with the defined value. Macros ...
Read MoreHow to get distinct values for non-key column fields in Laravel?
In Laravel, you can retrieve distinct values for non-key column fields using several methods. Let's explore different approaches to get unique values from a database table. Assume we have a students table created with the following structure − CREATE TABLE students( id INTEGER NOT NULL PRIMARY KEY, name VARCHAR(15) NOT NULL, email ...
Read MoreC program to print a string without any quote in the program
This is another tricky problem. In this program, we will see how to print a string using C where no quotation marks are used in the source code. Here we are using a macro function with the stringizing operator. We define a macro function that converts its argument into a string literal at compile time. Syntax #define getString(x) #x The getString() is a macro function that returns x by converting it into a string. The # before x is the stringizing operator that converts the macro argument into a string literal. Example ...
Read MoreHow to select all the column names from a table in Laravel?
In Laravel, you can retrieve column names from a database table using several methods. Laravel provides multiple approaches through the Schema facade, Eloquent models, and DB facade to access table structure information. Assume we have created a table named students in MySQL database using the following query − CREATE TABLE students( id INTEGER NOT NULL PRIMARY KEY, name VARCHAR(10) NOT ...
Read MoreC Program to display hostname and IP address
In C, we can retrieve the hostname and IP address of the local system using socket programming functions. This is useful for network programming and system administration tasks. Syntax int gethostname(char *name, size_t len); struct hostent *gethostbyname(const char *name); char *inet_ntoa(struct in_addr in); Key Functions Function Description gethostname() Retrieves the standard hostname for the local computer gethostbyname() Finds host information corresponding to a hostname from host database inet_ntoa() Converts an IPv4 network address into ASCII dotted decimal format ...
Read MoreC Program to print hollow pyramid and diamond pattern
In this tutorial, we will learn how to create hollow pyramid and diamond patterns in C programming. Unlike solid patterns, hollow patterns print stars only at the borders while keeping the interior empty using spaces. Syntax /* Hollow Pyramid Logic */ for(i = 1; i
Read MoreHow to find a user in Laravel by Username?
In Laravel, there are several ways to find a user by username using Eloquent ORM and the database query builder. Each method provides different levels of functionality and data retrieval options. Using the first() Method The first() method returns the first record that matches the search criteria. It returns null if no matching records are found − The output of the above code is − The name exists in the table Using SELECT Query with Specific Fields You can use the select() method to retrieve only specific fields ...
Read MoreC program to print digital clock with current time
In this section we will see how to make a digital clock using C. To work with time we can use the time.h header file. This header file has some function signatures that are used to handle date and time related issues. The four important components of time.h are like below − size_t − This size_t is basically the unsigned integral type. This is the result of sizeof(). clock_t − This is used to store the processor time time_t − This is used to store calendar time struct tm − This is a structure. It helps to ...
Read More