How To Display Database on Table in PHP?

  • (2 Pages)
  • +
  • 1
  • 2

16 Replies - 2920 Views - Last Post: 19 April 2012 - 01:49 AM Rate Topic: -----

#1 syndicateapiz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 43
  • Joined: 30-January 12

How To Display Database on Table in PHP?

Posted 18 April 2012 - 11:47 PM

Hello guys..I've been troubling to compile this codes..i dont know what is wrong with it..it cant display in the table..i hope u guys can help me what is wrong with my code..

<?php
$con = mysql_connect("localhost","root","");
if (!$con)

{
die('Could Not Connect: '. mysql_error());

// This block grabs the whole list for viewing
$bilboard_list = "";
$bilboard_list0 = "";
$bilboard_list1 = "";
$bilboard_list2 = "";
$sql = mysql_query("SELECT * FROM database ORDER BY Operator");
$bilboardCount = mysql_num_rows($sql); // count the output amount
if ($bilboardCount > 0) {
while($row = mysql_fetch_array($sql)){ 
$Operator = $row["Operator"];
$Nama_Pemilik = $row["Nama_Pemilik"];
$Lokasi = $row["Lokasi"];
$Jenis_Iklan = $row["Jenis_Iklan"];
//for show
$bilboard_list .= "$Nama_Pemilik<br>";
$bilboard_list0 .= "$Lokasi<br>";
$bilboard_list1 .= "$Jenis_Iklan<br>";
$bilboard_list2 .= "$Operator<br>";

?>
<html>
<head>
</head>

<body>
<table width="686" border="1">
      <tr>
<td width="69"><strong>NAMA PEMILIK</strong></td>
        <td width="111"><strong>LOKASI </strong></td>
        <td width="93"><strong>JENIS IKLAN</strong></td>
        <td width="121"><strong>OPERATOR</strong></td>
      </tr>
      <tr>
<td><?php echo $bilboard_list; ?></td>
        <td><?php echo $bilboard_list0; ?></td>
        <td><?php echo $bilboard_list1; ?></td>
        <td><?php echo $bilboard_list2; ?></td>
        </tr>
    </table>
<body>
</html>



Is This A Good Question/Topic? 0
  • +

Replies To: How To Display Database on Table in PHP?

#2 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3390
  • View blog
  • Posts: 9,586
  • Joined: 08-June 10

Re: How To Display Database on Table in PHP?

Posted 18 April 2012 - 11:54 PM

thatís due to the syntax errors (youíre actually missing all closing braces)
Was This Post Helpful? 0
  • +
  • -

#3 syndicateapiz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 43
  • Joined: 30-January 12

Re: How To Display Database on Table in PHP?

Posted 18 April 2012 - 11:56 PM

all? what do mean by all? can u show me?
Was This Post Helpful? 0
  • +
  • -

#4 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3390
  • View blog
  • Posts: 9,586
  • Joined: 08-June 10

Re: How To Display Database on Table in PHP?

Posted 19 April 2012 - 12:00 AM

every { needs a } to properly enclose a statement block.

add before line #2: error_reporting(-1); ini_set("display_errors", true);

This post has been edited by Dormilich: 19 April 2012 - 12:02 AM

Was This Post Helpful? 0
  • +
  • -

#5 Macjohn  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 80
  • View blog
  • Posts: 407
  • Joined: 10-April 09

Re: How To Display Database on Table in PHP?

Posted 19 April 2012 - 12:03 AM

it means that when you do something like this:

if (myValue != 0){
//code
//code
//code

/you have to have
}
at the end.

when you open them, you got to close them.
Was This Post Helpful? 0
  • +
  • -

#6 syndicateapiz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 43
  • Joined: 30-January 12

Re: How To Display Database on Table in PHP?

Posted 19 April 2012 - 12:10 AM

it still the same..cant display it..the output will become like this

0) { while($row = mysql_fetch_array($sql)){ $Operator = $row["Operator"]; $Nama_Pemilik = $row["Nama_Pemilik"]; $Lokasi = $row["Lokasi"]; $Jenis_Iklan = $row["Jenis_Iklan"]; //for show $bilboard_list .= "$Nama_Pemilik
"; $bilboard_list0 .= "$Lokasi
"; $bilboard_list1 .= "$Jenis_Iklan
"; $bilboard_list2 .= "$Operator
"; } } ?>

and some table will appear..
Was This Post Helpful? 0
  • +
  • -

#7 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3390
  • View blog
  • Posts: 9,586
  • Joined: 08-June 10

Re: How To Display Database on Table in PHP?

Posted 19 April 2012 - 12:56 AM

how do you call that file in the browser?
Was This Post Helpful? 0
  • +
  • -

#8 syndicateapiz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 43
  • Joined: 30-January 12

Re: How To Display Database on Table in PHP?

Posted 19 April 2012 - 12:59 AM

i dont know..i'm just following the instruction on someoen tutorial..can u teach me how can i show all the database on the browser?
Was This Post Helpful? 0
  • +
  • -

#9 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3390
  • View blog
  • Posts: 9,586
  • Joined: 08-June 10

Re: How To Display Database on Table in PHP?

Posted 19 April 2012 - 01:02 AM

what do you mean, you donít know how you call the file? if you have output (and I assume you got that output in a browser), all I want to know whatís displayed in the browserís address bar.


Quote

can u teach me how can i show all the database on the browser?

thatís what Iím trying to do.
Was This Post Helpful? 0
  • +
  • -

#10 syndicateapiz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 43
  • Joined: 30-January 12

Re: How To Display Database on Table in PHP?

Posted 19 April 2012 - 01:06 AM

ok its like this

i'm using a WAMP..this is for my system that i'm developing right now..i want to call the data from the database in phpmyadmin..i cant figure it out how to display it because i've tried to many attemp with different method by referring to someone else blog or website but it didnt work

u ask for a path at the address bar..this is what appear on the address

file:///C:/wamp/www/bilboard/test2.php
Was This Post Helpful? 0
  • +
  • -

#11 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3390
  • View blog
  • Posts: 9,586
  • Joined: 08-June 10

Re: How To Display Database on Table in PHP?

Posted 19 April 2012 - 01:10 AM

no wonder nothing happened.

PHP is a server side language. that means, you need to process it through the server and you only do that when you call the server and the server usually is called via IP or DNS. in your case that would be http://localhost/

if you just open the file in the browser, only the HTML processor sees this file, which is not associated with PHP in any way and hence cannot process your PHP code.
Was This Post Helpful? 0
  • +
  • -

#12 syndicateapiz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 43
  • Joined: 30-January 12

Re: How To Display Database on Table in PHP?

Posted 19 April 2012 - 01:18 AM

ahhhh...i see..i get it now..well i change the path to this

localhost/bilboard/test2.php

but i still get the error said

( ! ) Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\wamp\www\bilboard\test2.php on line 14

and a table called "CALL STACK" with table Time, Memory, Function, Location..
Was This Post Helpful? 0
  • +
  • -

#13 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3390
  • View blog
  • Posts: 9,586
  • Joined: 08-June 10

Re: How To Display Database on Table in PHP?

Posted 19 April 2012 - 01:19 AM

that means that your query failed.

you can get the SQL error message with mysql_error().
Was This Post Helpful? 0
  • +
  • -

#14 syndicateapiz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 43
  • Joined: 30-January 12

Re: How To Display Database on Table in PHP?

Posted 19 April 2012 - 01:27 AM

ahhh..i see..i will to figure it out if i got any problem,i will tell u ok..thanks for ur help Dormilich..nice to meet u..=)
Was This Post Helpful? 0
  • +
  • -

#15 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3390
  • View blog
  • Posts: 9,586
  • Joined: 08-June 10

Re: How To Display Database on Table in PHP?

Posted 19 April 2012 - 01:29 AM

one more recommendation, since youíre starting with PHP, donít use the old and outdated mysql extension. use PDO or MySQLi (itís not named mysql-improved for no reason)
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2