Jump to content

Recommended Posts

Hi all!

I'm migrating my site from .asp to php, which is interesting since I'm a noob to php. Things have been going ok, but now I'm stumped. All my data for the site is in a mysql database. I can connect to the database, but can not get the data to display on my pages. The problem is when i try to repeat the rows of the table to show all items. There is something with the $i=0 part, but can't figure it out. Following is the code:

 

<?php

require_once('connection.php');

 

mysql_connect($dbhost, $dbuser, $dbpassword);

mysql_select_db($dbname) or die("PHAIL");

 

$query = "SELECT * FROM bigcardtable WHERE category='GameUsed' ORDER BY 'PlayerName';";

 

$results = mysql_query($query);

echo mysql_error();

$array = mysql_fetch_array($results);

$num_Rows = mysql_num_rows($results);

 

$i=0;

while($i <= num_Rows ) {

$row = $array[$i];

echo '<table width="100%" border="1">';

echo '  <tr>';

echo '    <td rowspan="6"><img src="' . $row['ImagePath'] . '" /></td>';

echo '    <td>Player Name</td>';

echo '    <td>' . $row['PlayerName'] . '</td>';

echo '  </tr>';

echo '  <tr>';

echo '    <td>Card Description</td>';

echo '    <td>' . $row['CardDescription'] . '</td>';

echo '  </tr>';

echo '  <tr>';

echo '    <td>Serial Number</td>';

echo '    <td>' . $row['SerialNumber'] . '</td>';

echo '  </tr>';

echo '  <tr>';

echo '    <td>Price</td>';

echo '    <td>' . $row['Price'] . '</td>';

echo '  </tr>';

echo '  <tr>';

echo '    <td>Purchase</td>';

echo '    <td> </td>';

echo '  </tr>';

echo '  <tr>';

echo '    <td colspan="2"> </td>';

echo '  </tr>';

echo '</table>';

$i++;

}

?>

 

I hope I have provided enough information for people. Any help would be appreciated!

Thanks in advance.

Clint

Link to comment
https://forums.phpfreaks.com/topic/141028-solved-display-mysql-data-in-a-table/
Share on other sites

corbin is exactly correct here.  For the sake of clarity I use

 

while($row = mysql_fetch_array($results)) {


}

 

This way you can get rid of the  $row = $array[$i]; line totally and not change the rest of your variable names. You can lose $i = 0; too.  You don't need an accumulator here because this usage will continue the while loop until there are no more rows.

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.