php to html help please

This is a discussion on "php to html help please" within the PHP Forum section. This forum, and the thread "php to html help please are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices


Closed Thread
 
LinkBack Thread Tools
  #1 (permalink)  
Old Jun 15th, 2004, 20:58
Junior Member
Join Date: Mar 2004
Location: United Kingdom
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
php to html help please

I have a results page to a search but it is using the echo function to print it to screen.

I cannot seem to be able to format it so that they come up as a table.

How can I change the code so that I can have these results in an HTML table such as those on record charts pages. It is the echo statements at the bottom that I am having problems converting.
If anyone can amend this code for me it will be very much appreciated.

This is the code for the search results page:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Search Results</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_reloadPage(init) { //reloads the window if Nav4 resized
if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
//-->
</script>
<link rel="stylesheet" href="books.css">
</head>

<body class="body">
<table width="95%" border="0" align="center" cellpadding="3" cellspacing="0">
<tr>
<td width="11%" rowspan="2">[img]logo.gif[/img]</td>
<td height="82" colspan="3"> <div align="center">[img]ptBanner.gif[/img]</div></td>
</tr>
</table>
<table width="237">
<tr align="center" class="years-ago"><td>Pageturners Search Results</td></tr></table>
<?php
//create short variable names
$searchtype=$HTTP_POST_VARS['searchtype'];
$searchterm=$HTTP_POST_VARS['searchterm'];
$searchterm= trim($searchterm);

if (!$searchtype || !$searchterm)
{
echo 'You have not entered search details. Please go back and try again.';
exit;
}

$searchtype = addslashes($searchtype);
$searchterm = addslashes($searchterm);

@ $DbConn = mysql_connect("localhost","root","poppet");
if (!$DbConn)
{
echo "Error, Could not connect to the system database. Sorry...";
exit;
}

mysql_select_db('charts50');
$query = "select * from uk where ".$searchtype." like '%".$searchterm."%'";
$result = mysql_query($query);

$num_results = mysql_num_rows($result);

echo '

Number of records found: '.$num_results.'</p>';

for ($i=0; $i <$num_results; $i++)

{
$row = mysql_fetch_array($result);
echo '

[b]'.($i+1).' TW: ';
echo (stripslashes($row['TW']));
echo '[b]
LW: ';
echo stripslashes($row['LW']);
echo '
Wks: ';
echo stripslashes($row['Wks']);
echo '
Title: ';
echo stripslashes($row['Title']);
echo '
Artist: ';
echo stripslashes($row['Artist']);
echo '
Date: ';
echo stripslashes($row['Date']);
}
?>

</body>
</html>

  #2 (permalink)  
Old Jun 15th, 2004, 23:32
Most Reputable Member
Join Date: Jul 2003
Posts: 1,856
Thanks: 0
Thanked 0 Times in 0 Posts
Just draw up a table in standard HTML and then place the code around the PHP you have.

You can always end segments of PHP and have some HTML, then have another segment of PHP for the table content.
  #3 (permalink)  
Old Jun 16th, 2004, 08:24
Junior Member
Join Date: Mar 2004
Location: United Kingdom
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
<blockquote id="quote"><font size="1" face="geneva, verdana, arial" id="quote">quote:<hr height="1" noshade id="quote">Originally posted by Sirkent

Just draw up a table in standard HTML and then place the code around the PHP you have.

You can always end segments of PHP and have some HTML, then have another segment of PHP for the table content.
<hr height="1" noshade id="quote"></blockquote id="quote"></font id="quote">
Sounds easier said than done. I may sound a bit thick but being a newbie to PHP I don't quite understand how this is done.

Could you just give me one example please.
  #4 (permalink)  
Old Jun 16th, 2004, 08:40
Most Reputable Member
Join Date: Jul 2003
Posts: 1,856
Thanks: 0
Thanked 0 Times in 0 Posts
Well you can see that the < ? php tag starts halfway through the HTML and ends just before the end ? >

You should know basic HTML before you tackle any web language. So draw up a table in HTML.

This part:
Code: Select all
for ($i=0; $i <$num_results; $i++)

{
$row = mysql_fetch_array($result);
echo '

[b]'.($i+1).' TW: ';
echo (stripslashes($row['TW']));
echo '[b]
LW: ';
echo stripslashes($row['LW']);
echo '
Wks: ';
echo stripslashes($row['Wks']);
echo '
Title: ';
echo stripslashes($row['Title']);
echo '
Artist: ';
echo stripslashes($row['Artist']);
echo '
Date: ';
echo stripslashes($row['Date']);
}
Repeats over all of the records you have selected from the database.

First you will want your table header, so TW, LW, Weeks, etc in full (this should be before the for loop altogether).
Then you will want to place a new row at the beginning of the loop, then loop through each piece of information placing it in a seperate cell until the end of your loop when you end the row.

Therefore, each time the loop runs once, it spits out a row with your values.
  #5 (permalink)  
Old Jun 16th, 2004, 12:46
Junior Member
Join Date: Mar 2004
Location: United Kingdom
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Many thanks Sirkent I'll give it a go.
Closed Thread

Tags
php, html, help

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
HTML, css and php gecko Web Page Design 4 Apr 17th, 2008 07:44
Can I do this with html or anything else??? Petey_ Web Page Design 2 May 31st, 2006 21:04
PHP within HTML stickywicket PHP Forum 0 Dec 6th, 2005 19:05
Html leonheart Introduce Yourself 3 Aug 19th, 2005 21:55


All times are GMT. The time now is 18:44.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43