Page 1 of 1

PHP and MySql

Posted: Thu Jul 22, 2004 5:02 pm
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**

Posted: Thu Jul 22, 2004 5:04 pm
by feyd

Code: Select all

while($row = mysql_fetch_assoc($result))
{
  extract($row);
  // your row echo here
}

Posted: Sun Jul 25, 2004 2:01 pm
by SidewinderX
what do you mean by:

// your row echo here

Posted: Sun Jul 25, 2004 4:31 pm
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);

Posted: Sun Jul 25, 2004 4:57 pm
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>
";