0

I am attempting to get data from a mysql database. This is the code that I have so far:

include 'sqlConnection.php';
$strSQL = "SELECT * FROM PrimeSelectScan";
$rs = $sqlTableConnection->query($strSQL);
if ($sqlTableConnection->query($rs) === TRUE) {
    echo "Record updated successfully";
} else {
    echo "Error updating record: " . $sqlTableConnection->error;
} 
while($row = mysqli_fetch_array($rs)) 
{
    echo "\t<tr><td>".$row['id']."</td><td>".$row['cost']."</td><td>".$row['roi']."</td></tr>\n";
}
$sqlTableConnection->close();

The sqlConnection.php file is just the connection to the database. I am not exactly sure if I am correct or not. If someone could help me out and lead me in the right direction, I would really appreciate it. This is the first time I have attempted to get information like this. Thanks in advance.

Teddy Codes
  • 489
  • 4
  • 14

2 Answers2

1

First of all your heading says get table names for output so I am answering that. However, it doesn't look like that's what you're trying to do in your code

.... If getting table names IS what you want.. You can use

$sql = "SHOW TABLES FROM $dbname";

Then loop through:

while ($row = mysql_fetch_row($result)) {
    echo "<a> tag and <tr><td> stuff" . $row[0] . "end </td></tr> stuff";
}
Zak
  • 6,976
  • 2
  • 26
  • 48
1

Are you getting any error messages?

Here is an example for a mysqli query:

$mysqli = new mysqli("localhost", "user", "pass", "db");
$query  = "SHOW TABLES FROM primeselectscan";
$result = $mysqli->query($query);

header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=FILE-NAME-HERE.txt");
header("Pragma: no-cache");
header("Expires: 0");

while($row = $result->fetch_array()) {
    echo "\t<tr><td>".$row['Tables_in_primeselectscan']."</td><td>\n";
}

$mysqli->close();

If you are wanting the actual table names within the database then you need to change your query to use 'SHOW TABLES FROM dbName'. See http://dev.mysql.com/doc/refman/5.7/en/show-tables.html for details.

To have it output as an actual download add the following headers before you output anything, I added that to the code section above.

MajicBob
  • 487
  • 2
  • 8