Jump to content

[SOLVED] Listing / mysql


rugzo

Recommended Posts

Hi all,

 

I am new in the forum and also a beginner in php section. I am trying to do a simply listing in a php page. There is a simply table in mysql and the values in there should be listed in the page.

The code -->

<html>

<head>

<meta http-equiv="content-language" content="tr">

<meta http-equiv="content-type" type="text/html; charset=windows-1254">

</head>

<body>

 

<table border="1" bordercolor="#90022e">

<tr>

<td width="16%"><font face="Arial Black" size="2">Adı</font></td>

<td width="16%"><font face="Arial Black" size="2">Soyadı</font></td>

<td width="17%"><font face="Arial Black" size="2">Kullanıcı Adı</font></td>

<td width="13%"><font face="Arial Black" size="2">Şifre</font></td>

<td width="21%"><font face="Arial Black" size="2">email</font></td>

<td width="17%"><font face="Arial Black" size="2">Görüş</font></td>

</tr>

 

<?php

 

@mysql_connect ("localhost","root","123") or die ("nix sql") ;

 

@mysql_select_db ("uye") or die ("nix db") ;

 

$sql = mysql_query ("SELECT * FROM uyeler") ;

 

while ($liste = mysql_fetch_array($sql)) {

 

?>

 

<tr>

  <td width="%16"><font face="verdana" size="2"><? echo "$liste(0)"; ?></font></td>

  <td width="%16"><font face="verdana" size="2"><? echo "$liste(1)"; ?></font></td>

  <td width="%17"><font face="verdana" size="2"><? echo "$liste(2)"; ?></font></td>

  <td width="%13"><font face="verdana" size="2"><? echo "$liste(3)"; ?></font></td>

  <td width="%21"><font face="verdana" size="2"><? echo "$liste(4)"; ?></font></td>

  <td width="%17"><font face="verdana" size="2"><? echo "$liste(5)"; ?></font></td>

</tr>

 

<?

 

}

 

?>

</table>

</body>

</html>

 

But when i call the page i can see the table and the row numbers are also right but it look like ->

 

Adı          Soyadı  Kullanıcı Adı  Şifre  email  Görüş

Array(0) Array(1) Array(2) Array(3) Array(4) Array(5)

Array(0) Array(1) Array(2) Array(3) Array(4) Array(5)

Array(0) Array(1) Array(2) Array(3) Array(4) Array(5)

Array(0) Array(1) Array(2) Array(3) Array(4) Array(5)

Array(0) Array(1) Array(2) Array(3) Array(4) Array(5)

 

the first line is ok. but the values are not listed instead of the names you just see "array(0)...

 

Can anyone help me. Where is my mistake. I am following the exact instructions of my php book.

 

Thanks very much...

Link to comment
Share on other sites

try this:

<html>
<head>
<meta http-equiv="content-language" content="tr">
<meta http-equiv="content-type" type="text/html; charset=windows-1254">
</head>
<body>

<table border="1" bordercolor="#90022e">
<tr>
<td width="16%"><font face="Arial Black" size="2">Adı</font></td>
<td width="16%"><font face="Arial Black" size="2">Soyadı</font></td>
<td width="17%"><font face="Arial Black" size="2">Kullanıcı Adı</font></td>
<td width="13%"><font face="Arial Black" size="2">Şifre</font></td>
<td width="21%"><font face="Arial Black" size="2">email</font></td>
<td width="17%"><font face="Arial Black" size="2">Görüş</font></td>
</tr>

<?php

@mysql_connect ("localhost","root","123") or die ("nix sql") ;

@mysql_select_db ("uye") or die ("nix db") ;

$sql = mysql_query ("SELECT * FROM uyeler") ;
while ($liste = mysql_fetch_assoc($sql)) {
$liste0 = $liste[0];
$liste1 = $liste[1];
$liste2 = $liste[2];
$liste3 = $liste[3];
$liste4 = $liste[4];
$liste5 = $liste[5];
echo <<<END
<tr>
  <td width="%16"><font face="verdana" size="2">$liste0</font></td>
  <td width="%16"><font face="verdana" size="2">$liste1</font></td>
  <td width="%17"><font face="verdana" size="2">$liste2</font></td>
  <td width="%13"><font face="verdana" size="2">$liste3</font></td>
  <td width="%21"><font face="verdana" size="2">$liste4</font></td>
  <td width="%17"><font face="verdana" size="2">$liste5</font></td>
</tr>
END;
}
?>
</table>
</body>
</html>

Link to comment
Share on other sites

Does this help?

 

<tr>
  <td width="%16"><font face="verdana" size="2"><?php echo $liste[0]; ?></font></td>
  <td width="%16"><font face="verdana" size="2"><?php echo $liste[1]; ?></font></td>
  <td width="%17"><font face="verdana" size="2"><?php echo $liste[2]; ?></font></td>
  <td width="%13"><font face="verdana" size="2"><?php echo $liste[3]; ?></font></td>
  <td width="%21"><font face="verdana" size="2"><?php echo $liste[4]; ?></font></td>
  <td width="%17"><font face="verdana" size="2"><?php echo $liste[5]; ?></font></td>
</tr>

Link to comment
Share on other sites

Hell rugzo:

 

Give this a try:

 

<?php
// Create database connection.
@ mysql_connect ("localhost","root","123") or die ("nix sql") ;
@ mysql_select_db ("uye") or die ("nix db") ;

$sql = "SELECT * FROM uyeler";
$result = mysql_query($sql) or die(mysql_error());

?>
<table>
    <tr>
        <th>Adı</th>
        <th>Soyadı</th>
        <th>Kullanıcı Adı</th>
        <th>Şifre</th>
        <th>email</th>
        <th>Görüş</th>
    </tr>
   <?php
        while ($liste = mysql_fetch_array($result)) {
   ?>
   <tr>
      	<td><?php echo $liste[Adı]; ?></td>
        <td><?php echo $liste[soyadı]; ?></td>
        <td><?php echo $liste[KullanıcıAdı]; ?></td>
        <td><?php echo $liste[Şifre]; ?></td>
        <td><?php echo $liste[email]; ?></td>
        <td><?php echo $liste[Görüş]; ?></td>
    </tr>
    <?php }
        mysql_free_result($result);
    ?>
</table>

Link to comment
Share on other sites

Thanks for the reply but the result is -> Parse error: syntax error, unexpected ';' in C:\xampp\htdocs\t.php on line 23

 

I am also trying to understand why the example from my php book isn't working. It creates the table but list all values as array()...

Can the reason be the version of php i am using 5.2.5 or maybe the version of mysql...

Or can it be that i have to make a configuration in php.ini...

 

I am really lost  ???

Link to comment
Share on other sites

Its because you were using parenthesis on your array elements when they should be square brackets.

 

Wrong:

<? echo "$liste(0)"; ?>

 

Right:

<?php echo $liste[0]; ?>

 

You shouldnt need quotes around your array element.

Also, its bad practice to use php short tags (<?), use the full tag (<?php)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.