lukeseager
lukeseager

Reputation: 2615

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>';   
}

Upvotes: 0

Views: 41

Answers (2)

pulsar
pulsar

Reputation: 985

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>

Upvotes: 0

lukeseager
lukeseager

Reputation: 2615

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!

Upvotes: 1

Related Questions