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
- MySQL Error: : ‘Access denied for user ‘root’@’localhost’
- How to add elements to an empty array in PHP?
- ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: YES)
- ERROR 1698 (28000): Access denied for user ‘root’@’localhost’
- When to use SELECT … FOR UPDATE?
- Forbidden :You don’t have permission to access /phpmyadmin on this server
- MySqli Commands out of sync; you can’t run this command now
- Trying to get property of non-object in
- Fix Access denied for user ‘root’@’localhost’ for phpMyAdmin
- Getting connection failed: php_network_getaddresses: getaddrinfo failed: Name or service not known
- #1045 – Access denied for user ‘root’@’localhost’ (using password: YES)
- How to update a record using sequelize for node?
- Can’t open the mysql.plugin table. Please run mysql_upgrade to create it
- Convert MySQL to SQlite [closed]
- MySQL query to get column names?
- MySql: is it possible to ‘SUM IF’ or to ‘COUNT IF’?
- MySQL: What’s the difference between float and double?
- How can I search (case-insensitive) in a column using LIKE wildcard?
- No query results for model [App\Products] Laravel
- SQL – IF EXISTS UPDATE ELSE INSERT INTO
- How to unblock with mysqladmin flush hosts
- You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ””)’ at line 2
- Php – Your PHP installation appears to be missing the MySQL extension which is required by WordPress
- WordPress mysqli and PDO
- Transaction when using WP functions rather than vanilla SQL?
- How to properly insert data into custom table via plugin
- Searching users with WP_List_Table plugin
- Jquery ajax to custom php file: returning blank data
- Same option_id=0 for 2 options in wp_options?
- How to let a user choose an authors and save it to the database?
- How to merge local and live databases?
- Is a MySQL DATETIME or TIMESTAMP value retrieved through $wpdb in UTC?
- Performance issues with large website [closed]
- WordPress 3 – how are passwords stored and how do I compare to them?
- MySQL crashed because of the large number of requests
- How to select WooCommerce products by post_meta and order them
- Remove one value in dismissed_wp_pointers?
- How can I save unique user data on my site? [closed]
- 306 MB of wp_options occupied by WordPress SEO Plugin, is that normal? [closed]
- SQL Database, repeated tables?
- Assign External Database Queries to Global Variables and Make Them Accessible
- Using custom tables for old posts
- Notice: Uninitialized string offset: 0 in social sharing mu-plugin
- Multiple meta_key in one global $wpdb;
- Moving wordpress site from localhost to live server using GoDaddy cPanel
- How does WP work in conjunction with a web server?
- WordPress create database not working
- WordPress function and string as variable?
- Location of core code for database connection and get_header
- WordPress and MySQL: trying to print data using PHP from user_meta custom field data
- database optimization and server errors
- Get access to variable from previous pageview, excluding ajax-calls
- Hide posts if user is added to it WP_query
- Setting up WordPress Locally on WAMP for a new site (with one already)
- Store and Change Session variable – PHP SESSION VARIABLE
- Overide Variable in Child Theme
- Get the id of the row from database on click of a button [closed]
- Calling mysql_query() on another database, assumes WordPress using that database
- querying user bookmarks from a large number of bookmarks
- How to fix the amount of comments displayed for each post?
- SQL error with custom query
- Modify WooCommerce used to get all orders in dashboard
- How do I echo all users’ display_name and their meta_value who have a certain meta_key?
- global $product is empty string when passed into function
- Inside Array – “unidentified index” error with “prepare was called incorrectly” despite not calling the prepared statement with wordpress [closed]
- WordPress Bad Request Error 400
- I am facing this error Your PHP installation appears to be missing the MySQL extension which is required by WordPress
- What is the correct way to search 3 custom fields only in WordPress?
- SQL. Select category descendants
- MySQL Actibity without any active visitors via Google Analytics
- New database entry to trigger runing PHP/SQL query through link with token, without logging into the website
- Query doesn’t display text data with apostrophes
- I want show only data for today
- Why is local wordpress install calling live site executions?
- Display MySQL as part of a Page
- Migration of wordpress database from mariadb 10.0.20 to 5.5.50
- WP Meta Query – mixed AND / OR query doesn’t work
- Internal error (500) on local & Fatal error on live when trying to access post type edit screen
- Query sql for truncate post_content in wp_posts table
- PHP Use Declared array Variable inside already Declared Array
- Your PHP installation appears to be missing the MySQL … After deleting and restarting from cpanel
- Why does the MySQL command line tool ignore the –port parameter?
- Postgres equivalent to MySQL’s \G?
- Possible SQL injection. How to locate and fix?
- Can’t insert into a database wordpress