Click here to Skip to main content
15,884,629 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Focusing on this lines:
SQL
$qString = $gConnection->prepare("SELECT ? FROM `accounts` WHERE `Username` = ?"); $qString->bind_param('ss', $gConnection->real_escape_string($TableC), $gConnection->real_escape_string($UsernameC));

$qResult = $qString->execute();


After the execute, I'm searching for the function that will withdraw the data from the column and the column name and if it exists. ((exists part should be PHP))

What function that will work with the mysqli statment and be able to retrive data from column's and function that will check if the column exists.

(( This script is used on PHP ))
Posted

1 solution

It's late and I'm tired. Hope you'll forgive me if my explanation isn't so good.

As far as I know, you cant do it all in one go - I've used the following function in the past when wanting to display a table in the same way that phpMyAdmin does - i.e with each column name shown above it's data.

Basically, it's one sql statement to get the column names, followed by another to get the data.
Add the two together and presto!

Just substitute mysqli for pdo - its really just the sql and php you need. At least with pdo, you cant use place-holders for table or column names. It may be different with the mysqli extension - I don't know.

PHP
function displayTable($tblName)
{
    global $pdo;
    $colNames = array();

    $query = $pdo->prepare("show columns from $tblName");
    $query->execute();
    while ($result = $query->fetch())
    {
        $colNames[] = $result[0];
    }

    echo "<table cellspacing='0'>";
        echo "<tbody>";
            echo "<tr>";
                foreach($colNames as $curName)
                {
                    echo "<th>" . $curName . "</th>";
                }
            echo "</tr>";

            $query = $pdo->prepare("select * from $tblName");
            $query->execute();
            $rowNum = 0;
            while ($result = $query->fetch())
            {
                if ($rowNum % 2)
                    printf("<tr class='odd'>");
                else
                    printf("<tr class='even'>");
                for ($i=0; $i<count($colNames); $i++)
                    printf("<td>%s</td>", $result[$i]);
                printf("</tr>");
                $rowNum++;
            }
        echo "</tbody>";
    echo "</table>";
}
 
Share this answer
 
Comments
NextGenDeveloper 16-Apr-13 13:20pm    
Tried it, it didn't return anything in the echo, printf.
PDO is the same as MySQLi, I rather be with MySQLi for now.
And yes, I have changed the sql query to my table name and stuff.
enhzflep 16-Apr-13 13:37pm    
Okay, then in that case, I suggest you follow the directions set out here: www.sscce.org/
Namely, post a minimal example of the code you're working with, that only serves to eliminate ambiguity and get you a solution faster and with less effort.

No idea what the problem with your code is without that..

Also, and off-topic, PDO is better than MySqli in that it supports 12 different database drivers (18 databases!). MySqli only supports 1 - mysql. See here for a more detailed comparison: pdo vs mysqli

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900