Jump to content

Make a tidier list


m4tt1986

Recommended Posts

Hi,

  Im fairly new to php and was wondering if any one is able to shed some light on the following.

 

I used a form to database generator to provide a quoting system for insurance.

 

the page I have for the admin to view all quotes submitted by customers is a bit messy, as it will just display all customers details one after the other, eg:

 

first name: Joe

surname: bloggs

Car: fiesta

 

first name: John

surname: smith

car: Escort

 

etc etc.

 

I am looking to make this look like the following table:

www.euro-compare.eu/tableview.htm

 

The code i have for the list is as follows:

<a href="add.html">Add entry</a><br>

<br>

<?php

/// In order to use this script freely

/// you must leave the following copyright

/// information in this file:

/// Copyright 2006 www.turningturnip.co.uk

/// All rights reserved.

 

include("connect.php");

 

$query="SELECT * FROM motor_insuraction_quotation ";

$result=mysql_query($query);

$num = mysql_num_rows ($result);

mysql_close();

 

if ($num > 0 ) {

$i=0;

while ($i < $num) {

$firstname = mysql_result($result,$i,"firstname");

$surname = mysql_result($result,$i,"surname");

$address = mysql_result($result,$i,"address");

$province = mysql_result($result,$i,"province");

$email = mysql_result($result,$i,"email");

$telephone = mysql_result($result,$i,"telephone");

$dd = mysql_result($result,$i,"dd");

$mm = mysql_result($result,$i,"mm");

$yyyy = mysql_result($result,$i,"yyyy");

$make = mysql_result($result,$i,"make");

$model = mysql_result($result,$i,"model");

$enginesize = mysql_result($result,$i,"enginesize");

$transmission = mysql_result($result,$i,"transmission");

$convertible = mysql_result($result,$i,"convertible");

$origin = mysql_result($result,$i,"origin");

$yearofmanufacture = mysql_result($result,$i,"yearofmanufacture");

$value = mysql_result($result,$i,"value");

$coverrequired = mysql_result($result,$i,"coverrequired");

$ncb = mysql_result($result,$i,"ncb");

$youngestdriver = mysql_result($result,$i,"youngestdriver");

$password = mysql_result($result,$i,"password");

$passreminder = mysql_result($result,$i,"passreminder");

$newsletter = mysql_result($result,$i,"newsletter");

$id = mysql_result($result,$i,"id");

 

echo "<b>FirstName:</b> $firstname<br>";

echo "<b>Surname:</b> $surname<br>";

echo "<b>Address:</b> $address<br>";

echo "<b>Province:</b> $province<br>";

echo "<b>Email:</b> $email<br>";

echo "<b>Telephone:</b> $telephone<br>";

echo "<b>dd:</b> $dd<br>";

echo "<b>mm:</b> $mm<br>";

echo "<b>yyyy:</b> $yyyy<br>";

echo "<b>Make:</b> $make<br>";

echo "<b>Model:</b> $model<br>";

echo "<b>EngineSize:</b> $enginesize<br>";

echo "<b>Transmission:</b> $transmission<br>";

echo "<b>Convertible:</b> $convertible<br>";

echo "<b>Origin:</b> $origin<br>";

echo "<b>YearOfManufacture:</b> $yearofmanufacture<br>";

echo "<b>Value:</b> $value<br>";

echo "<b>CoverRequired:</b> $coverrequired<br>";

echo "<b>NCB:</b> $ncb<br>";

echo "<b>YoungestDriver:</b> $youngestdriver<br>";

echo "<b>Password:</b> $password<br>";

echo "<b>PassReminder:</b> $passreminder<br>";

echo "<b>Newsletter:</b> $newsletter<br>";

echo "<a href=\"update.php?id=$id\">Update</a> - <a href=\"delete.php?id=$id\">Delete</a>";

echo "<br><br>";

 

++$i; } } else { echo "The database is empty"; }?>

 

Kind Regards

Matt

Link to comment
Share on other sites

Try this and throw your "generator" away.

 

<?php
include 'connect.php';

$result = mysql_query('SELECT * FROM motor_insuraction_quotation');
if (mysql_num_rows($result) > 0) {
echo <<<EOF
<table>
<tr>
	<th>ID</th>
	<th>Firstname</th>
	<th>Surname</th>
	<th>Email</th>
	<th>Phone</th>
	<th>View</th>
	<th>Delete</th>
	<th>Update</th>
</tr>

EOF;
while ($row = mysql_fetch_assoc($result)) {
	echo <<<EOF
<tr>
	<td>{$row['id']}</td>
	<td>{$row['firstname']}</td>
	<td>{$row['surname']}</td>
	<td>{$row['email']}</td>
	<td>{$row['telephone']}</td>
	<td><!-- view --></td>
	<td><!-- delete --></td>
	<td><!-- update --></td>
</tr>

EOF;
}
echo <<<EOF
</table>

EOF;
}
else {
echo 'Database is empty';
}
?>

Link to comment
Share on other sites

Yes there is...But im not gonna write out the whole thing but ill give you the idea...

First your gonna make the top part of the table first then write your php script.

 

include("connect.php");
$query="SELECT * FROM motor_insuraction_quotation ";
$result=mysql_query($query);
while ($row = mysql_fetch_array($result)){
echo '<tr><td>'.$row['yourcolumnname'].'</td><td>'.$row['nextcolumnname'].'</td><td>';
}

..............and so on.

When ever you want to stop the text and put in a variable you need end it with a ' and to let php know your gonna put in a variable you put in a period .$your variable and then another . to end the variable and then you start the text alll over again with a '

after the php and the table.

 

Link to comment
Share on other sites

When ever you want to stop the text and put in a variable you need end it with a ' and to let php know your gonna put in a variable you put in a period .$your variable and then another . to end the variable and then you start the text alll over again with a '

It's called concatenation.

Link to comment
Share on other sites

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.