PHP and MySql

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
SidewinderX
Forum Contributor
Posts: 407
Joined: Fri Jul 16, 2004 9:04 pm
Location: NY

PHP and MySql

Post by SidewinderX »

Hey, im new to PHP let alone MySQL

Though some reading I managed to build a database called 'games' with I guess you would call it a table called 'gamesinfo' and in that table I created 7 i guess you would call them rows. These rows are:
id
gameName
pubPrice
prvPrice
tsPrice
minPlayer
maxPlayer
I want to design a script to put all the info thats in the rows gameName, pubPrice and prvPrice into a table.

This is as far as I got

Code: Select all

<?php
$db = mysql_connect("localhost", "", "");
mysql_select_db("games",$db);
$result = mysql_query("SELECT * FROM gamesinfo ORDER BY gameName",$db);
Now to build the table

Code: Select all

echo "<table border=1 align="center" width="75%">"; 

echo "
<tr>
<th>Game Name</th>
<th>Private Price</th>
<th>Public Price</th>
<th>Order</th>
</tr>
";

echo "
<tr>
<td>$gameName</td>
<td>$pubPrice</td>
<td>$prvPrice</td>
<td>Order</td>
</tr>
";
?>
My qyestion is how do I populate the table with the information from my db using the variables in the table ($gameName, $pubPrice, $prvPrice) or others if need be

**Edited by infolock : Moved to database forums**
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

while($row = mysql_fetch_assoc($result))
{
  extract($row);
  // your row echo here
}
SidewinderX
Forum Contributor
Posts: 407
Joined: Fri Jul 16, 2004 9:04 pm
Location: NY

Post by SidewinderX »

what do you mean by:

// your row echo here
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

Code: Select all

require_once('[url]http://home.mysth.be/~timvw/programming/php/result2table.txt[/url]');

$db = mysql_connect("localhost", "", "");
mysql_select_db("games",$db);
$query = 'SELECT gameName as `Game Name`, prvPrice as `Private Prive`, pubPrice as `Public Price` FROM gamesinfo ORDER BY gameName";
$result = mysql_query($query) or die(mysql_error());

listresult($result);
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

SidewinderX wrote:what do you mean by:

// your row echo here

Code: Select all

echo "
<tr>
<td>$gameName</td>
<td>$pubPrice</td>
<td>$prvPrice</td>
<td>Order</td>
</tr>
";
Post Reply