You are comparing, not assigning:
if ($type == 1){ $type = "Bear"; }
You compare values with ==
or ===
.
You assign values with =
.
You could write less code to achieve the same result too, with a switch
statement, or just a bunch of if
s without the elseif
s.
if ($type == 1) $type = "Bear"; if ($type == 2) $type = "Cat"; if ($type == 3) $type = "Dog";
I would make a function for it, like this:
function get_species($type) { switch ($type): case 1: return 'Bear'; case 2: return 'Cat'; case 3: return 'Dog'; default: return 'Jeff Atwood'; endswitch; } $type = get_species($row['ttype']);
Related Posts:
- How to use mysqli_query() in PHP?
- PHP Connection failed: SQLSTATE[HY000] [2002] Connection refused
- PHP Connection failed: SQLSTATE[HY000] [2002] Connection refused
- PHP Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP
- what does “/index.php?admin/admin_dashboard” in my url mean
- MySQL “Or” Condition
- What is the PHP syntax to check “is not null” or an empty string?
- How can I prevent SQL injection in PHP?
- MySQL IF NOT NULL, then display 1, else display 0
- How to create a foreign key in phpmyadmin
- PHP date() format when inserting into datetime in MySQL
- PHP Like thing similar to MySQL Like, for if statement?
- MySQL – count total number of rows in php
- PHP Warning: mysqli_error(): Couldn’t fetch mysqli in
- Foreach only outputs if id is 0
- Many slow queries post_type = ‘attachment’;
- Help with a $wpdb MySQL Query
- Connect to MySQL using Windows Authentication
- WordPress SQL injection
- Code to remove authors with no posts connected to them
- Not connecting to database in file with multiple MySQL connections
- Way to bulk make all my tags lowercase?
- $Wpdb post meta query is not working with mutliple meta keys and values? [closed]
- What should a WordPress developer know about MySQL? [closed]
- Copyright: Get first and last date of post type
- Defining the same price to all WooCommerce Products
- How i can obtain all the post meta for a specific post as an array?
- multiple where condition in result query
- pagination on data fetched using SQL query
- SQL command to convert all tags in lowercase?
- Which is better and faster ? WordPress Queries or SQL Query
- Grouping posts by a custom meta value
- Variable not staying set
- SQL Query in WordPress – Getting Impossible WHERE error
- Problem with admin login after deployment
- Find out how many times the user has logged in
- WordPress(wpdb class) and mysql stored procedures
- Are these WordPress tables safe to add indexes to?
- Notice: Uninitialized string offset: 0 in social sharing mu-plugin
- Multiple meta_key in one global $wpdb;
- Custom array from a query only write the last row of the query
- WordPress plugins for database queries
- Is it possible to create a WordPress table using array and loop?
- WordPress member notification
- Update MySQL query so that it functions again
- Trying to Create a PHP Variable for post_type that can be referenced Site Wide
- Can’t Query Custom Table Using $wpdb Method
- SQL syntax error when getting data for a url
- Moving wordpress site from localhost to live server using GoDaddy cPanel
- How does WP work in conjunction with a web server?
- Database Structure on Different Servers
- WordPress create database not working
- WordPress Block developer from exporting Database via PHP
- WordPress function and string as variable?
- Assign custom parameter to each post in query
- Can’t run database query
- Create a WordPress shortcode using PHP [duplicate]
- Is there a page length limit?
- WordPress doesn’t display accents after migration
- How to pass a PHP $_GET variable and fetch/output it?
- $wpdb returns duplicate posts
- Creating WordPress Shortcode with Variable
- Using WPDB->Insert()
- Using ‘mysqli_connect’ ‘crashes’ WordPress client-side
- Active DB queries in WordPress?
- Update postmeta after theme switch
- How to stop $wpdb from prepending database name
- Mixing variables into an array when inserting values
- Location of core code for database connection and get_header
- wpdb prepare insert table doesn’t work
- Should I use WordPress to skin a database website?
- php include not working in custom page
- How do I display offsite database info on my wordpress site?
- Custom Post not working as expected
- Creating Database Table vs. Adding MetaData to Post & User
- How to put a form with php code into a variable or shortcode?
- Make a database query using WordPress
- Changing MySQL password via WHM – does this affect WordPress?
- Apply class to every third list item? [duplicate]
- Passing a variable from a FOREACH loop in a link
- Force Users To Relogin
- persist a variable set in header.php all the way down to footer.php
- Query posts by custom taxonomy and sort by post_modified
- WordPress $wpdb get posts from category and sort by custom meta
- WordPress tables and aliases?
- What’s the sql for this condition?
- WordPress and MySQL: trying to print data using PHP from user_meta custom field data
- Import CSV to MySQL, with custom registration field information
- database optimization and server errors
- WordPress Custom SQL Table with UserID Filter for results
- Get access to variable from previous pageview, excluding ajax-calls
- Locally restoring a ManageWP full site backup
- Create a form with custom autocomplete address field and CSV import values
- How to deal with too many $_POST variable conditions from ajax request at backend? [closed]
- WordPress doesn’t save changes some times
- Match tag names with form titles
- Most commented posts by time period (last 12h, last 24h and etc)
- Error missing MySQL extension
- Use $wpdb or other PHP script method to find/replace in WP database
- What is the alternative code to if (isset ($_POST) && !empty ($_POST) to avoid warnings?