NameSilo

Help with php

Spaceship Spaceship
Watch

JH

Established Member
Impact
5
Hi,
Im not very good with php at all,
I was wondering if anyone can help me with this... i want to clean it up and make it html valid ect
is there a way to do it instead of having to use the print function ?

Any help appreciated.:)

PHP:
<?php 
include "connect.php"; //mysql db connection here
print "<title>Title</title>";
print "<link rel='stylesheet' href='style.css' type='text/css'>";
print "<A href='post.php'>New Topic</a><br>";
print "<table class='maintable'>";
print "<tr class='headline'><td width=50%>Topic</td><td width=20%>Topic Starter</td><td>Replies</td><td>Last replied time</td></tr>";
$getthreads="SELECT * from forumtutorial_posts where parentid='0' order by lastrepliedto DESC";
$getthreads2=mysql_query($getthreads) or die("Could not get threads");
while($getthreads3=mysql_fetch_array($getthreads2))
{
  $getthreads3[title]=strip_tags($getthreads3[title]);
  $getthreads3[author]=strip_tags($getthreads3[author]);
  print "<tr class='mainrow'><td><A href='message.php?id=$getthreads3[postid]'>$getthreads3[title]</a></td><td>$getthreads3[author]</td><td>$getthreads3[numreplies]</td><td>$getthreads3[showtime]<br>Last post by <b>$getthreads3[lastposter]</b></td></tr>";
}
print "</table>";


?>
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
AfternicAfternic
you can put valid xhtml into a .php without <?php ?> or print's.
 
0
•••
Well this is what iv got and it isnt working... help anyone?

cheers

PHP:
<?php include "connect.php"; //mysql db connection here ?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Title</title>
<link rel='stylesheet' href='style.css' type='text/css'>

<body>

<A href='post.php'>New Topic</a><br>
<table class='maintable'>

<tr class='headline'><td width=50%>Topic</td><td width=20%>Topic Starter</td><td>Replies</td><td>Last replied time</td></tr>
<?php $getthreads="SELECT * from forumtutorial_posts where parentid='0' order by lastrepliedto DESC"; ?>
<?php $getthreads2=mysql_query($getthreads) or die("Could not get threads"); ?>
<?php while($getthreads3=mysql_fetch_array($getthreads2)); ?>

<?php  $getthreads3[title]=strip_tags($getthreads3[title]); ?>
<?php  $getthreads3[author]=strip_tags($getthreads3[author]); ?>
<tr class='mainrow'><td><A href='message.php?id=<?php $getthreads3[postid];?>'><?php $getthreads3[title];?></a></td><td><?php $getthreads3[author];?></td><td><?php $getthreads3[numreplies];?></td><td><?php $getthreads3[showtime];?><br>Last post by <b><?php $getthreads3[lastposter];?></b></td></tr>


</table>

</body>
</html>
 
Last edited:
0
•••
PHP:
<?php include "connect.php"; //mysql db connection here ?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Title</title>
<link rel='stylesheet' href='style.css' type='text/css'>

<body>

<a href='post.php'>New Topic</a><br />
<table class='maintable'>

<tr class='headline'><td width=50%>Topic</td><td width=20%>Topic Starter</td><td>Replies</td><td>Last replied time</td></tr>

<?php 
$getthreads="SELECT * from forumtutorial_posts where parentid='0' order by lastrepliedto DESC";
$getthreads2=mysql_query($getthreads) or die("Could not get threads");


while($getthreads3=mysql_fetch_array($getthreads2)){
    $getthreads3[title]=strip_tags($getthreads3[title]);
    $getthreads3[author]=strip_tags($getthreads3[author]); 
    echo "<tr class='mainrow'><td><a href='message.php?id=".$getthreads3[postid]."'>".$getthreads3[title]."</a></td><td>".$getthreads3[author]."</td><td>".$getthreads3[numreplies]."</td><td>".$getthreads3[showtime]."<br />Last post by <b>".$getthreads3[lastposter]."</b></td></tr>"; 
}
?>


</table>

</body>
</html>

Let me know if it works or not. You were closing php tags far too often and reopening them.
Also, your while loop just ended after you declared it, meaning it did nothing, you need to open it with a { after declaration then tell it what to do and close with };
 
0
•••
Cheers NVD,

It works like a charm :)
 
0
•••
Anytime :)
 
0
•••
Use double quotes for xhtml tag attributes, not single quotes! e.g. <a href="post.php">
 
0
•••
PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Title</title>
<link rel="stylesheet" href="style.css" type="text/css" />
</head>
<!-- you were missing </head>, also added in what amoeba was saying ;) use double quotes for tag attributes -->

<body>

<a href="post.php">New Topic</a><br />

<table class="maintable">
<tr class="headline">
	<td width="50%">Topic</td>
	<td width="20%">Topic Starter</td>
	<td>Replies</td>
	<td>Last replied time</td>
</tr>

<?php

/**
 * when retreiving the SQL records, it's better to use mysql_fetch_assoc if you're not using row #'s
 * 
 * also, no point in assigning a query string to a var and using another var to actually perform the query
 * and.. no point wrapping strings in php with " unless it is a SQL string, contains $vars, or uses single quotes
 * within it.
 */
$getthreads = mysql_query("
	SELECT * 
	FROM forumtutorial_posts
	WHERE parentid = '0'
	ORDER BY lastrepliedto DESC
") or die('Could not get threads');

while ($thread = mysql_fetch_assoc($getthreads))
{
	/**
	 * In PHP arrays, you should use single quotes!
	 * 
	 * GOOD: $thread['title']
	 * BAD : $thread[title]
	 * 
	 * :P
	 *
	 * Only exception is if you're using them in a double quoted string
	 */
	$thread['title'] = strip_tags($thread['title']);
	$thread['author'] = strip_tags($thread['author']); 
    echo "
<tr class=\"mainrow\">
	<td><a href=\"message.php?id=$thread[postid]\">$thread[title]</a></td>
	<td>$thread[author]</td>
	<td>$thread[numreplies]</td>
	<td>$thread[showtime]<br />Last post by <b>$thread[lastposter]</b></td>
</tr>
"; 
}

?>
</table>

</body>
</html>
 
0
•••

We're social

Unstoppable Domains
Domain Recover
DomainEasy — Live Options
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back