2

This is my full page code:

<?php


$servername = "localhost";
$username = "root";
$password = "null";
$dbname = "logs";

$conn = new mysqli($servername, $username, $password, $dbname);

if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
} 


$result = mysql_query("SELECT * FROM 'd82Kap3'");
$row = mysql_fetch_array($result);
echo $row['ip'];

?>

This is my table structure: http://prntscr.com/7we7ck

I am trying to make it echo all the records in the field "ip".

Mads Hansen
  • 63,927
  • 12
  • 112
  • 147
user3724476
  • 4,720
  • 3
  • 15
  • 20
  • And the the problem is ? What is your actual output ? – Random Jul 24 '15 at 09:31
  • I highly advice you read up on [Why you **really** shouldn't use `mysql_` and `mysqli_` extensions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php) *Please* refer to the [PDO manual](http://php.net/manual/en/book.pdo.php) instead. – Vanitas Jul 24 '15 at 09:34
  • the sql looks wrong - use backticks around the table name rather than single quotes – Professor Abronsius Jul 24 '15 at 09:39
  • `SELECT ip FROM d82Kap3`. Yw – Alfwed Jul 24 '15 at 10:08

3 Answers3

2

Use while loop for it.

Example

$result = mysql_query("SELECT * FROM 'd82Kap3'");
while($row = mysql_fetch_array($result))
{
     echo $row['ip']."<br />";
}

Note

mysql extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQL extension should be used.

Update

<?php

$servername = "localhost";
$username = "root";
$password = "null";
$dbname = "logs";

$conn = new mysqli($servername, $username, $password, $dbname);

if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
} 


$result = $conn->query("SELECT * FROM `d82Kap3`");

while($row = $result->fetch_array())
{
     echo $row['ip']."<br />";
}

?>
Muhammad Hassaan
  • 7,296
  • 6
  • 30
  • 50
0

Dont mix mysql and mysqli

<?php


$servername = "localhost";
$username = "root";
$password = "null";
$dbname = "logs";

$conn = new mysqli($servername, $username, $password, $dbname);

if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
} 


$result = $conn->query("SELECT * FROM d82Kap3");
while($row = $result->fetch_assoc())
echo $row['ip'];

?>
Dhinju Divakaran
  • 893
  • 1
  • 8
  • 11
0

Use following code:

$result = mysql_query("SELECT * FROM 'd82Kap3'");
while($row = mysql_fetch_array($result))    
{
 echo $row['ip'];
}
Sagar
  • 642
  • 3
  • 14
  • Does not work. I will update my post with the full page code. – user3724476 Jul 24 '15 at 09:38
  • remove single quotes from table name. mysql_query("SELECT * FROM d82Kap3"); And use function mysql_fetch_assoc instead of mysql_fetch_array. – Sagar Jul 24 '15 at 09:48