Data into a table

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Ducca
Forum Newbie
Posts: 5
Joined: Thu Apr 15, 2004 8:08 pm

Data into a table

Post by Ducca »

I,ve written a small script that outputs the data from a database, this is then output into a webpage,
I,m trying to put the data into a table ,but can,t suss it, very new to php
can anyone help
thanks in advance
Ducca

Code: Select all

<HTML>
<HEAD>
<LINK REL=stylesheet TYPE="text/css" HREF="wmd.css">
<HTML>
<HEAD>
<LINK REL=stylesheet TYPE="text/css" HREF="wmd.css">
<TITLE>Inserting Data into a Database</TITLE>
</HEAD>
<BODY><center>

<?php
/* This page receives and handles the data generated by "savedata.html". */
// incoming data.

$auctionId = $_POST&#1111;"auctionId"];
$title = $_POST&#1111;"title"];
$userId = $_POST&#1111;"userId"];
$itemDesc = $_POST&#1111;"itemDesc"];
$image = $_POST&#1111;"image"];
$startPrice = $_POST&#1111;"startPrice"];
$startDate = $_POST&#1111;"startDate"];
$expiresDate = $_POST&#1111;"expiresDate"];

// Set the variables for the database access:

$host="localhost";
$user="Paul";
$password="";
$database = "auction";
$TableName = "auctiondata";



$connection = mysql_connect($host,$user,$password)
or die ("couldn't connect to server");

$db = mysql_select_db($database,$connection)
or die ("Couldn't select database");

$Query = "INSERT into $TableName (auctionId,title,userId,itemDesc,image,startPrice,startDate,expiresDate)
values ('$auctionId','$title','$userId','$itemDesc',
'$image','$startPrice','$startDate','$expiresDate')";



//print ("The query is:<BR>$Query<P>\n");

if (mysql_db_query ($database, $Query, $connection)) 

&#123;
print ("Your Item was succsessfully added to auction!<BR>\n");
 
&#125; 
else 
&#123; 
print ("sorry !! try again Remember auction Id<BR>\n");
&#125;

/*mysql_close ($connection);*/
 $query = "SELECT * FROM auctionData";
  $result = mysql_query($query)
       or die ("Couldn't execute query.");

  /* Display results in a table */
  echo "<center><h1>auctions</h1></center>";
  echo "<table cellspacing='25'>";

  echo "<tr><td colspan='8'><hr></td></tr>";
  while ($row = mysql_fetch_array($result))
  &#123;
     extract($row);
     
 $datastring = $auctionId."\n".$title."\n".$userId."\n".$itemDesc."\n".$image."\n".$startPrice.
"\n".$startDate."\n".$expiresDate."\n";

      echo "<tr>\n

           <td>$datastring </td>\n
           
           </tr>\n";
    // echo "<tr><td colspan='3'><hr></td></tr>\n";
  &#125;
  echo "</table>\n";

?></center>
</BODY>
</HTML>
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

What's the problem exactly?
Ducca
Forum Newbie
Posts: 5
Joined: Thu Apr 15, 2004 8:08 pm

Post by Ducca »

the output is eg;
1 Bike Paul Red 50 2004-04-10 2004-10-04

I,m trying to put it in a table so i can give it the appropriate headers so anyone viewing the data can understand exactly what it is

Id || item || name || desc || price || startdate || end date

1 || Bike || Paul || Red || 50 || 2004-04-10 || 2004-10-04

Thanks for your help
Ducca
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Ah, ok. I think you're after something along the lines of:

Code: Select all

echo "<tr><td colspan='8'><hr></td></tr>";
while ($row = mysql_fetch_array($result))
{
    extract($row);
    echo "<tr>\n
    <td>$auctionId</td>\n
    <td>$title</td>\n
    <td>$userId</td>\n
    <td>$itemDesc</td>\n
    <td>$image</td>\n
    <td>$startPrice</td>\n
    </tr>\n";
 }
echo "</table>\n";
Post Reply