0

Sorry for my bad English,
I cant retrieve record from mysql database, there's no error messages and nothing showing. The things is I want to retrieve data on a page with session using external php file. My table has data on it, I've inserted it with phpmyadmin. Here's the code :

UPDATE

I only work on php file now, and here the konek.php

<?php
error_reporting(E_ALL);
$konek=new mysqli('localhost','root','zxcvbnm','jumat') or die(mysqli_connect_error);

$selek=mysqli_query($konek,'select * from kategori');
    while($baris=mysqli_fetch_array($selek)){
        echo $baris['kodekat'].' '.$baris['namakat'];
        echo '<br>';
    }


if($konek){
    echo 'koneksi ok';
}


$konek->close();
?>

it only shows the 'koneksi ok' word, is the while not processed?

thank you in advance

13
  • 1
    Try to print a string within konek.php and see if you've included the file ok. Commented Oct 21, 2014 at 6:18
  • What is your PHP version? mysql_* is depreceted as of PHP 5.5 Commented Oct 21, 2014 at 6:20
  • Add this code at the start of your code so it will show you errors regarding your code. error_reporting(E_ALL); Commented Oct 21, 2014 at 6:22
  • i think if($i<=mysql_fetch_array($selek)) is wrong statement. remove it and then check, hope it will work. Commented Oct 21, 2014 at 6:23
  • yes, its ok, I've add if statement, then echo something, it shows, after I mark my php as comment, Commented Oct 21, 2014 at 6:24

4 Answers 4

2

What are you trying to do with this line:

if($i<=mysql_fetch_array($selek)){

If you are trying to compare with the no. of data use:

if($i<=mysql_num_rows($selek)){
Sign up to request clarification or add additional context in comments.

Comments

0

From personal experience, I had trouble with this traditional MySQL api.

I'll share this small PDO tutorial that got me over this mess, hope this helps you as much as it helped me.

http://code.tutsplus.com/tutorials/php-database-access-are-you-doing-it-correctly--net-25338

2 Comments

how to install PDO or mysqli extension for PHP on XAMPP linux?
Hi mate, you don't need to install PDO extensions. I think PHP already supports this feature. The functions are already there sorry for late reply, i am working atm
0

Try this:

<?php
$konek=mysqli_connect("localhost","root","zxcvbnm","jumat") or die(mysqli_error());
$selek=mysqli_query($konek,"select kodekat,namakat from kategori");
$i=0;
if(mysqli_num_rows($selek) > 0 ){
    while($baris = mysqli_fetch_array($selek)){
        $id = $baris["kodekat"];
        $nmk = $baris["namakat"];   

        echo"kode: ".$id."nama:".$nmk.'<br/>';
    }
}else{
    echo 'No items in database';    
}
mysqli_close($konek);
?>

Comments

0

I know the problem. Yhe problem is, my database is empty, I'm so forgetfull, :) sorry for the inconvenience, I'm sorry I'm sorry, the code is fine, all of them, :) and all of answers above, I'm sure it works, its my faults, that's my database was empty in the first place,

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.