MySQL help
Posted
#4949
(In Topic #1105)

Standard member

Returning all rows from table
I'm creating a new symbol to pull all rows from a specific table, but I've hit a roadblock: it seems my returned results are in an array, but I have no idea how to convert that to a string. I tried using PHP's implode() but this just caused errors about array to string conversions.Code (php)
$db = $GLOBALS['SITE_DB'];
$sql = 'SELECT ' . $param[0] . ' FROM ' . $db->get_table_prefix() . 'catalogue_categories WHERE c_name="' . $param[1] . '"';
$query = $db->query($sql);
return json_encode($query);
$sql = 'SELECT ' . $param[0] . ' FROM ' . $db->get_table_prefix() . 'catalogue_categories WHERE c_name="' . $param[1] . '"';
$query = $db->query($sql);
return json_encode($query);
Returns this:
[{"cc_title":"Contact Us"},{"cc_title":"Overview"},{"cc_title":"Features, Tools, & Modules"},{"cc_title":"Help & Support home"},{"cc_title":"Overview"},{"cc_title":"General"},{"cc_title":"Website"},{"cc_title":"Member Sites"},{"cc_title":"Opportunities"},{"cc_title":"Training"},{"cc_title":"Forums"},{"cc_title":"Profile & Accounts"},{"cc_title":"PRO Membership"}]
How do I get rid of all the junk here and just return all cc_title's (maybe seperated by commas)?
Posted

Site director

Code
return implode(',', collapse_1d_complexity('cc_title', $query));
Become a fan of Composr on Facebook or add me as a friend. Add me on on Mastodon. Follow me on Minds (where I am most active). Support me on Patreon
- If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
- If so, please let others know about Composr whenever you see the opportunity or support me on Patreon.
- If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying Composr on fun personal projects.
- If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
1 guest and 0 members have just viewed this.