Forum Moderators: coopster
I have been working with Flash and PHP for a lil while but I've got a bigger project of my own to do.
Basically, I want to have a form, which will submit data to mysql, then I would like to be able to go online to a specific page and view the results in a table.
Like -
date ----- ¦---- name ----- ¦ ------ email -----------¦
10.12.03 ------- Mrs.Warm ---- marm@warmer.com -----
11.12.03 ------- mr.duck ------ duck@duckover.com ----
Results like that then you be able to click on one of the rows and show all the results submitted from the user, not just date, name, email...everything from the form they submitted, in a decent viewable layout so it can be printable.
I hope people can help and guide me along this journey ;)
Thank you ever so much
What you should do is design a static HTML page and then work the MySQL and PHP code functionality around that.
Structure your results in a table, then just use a for loop to get the data from the database. Something like:
$query = "SELECT * FROM table";
$result = mysql_query($query);<div align="center"><center>
<table border="0" width="80%">
<tr>
<td align="center" width="33%">Date</td>
<td align="center" width="34%">Name</td>
<td align="center" width="33%">E-Mail</td>
</tr><?
for ($i=0; $i<$row = mysql_fetch_array($result); $i++)
{
<tr>
<td>$row[date]</td>
<td>$row[name]</td>
<td>$row[email]</td>
</tr>}
?>
</table>
</center></div>
I doubt anyone here will have time to design the whole thing for you as they probably won`t have time. No fun in learning if someone else is doing it for you anyway I don`t think.
Hope that helps in some way. :)
The system Im making is basically storing information from a form to the database then I want to show all descriptions like above then that row of the table would link to the full data of the selected. Which will be set out readable and be bale to print.
How would I link, for each row to show the information? and how could I create a function so that I could print a selected amount of the data? Say I clicked on the first link, it would open a page with tha information in it, then I could print it, but what about if I wanted to print say all or even 10 selections at al time?
Thanks immensely!
When you store the info, its best to give each row a unique id number. ie:
id int(4) NOT NULL auto_increment,
Then when you pull all the data from the row, you`ll also pull that unique id number. So taking the original table I did, you would do:
$query = "SELECT * FROM table";
$result = mysql_query($query);<div align="center"><center>
<table border="0" width="80%">
<tr>
<td align="center" width="25%">ID</td>
<td align="center" width="25%">Date</td>
<td align="center" width="25%">Name</td>
<td align="center" width="25%">E-Mail</td>
</tr><?
for ($i=0; $i<$row = mysql_fetch_array($result); $i++)
{
<tr>
<td>$row[id]</td>
<td>$row[date]</td>
<td>$row[name]</td>
<td>$row[email]</td>
</tr>}
?>
</table>
</center></div>
To then get the info unique to that id, you could just add a url with a query string, for example:
<td><a href="print.php?id=$row[id]">$row[id]</a></td>
Then on your print page, you would do something like:
if (isset($id))
{
$query = "SELECT * FROM table WHERE id = '$id'";
$result = mysql_query($query);...here again display the info for that link as above
}
Say I clicked on the first link, it would open a page with tha information in it, then I could print it, but what about if I wanted to print say all or even 10 selections at al time?
If you want to select a certain amount of entries, you would use the LIMIT clause.
Firstly create a function called say printALL(); This displays a specified amount of entries when its loaded.
Inside this function you would use the limit clause:
$query = "SELECT * FROM table LIMIT 0,10";
$result = mysql_query($query);
Change the limit to whatever you want. You can also order it by something. ie:
$query = "SELECT * FROM table ORDER by id LIMIT 0,10";
$result = mysql_query($query);
This would print the first 10 entries ordered by id.
On your page with the database info, you would do a URL again with a query string, something like:
print.php?action=printall
Then on your print page, load the function:
if ($_GET['action'] =="printall) { printAll(); }
Is this making any sense? I should be doing something more with my Saturday nights. LOL!
When you create your print page, make sure its just black and white, ie, printer friendly.
Hope that helps!
:)
[edited by: dreamcatcher at 10:39 pm (utc) on Nov. 15, 2003]
I should be doing something more with my Saturday nights. LOL!
>>How would I link, for each row to show the information?
Basically, as you are looping through the data to display on this first screen, you simply add your links. Let's say you wanted the link to be on the name. Then in the line of the for loop specifying the name, add your <a href> to the variable and direct it to your next page. That page would be a PHP receiving page that would grab the variables from the GET query string and once again access the database to retrieve the information you wish to format and display.
>> and how could I create a function so that I could print a selected amount of the data? Say I clicked on the first link, it would open a page with tha information in it, then I could print it, but what about if I wanted to print say all or even 10 selections at al time?
Do you mean ten items from the list on your first page? Or ten rows of information regarding the clicked link on that first page? Either way, you would simply change the SQL SELECT statement to retrieve the result set of information you want to loop through to format and display.
DROP TABLE IF EXISTS mortgage;
CREATE TABLE mortgage (
ID int(4) NOT NULL auto_increment,
FirstName mediumtext NOT NULL,
SurName mediumtext NOT NULL,
Email mediumtext NOT NULL,
Telephone mediumtext NOT NULL,
Mobile mediumtext NOT NULL,
Address mediumtext NOT NULL,
Town mediumtext NOT NULL,
PostCode mediumtext NOT NULL,
EmploymentStatus mediumtext NOT NULL,
Occupation mediumtext NOT NULL,
ApplicantOneIncome mediumtext NOT NULL,
ApplicantTwoIncome mediumtext NOT NULL,
CurrentHome mediumtext NOT NULL,
PurchasePrice mediumtext NOT NULL,
Deposit mediumtext NOT NULL,
AmountToBorrow mediumtext NOT NULL,
CreditProblems mediumtext NOT NULL,
AdditionalComments mediumtext NOT NULL
) TYPE=MyISAM;
error
MySQL said:
Incorrect table definition; There can only be one auto column and it must be defined as a key
What is a key?!
Do I have to set it in the form? Sorry about this guys but just bare with me please :)
ooops, EDIT -
I have it sorted now heh!
sorry about that, I'll crack on with the rest you gave me dreamcatcher!
Thank you friend!
Watch this space lol
I've got -
<html>
<head>
<title>View data</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php
$db = mysql_connect("localhost","dbname","pass");
mysql_select_db("db",$db);
$query = "SELECT * FROM mortgage";
$result = mysql_query($query); <div align="center"><center>
<table border="0" width="80%">
<tr>
<td align="center" width="25%">ID</td>
<td align="center" width="25%">Date</td>
<td align="center" width="25%">Name</td>
<td align="center" width="25%">E-Mail</td>
</tr>
<?
for ($i=0; $i<$row = mysql_fetch_array($result); $i++)
{
<tr>
<td>$row[id]</td>
<td>$row[FirstName]</td>
<td>$row[SurName]</td>
<td>$row[Email]</td>
</tr>
}
?>
</table>
</center></div>
</body>
</html>
Just not working, get errors, when I edit too, Only slight one line error but still, not working!
Thanks in adnvaced...
Firstly, from the code you posted you are missing a closing PHP tag after:
$result = mysql_query($query);
after that line add:
?>
Also, if you get database problems, it might be best to change the above line to:
$result = mysql_query($query) or die(mysql_error());
This is useful for debugging purposes.
Change:
<tr>
<td>$row[id]</td>
<td>$row[FirstName]</td>
<td>$row[SurName]</td>
<td>$row[Email]</td>
</tr>
to:
echo "<tr>\n";
echo "<td>$row[id]</td>\n";
echo "<td>$row[FirstName]</td>\n";
echo "<td>$row[SurName]</td>\n";
echo "<td>$row[Email]</td>\n";
echo "</tr>\n";
:)
Sorry to be like this but Ive got problems!
The print page code you gave me, keeps getting parse errors
[code]
</head>
<body>
<?php
$db = mysql_connect("localhost","","");
mysql_select_db("o",$db);
?>
<table border="0" width="80%">
<tr>
<td align="left" width="25%">ID</td>
<td align="left" width="25%">Date</td>
<td align="left" width="25%">Name</td>
<td align="left" width="25%">E-Mail</td>
</tr>
<?
if (isset($id))
{
$query = "SELECT * FROM mortgage WHERE ID = '$id'";
$result = mysql_query($query);
for ($i=0; $i<$row = mysql_fetch_array($result); $i++)
{
echo "<tr>\n";
echo "<td>$row[id]</td>\n";
echo "<td>$row[FirstName]</td>\n";
echo "<td>$row[SurName]</td>\n";
echo "<td>$row[Email]</td>\n";
echo "</tr>\n";
}
?>
</table>
</center></div>
</body>
</html>
[code]
Also the link in the$row, seems to get parse error too
Really need a helping hand
Thanks so much!
since you didn't say what type of parse error or what line it's on it doesn't help much but I'll do part of your homework
change this
for ($i=0; $i<$row = mysql_fetch_array($result); $i++)
{
echo "<tr>\n";
echo "<td>$row[id]</td>\n";
echo "<td>$row[FirstName]</td>\n";
echo "<td>$row[SurName]</td>\n";
echo "<td>$row[Email]</td>\n";
echo "</tr>\n";
}
to
while ($row = mysql_fetch_array($result)){
echo "<tr>\n<td>" . $row[id] . "</td>\n<td>" . $row[FirstName] . "</td>\n<td>" . $row[SurName] . "</td>\n<td>" . $row[Email] . "</td>\n</tr>\n";
}
see if that works
<html>
<head>
<title>View Data</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php
$db = mysql_connect("localhost","o","");
mysql_select_db("o",$db);
?><table border="0" width="80%">
<tr>
<td align="left" width="25%">ID</td>
<td align="left" width="25%">Date</td>
<td align="left" width="25%">Name</td>
<td align="left" width="25%">E-Mail</td>
</tr>
<?
if (isset($id))
{
$query = "SELECT * FROM mortgage WHERE ID = '$id'";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result)){
echo "<tr>\n<td>" . $row[id] . "</td>\n<td>" . $row[FirstName] . "</td>\n<td>" . $row[SurName] . "</td>\n<td>" . $row[Email] . "</td>\n</tr>\n";
}
?>
</table>
</center></div>
</body>
ERROR 33 HERE </html>
plus the link of the $row, what dreamcatcher gave me, dont seem to work, I just cant get it working in the bit instead of rowID, when I replace it I get parse error, saying expected ;
Thanks so much guys, Im a big trouble!
Just one more lol
You can shoot me after this!
<?
for ($i=0; $i<$row = mysql_fetch_array($result); $i++)
{
echo "<tr>\n";
echo "<td><a href="details.php?ID=$row[ID]">$row[ID]</a></td>\n";
echo "<td>$row[FirstName]</td>\n";
echo "<td>$row[SurName]</td>\n";
echo "<td>$row[Email]</td>\n";
echo "</tr>\n";
}
?>
What's wrong with that? says missing / expected " ; "
Thank you, I owe you all a beer!
I used -
<?
for ($i=0; $i<$row = mysql_fetch_array($result); $i++)
{
echo "<tr>\n<td>" <a href=\"details.php?ID=$row[ID]"\> . $row[ID] . </a> "</td>\n<td>" . $row[FirstName] . "</td>\n<td>" . $row[SurName] . "</td>\n<td>" . $row[Email] . "</td>\n</tr>\n";
}
?>
Dont work! :(
hey, and thanks for poping by DreamCatcher!
echo "<tr>\n<td><a href=\"details.php?ID=" . $row[ID] . "\">" . $row[ID] . "</a></td>\n<td>" . $row[FirstName] . "</td>\n<td>" . $row[SurName] . "</td>\n<td>" . $row[Email] . "</td>\n</tr>\n";
don't blame my while loop ;)
As for getting a specific amount of data from a database, you will be using a LIMIT claus.
$query = "SELECT FROM table WHERE blah = 'blah' LIMIT 1";
$result = mysql_query($query);
Depending on your query this would pull 1 entry from the database. So, if you wanted to have say a drop down menu with different values, ie:
<select name="total">
<option value="10">10</option>
<option value="20">>20</option>
<option value="50">>50</option>
<option value="100">>100</option>
</select>
you need to send the value of the above to the database for it to pull the specified amount of entries.
$total = $_POST['total'];
$query = "SELECT FROM table WHERE blah = 'blah' LIMIT $total";
$result = mysql_query($query);
Hope that helps.