I found the errors thanks to the help from @Milo
@Milo’s query on catno pointed me to my error with my first query involving catno, and I also noticed a double equals in $catno == $row[0]; when it should be $catno = $row[0];
Final coding is
function QueryStock($cat) {
$query = "SELECT * FROM stock WHERE catno = '$cat'";
global $wpdb;
$row = $wpdb->get_row($query, ARRAY_N);
$catno = $row[0];
$itemname = $row[2];
$price = $row[4];
$stock = $row[5];
echo "There are " . $stock . " bears, the price of each bear is £" . $price;
}
Related Posts:
- How to return number of found rows from SELECT query
- Can i use php sql functions instead of $wpdb?
- $wpdb->delete column values IN ARRAY()?
- Custom query to get post names beginning with a digit
- WordPress get pagination on wpdb get_results
- Ajax $wpdb not returning table data
- Converting MYSQL to WordPress $WPDB
- Why is variable not working on custom sql query using wpdb?
- Show MySQL errors that occur when I excute $wpdb->insert()
- Can’t get wp_insert_post to work
- WSoD being caused by this piece of code
- I want to select the from values from database in WordPress? [closed]
- Update results, Before deleting the related category [closed]
- wp query foreach deleting record returning only first or last item
- Database query works fine outside WordPress
- Using $wpdb (WPDB class) ‘replace’ with multiple WHERE criteria problem
- $wpdb->insert() does not Insert record in a table
- Help with a $wpdb MySQL Query
- Custom array from a query only write the last row of the query
- $wpdb returns duplicate posts
- Mixing variables into an array when inserting values
- Use $wpdb or other PHP script method to find/replace in WP database
- How can I add a new row in a separate database when someone registers via WordPress?
- Basic wpdb update question
- I can’t update my data through $wpdb
- Output: “Array”
- How to use mysql LIKE with wpdb?
- How do I prepare strings for insertions as values into a MySQL table?
- How to use AJAX in WordPress in MYSQL query?
- form $_post action value gets truncated after it passes through two forms
- Why won’t this wpdb get_results query return results?
- WPDB secure custom form
- Add row to custom database Table and delete all rows older than 1 day
- select a single val though a table in wordpress
- populate select options from extra mysql table data
- Query the links Database
- MySQL Query Returns Array () In Shortcode
- Passing in MySQL prepare statement parameter separately throwing error
- Convert a column of a table containing an Array as response in HTML
- Database SQL query error
- MYSQL TIMESTAMP when adding DATE_FORMAT then the output is blank, PHP conflict?
- Conditional formatting on data fetched from MYSQL
- What is the correct way to search 3 custom fields only in WordPress?
- Using wpdb to connect to a different database is not working
- Rewrite SQL query as a prepared statement and use in foreach loop
- Advanced WordPress SQL Query
- MySQL query in WordPress with AJAX
- Passed variable gets undefined variable error on insert on next page
- Using the same shortcode to show any table from the database
- MySQL database migration to WordPress
- Error resetting database index using ALTER TABLE in $wpdb->query
- Putting form result in my database
- How can I update a value of a field depending on outside source?
- Fatal error: Call to undefined function mysql_connect()
- Insert post without actions/hooks
- Import 10,000 Users into WordPress WITH a specific ID for each user
- Custom Plugin For Converting CSV To MySQL
- $wpdb->wp_users returning empty value for
- Using custom tables for old posts
- Multiple meta_key in one global $wpdb;
- WordPress member notification
- Moving wordpress site from localhost to live server using GoDaddy cPanel
- How does WP work in conjunction with a web server?
- Location of core code for database connection and get_header
- Wpdb->insert() doesn’t insert new row after the last one
- WordPress and MySQL: trying to print data using PHP from user_meta custom field data
- Most commented posts by time period (last 12h, last 24h and etc)
- How to get specific attribute from DB
- Hide posts if user is added to it WP_query
- How to unserialize data from MySQL
- PHP -> SQL Query with Summing
- How to insert wp_users ->user login name to wp_terms when a new user registering?
- Known Issues in WordPress When Upgrading PHP to ver 7
- Change MySQL PDO connection to a WPDB connection
- $wpdb->get_results breaking page?
- Get the id of the row from database on click of a button [closed]
- Call to a member function get_row() on a non-object, Unable to use global $wbdp inside a plugin
- SQL error with custom query
- Modify WooCommerce used to get all orders in dashboard
- WordPress SQL Prepare
- Weird fonts showing which are coming from database
- 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
- cant insert data in a custom table in phpmyadmin
- autocomplete in wordpress using ajax with json-data
- 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
- SQL Query Search page
- Accessing external database: ERR_INCOMPLETE_CHUNKED_ENCODING
- At what point during a typical request does the $wpdb object become available?
- Let users register weight each day and save it in DB
- Fetching wpdb data from a php file seems to break?
- posts_clauses drop ACF get_field function
- Execute multiple PHP Snippets causes error?
- use wpdb object on other file
- Warning: Undefined property: wpdb::$question_overview in C:\Wamp.NET\sites\proxyvragenmodule\wordpress\wp-includes\class-wpdb.php
- what to do after instlling cyberpanel on VPS
- Trying to GET data with ajax from database and show in fullcalendar