MySQL data displaying unexpectedly

I'm struggling to find a solution to this little issue I'm having. I've made a new custom table in WordPress using the WordPress Custom Tables Plugin, and I've come to create my code to display that information to the current user, but when I echo out the values of the table, they come with some extra information I don't need or want, strange.

Example: Instead of outputting just Search Name I'm getting s:13:"Search Name"; I'm assuming it's giving me some information from the array that I don't need.

Anyone have an idea how to retrieve only the value of the table data?

For reference, the code that outputs this is as follows:

global $wpdb;
global $current_user;

$userID = $current_user->ID;
$searchIDs = $wpdb->get_results("SELECT * FROM wp_wct3 WHERE userid = $userID;");

foreach($searchIDs as $searchID) {

    echo '<a href="/results">
    <div class="search-summary working">
        <h2 class="h1 orange left padding-left-1-4">'.$searchID->searchid.'</h2>
        <h2 class="dark-orange">'.$searchID->searchname.'</h2>
        <p>
        Status: <span class="red">In Progress</span><br>
        Date Created: 15/11/12<br>
        Keywords: 20
        </p>
    </div>
    </a>';   
}

Solutions

try this after your foreach declaration:

if(preg_match('/"([^"]+)"/', $searchID->searchname, $match))
{
    $searchName = $match;
}
else
{
    $searchName = $searchID->searchname;
}

and then change the second <h2> to:

<h2 class="dark-orange">'.$searchName.'</h2>

Ah! I needed to save the data to the table as a escaped string, instead of serialising it!

Before I was saving form data to the table using $searchname = serialize($_POST["searchname"]);

But now using $searchname = mysql_real_escape_string($_POST["searchname"]); worked a treat!

Tags: PHP / Mysql / Wordpress

Similar questions

PHP script closes unexpectedly
I have a problem: I have a wordpress website and I do the next simple action: And the problem is that server closes php script at -> and then the code becomes a simple html. Why can it be and how can I fix it?
session variable changes unexpectedly on page load in wordpress plugin
I have a problem with SESSIONs in wordpress. I have looked around but could not find any answer. A similar question has been asked in another post on stackaoverflow, but no answer yet. I have followed this tutorial to build my own FORM:build your own wordpress contact form in 5 minutes. To make my form more secure, I decided to generate a session s...
mysqld stops unexpectedly on t2.micro Amazon Linux instance
I'm running an t2.micro Amazon Linux instance on EC2. I installed LAMP and Wordpress on it. I have been experiencing many unexpected mysqld shut-downs every time I left my terminal connected to my instance via ssh before going to bed/going outside. When I woke up/came back home, mysqld always shut down itself. (And I'm not sure if this is related t...
ubuntu VM with wordpress install redirects unexpectedly ( port forwarding 80 to 8080?)
I've got an Ubuntu 14 VM running on a windows 10 host. I've installed nginx and using in my Vagrantfile I can see the default nginx page when I visit 127.0.0.1:8080 in my browser on the host machine. With that working I installed wordpress in a folder so that it would appear as http://127.0.0.1:8080/aqua/ that worked as well and the wordpress site ...
Can't open wp-admin in Safari - "server unexpectedly dropped the connection"
Hi I have installed a Wordpress theme in my MACBOOK pro successfully (after downloading MAMP & creating wordpress database of course). When i open localhost:8888/wordpress - it all looks good. I am now trying to open this link: localhost:8888/wordpress/wp-admin to be able to customise the theme. I encounter error. The error in safari says: "Saf...
Issue with MYSQL connection in Wordpress - Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
So I am having an issue with my Database lookup code: Website Here It is very odd because I am on a webhost (Godaddy) and I have confirmed nothing is wrong on their end. It was working perfectly before but then I got on to some other projects and I came back to this error. {Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.so...

Also ask

We use cookies to deliver the best possible experience on our website. By continuing to use this site, accepting or closing this box, you consent to our use of cookies. To learn more, visit our privacy policy.