blueman378 Posted March 15, 2008 Share Posted March 15, 2008 hi guys, well we are making a little forum and heres our select code: "SELECT * FROM $tbl_name2 WHERE question_id='$id'"; but as of current its showing reply 5 reply 4 reply 3 reply 2 reply 1 how would we make it orderd by a_id and have it reply 1 reply 2 reply 3 reply 4 reply 5 cheers matt Quote Link to comment Share on other sites More sharing options...
derrick1123 Posted March 15, 2008 Share Posted March 15, 2008 Can you post the code were you echo it? Quote Link to comment Share on other sites More sharing options...
blueman378 Posted March 15, 2008 Author Share Posted March 15, 2008 <?php $root = "../"; $tbl_name="forum_question"; // Table name // get value of id that sent from address bar $id=$_GET['id']; $query="SELECT * FROM $tbl_name WHERE id='$id'"; $result=mysql_query($query); $rows=mysql_fetch_array($result); $queryd="SELECT avatar FROM users WHERE username='$rows[name]'"; $resultd=mysql_query($queryd); $rowd=mysql_fetch_array($resultd); ?> <table width="605" border="0" align="left" cellpadding="0" cellspacing="1" class="forum"> <tr height="30" class="titles"> <td valign="top" colspan="2"><u><? echo $rows['topic']; ?></u></td> </tr> <tr> <td bgcolor="#111111" style="padding:5px 5px 5px 5px;" width="1%"> <? echo $rows['name']; ?><br /> <strong>Posted on:</strong><br><? echo $rows['datetime']; ?> <img border="1" src="avatars/<? echo $rowd['avatar']; ?>" width="60" height="60"></td> <td colspan="3" valign="top" style="padding:5px 5px 5px 5px;"><? echo $rows['detail']; ?></td> </tr> </table> <?php $tbl_name2="forum_answer"; // Switch to table "forum_answer" $query2="SELECT * FROM $tbl_name2 WHERE question_id='$id'"; $result2=mysql_query($query2); while($rows=mysql_fetch_array($result2)){ ?> <table width="605" border="0" align="left" cellpadding="0" cellspacing="2"> <tr><td colspan="2"><hr /></td></tr> <tr><td colspan="2"><? echo $rows['a_title'];?></td></tr> <tr> </tr> <tr> <td bgcolor="#111111" valign="top" style="padding:5px 5px 5px 5px;" width="1%"> <? echo $rows['a_name']; ?><br /> <strong>Posted on:</strong><br><? echo $rows['a_datetime']; ?><br> <img border="1" src="avatars/<? echo $rowd['avatar']; ?>" width="60" height="60"></td> <td colspan="3" valign="top" width="470" style="padding:5px 5px 5px 5px;"> <? echo $rows['a_answer']; ?></td> </tr> </table> <?php $q_title=$rows['a_title']; ?> <? } $query3="SELECT view FROM $tbl_name WHERE id='$id'"; $result3=mysql_query($query3); $rows=mysql_fetch_array($result3); $view=$rows['view']; // if have no counter value set counter = 1 if(empty($view)){ $view=1; $query4="INSERT INTO $tbl_name(view) VALUES('$view') WHERE id='$id'"; $result4=mysql_query($query4); } // count more value $addview=$view+1; $query5="update $tbl_name set view='$addview' WHERE id='$id'"; $result5=mysql_query($query5); if ($_SESSION['loggedin'] == "1") { ?> <div class="form"> <table border="0" align="center" cellpadding="0" cellspacing="1"> <tr> <td> <b>Submit a comment:</b> </td> </tr> <tr> <form name="form1" method="post" action="add_answer.php"> <td> <table width="100%" border="0" cellpadding="3" cellspacing="1"> <tr> <td><textarea name="a_answer" cols="43" rows="5" id="a_answer"></textarea></td> </tr> <tr> <td align="center"><input name="id" type="hidden" value="<? echo $id; ?>"><input type="submit" name="Submit" value="Submit" class="button"> <input type="reset" name="Submit2" value="Reset" class="button"></td> <td></td> </tr> </table> </td> </form> </tr> </table> </div> <?php } ?> Quote Link to comment Share on other sites More sharing options...
therealwesfoster Posted March 15, 2008 Share Posted March 15, 2008 Change it to: "SELECT * FROM $tbl_name2 WHERE question_id='$id' ORDER BY question_id ASC"; ASC = Ascending DESC = Descending Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.