Dynadot .com transfer sale, only $10.12 with coupon code DYNA12, available while supplies last, ends October 31, 2026.

Help with php

Namecheap AuctionsNamecheap Auctions
Namecheap AuctionsNamecheap Auctions
SpaceshipSpaceship
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
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
you can put valid xhtml into a .php without <?php ?> or print's.
 
0
Close
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
Close
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
Close
Cheers NVD,

It works like a charm :)
 
0
Close
Anytime :)
 
0
Close
Use double quotes for xhtml tag attributes, not single quotes! e.g. <a href="post.php">
 
0
Close
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
Close
CatchedCatched

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Spatial Sidebar: More consistent display
We fixed some bugs in the Spatial Sidebar. It now displays more consistently across browsers and should perform better. If you use it...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back