zero-perfoliate
zero-perfoliate

Author Topic: Database Query Output  (Read 282 times)

Offline silvermoondragon

  • PHP Workers
  • **
  • Posts: 7
  • Karma: +0/-0
Database Query Output
« on: May 21, 2010, 11:58:51 AM »
I was working on a basic results display query of a database but I can only get one result to be displayed when I want it to display them all(there are currently 3 records). Any help would be greatly appreciated.

Here is my code:

Code: [Select]
<?php // query.php
require_once 'login.php';
$db_server mysql_connect($db_hostname$db_username$db_password);

if (!
$db_server) die("Unable to connect to MySQL: " mysql_error());

mysql_select_db($db_database)
or die("Unable to select database: " mysql_error());

$query "SELECT *
These two lines of codes(above and below) are joined, but for some reason the word "F R O M" in the middle was causing an error with posting... I can't even post it here without the spaces... weird.
Code: [Select]
gryphines";

$result = mysql_query($query);

if (!$result) die ("Database access failed: " . mysql_error());

$rows = mysql_num_rows($result);

for ($j = 0 ; $j < $rows ; ++$j);
{
$row = mysql_fetch_row($result);
echo 'ID: ' . $row[0] . '<br />';
echo 'Name: ' . $row[1] . '<br />';
echo 'Owner: ' . $row[2] . '<br />';
echo 'Gender: ' . $row[3] . '<br />';
echo 'Species: ' . $row[4] . '<br />';
echo 'Traits: ' . $row[5] . '<br />';
echo 'Colours: ' . $row[6] . '<br />';
echo 'Mother: ' . $row[7] . '<br />';
echo 'Father: ' . $row[8] . '<br />';
echo 'Children: ' . $row[9] . '<br />';
echo 'Pack: ' . $row[10] . '<br />';
echo 'Other: ' . $row[11] . '<br />';
echo 'Image: ' . $row[12] . '<br /><br />';
}
mysql_close($db_server);
?>

Offline Sergey Popov

  • PHP Helpers
  • ***
  • Posts: 31
  • Karma: +0/-0
    • Freelance PHP Developer
Re: Database Query Output
« Reply #1 on: May 25, 2010, 09:42:46 AM »
Your code seem to be fine, if there are 3 records - they all should be displayed by this code.
Refer to php documentation or PHP Help forum for more info and for answers to your questions

Offline silvermoondragon

  • PHP Workers
  • **
  • Posts: 7
  • Karma: +0/-0
Re: Database Query Output
« Reply #2 on: May 25, 2010, 05:52:56 PM »
But only the first record is displayed when I test it. Could it be a problem with the database? I am using XAMPP and testing it virtually on my own computer.

 

zero-perfoliate