NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page Help with php

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search
5 members in live chat ~  


Reply
 
LinkBack Thread Tools
Old 10-10-2009, 11:02 AM THREAD STARTER               #1 (permalink)
JH
NamePros Regular
Join Date: Jun 2005
Location: UK
Posts: 533
JH is a jewel in the roughJH is a jewel in the roughJH is a jewel in the rough
 



Help! Help with php


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 Code:
<?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>";
????: NamePros.com http://www.namepros.com/programming/615790-help-with-php.html
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";
????: NamePros.com http://www.namepros.com/showthread.php?t=615790
$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>";


?>
__________________
Joe or Joseph ???
JH is offline   Reply With Quote
Old 10-10-2009, 11:05 AM   #2 (permalink)
Senior Member
 
shockie's Avatar
Join Date: Dec 2006
Posts: 4,702
shockie has a reputation beyond reputeshockie has a reputation beyond reputeshockie has a reputation beyond reputeshockie has a reputation beyond reputeshockie has a reputation beyond reputeshockie has a reputation beyond reputeshockie has a reputation beyond reputeshockie has a reputation beyond reputeshockie has a reputation beyond reputeshockie has a reputation beyond reputeshockie has a reputation beyond repute
 



you can put valid xhtml into a .php without <?php ?> or print's.
__________________
- shockie
shockie is offline   Reply With Quote
Old 10-10-2009, 11:42 AM THREAD STARTER               #3 (permalink)
JH
NamePros Regular
Join Date: Jun 2005
Location: UK
Posts: 533
JH is a jewel in the roughJH is a jewel in the roughJH is a jewel in the rough
 



Well this is what iv got and it isnt working... help anyone?

cheers

PHP Code:
<?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]); ?>
????: NamePros.com http://www.namepros.com/showthread.php?t=615790
????: NamePros.com http://www.namepros.com/showthread.php?t=615790
<?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>
__________________
Joe or Joseph ???
Last edited by JH; 10-10-2009 at 11:53 AM.
JH is offline   Reply With Quote
Old 10-10-2009, 06:35 PM   #4 (permalink)
NamePros Regular
 
pixelhero's Avatar
Join Date: May 2008
Location: England
Posts: 771
pixelhero is a name known to allpixelhero is a name known to allpixelhero is a name known to allpixelhero is a name known to allpixelhero is a name known to allpixelhero is a name known to all
 


Help The Homeless - Holiday 2009
PHP Code:
<?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]); 
????: NamePros.com http://www.namepros.com/showthread.php?t=615790
    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>"
????: NamePros.com http://www.namepros.com/showthread.php?t=615790
}
?>


</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 };
pixelhero is offline   Reply With Quote
Old 10-11-2009, 06:19 AM THREAD STARTER               #5 (permalink)
JH
NamePros Regular
Join Date: Jun 2005
Location: UK
Posts: 533
JH is a jewel in the roughJH is a jewel in the roughJH is a jewel in the rough
 



Cheers NVD,

It works like a charm
__________________
Joe or Joseph ???
JH is offline   Reply With Quote
Old 10-11-2009, 07:36 AM   #6 (permalink)
NamePros Regular
 
pixelhero's Avatar
Join Date: May 2008
Location: England
Posts: 771
pixelhero is a name known to allpixelhero is a name known to allpixelhero is a name known to allpixelhero is a name known to allpixelhero is a name known to allpixelhero is a name known to all
 


Help The Homeless - Holiday 2009
Anytime
pixelhero is offline   Reply With Quote
Old 10-31-2009, 12:00 AM   #7 (permalink)
NamePros Regular
 
amoeba's Avatar
Join Date: Sep 2005
Location: ~$
Posts: 656
amoeba is a splendid one to beholdamoeba is a splendid one to beholdamoeba is a splendid one to beholdamoeba is a splendid one to beholdamoeba is a splendid one to beholdamoeba is a splendid one to beholdamoeba is a splendid one to behold
 



Use double quotes for xhtml tag attributes, not single quotes! e.g. <a href="post.php">
__________________
[ syzygy ] [ free public DNS service ]
amoeba is online now   Reply With Quote
Old 10-31-2009, 12:54 AM   #8 (permalink)
Tech Support
Join Date: Mar 2005
Posts: 4,944
Eric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatness
 

Member of the Month
MOTM September 2005
Save a Life Child Abuse 9/11/01 :: Never Forget Baby Health Marrow Donor Program AIDS/HIV Breast Cancer Animal Rescue Cystic Fibrosis Ethan Allen Fund Animal Cruelty Ethan Allen Fund Ethan Allen Fund Baby Health Cancer Alzheimer's Protect Our Planet Cancer Survivorship SIDS Child Abuse Diabetes Protect Our Planet Multiple Sclerosis Autism Adoption Special Olympics
PHP Code:
<!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
????: NamePros.com http://www.namepros.com/showthread.php?t=615790
 * 
 * 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
????: NamePros.com http://www.namepros.com/showthread.php?t=615790
"
) 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>
Eric is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


 
All times are GMT -7. The time now is 02:31 PM.

Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger