i want to sort qtitle by numbers. anyone can help me with tat.. i tried to modify the code below, but i couldn't find the solution. please help me..

<?php
$query1 = "SELECT * FROM table1";
$result1 = mysql_query($query1);

$i=1;
$num_row=mysql_num_rows(result1;)

while ($row1 = mysql_fetch_array($result1)) {
$qid = $row1['qid'];
$qtitle = $row1['qtitle'];

$query2 = "SELECT * FROM table2 WHERE qid='$qid'";
$result2 = mysql_query($query2);

while ($i<$num_row){
echo "<span style=\"text-decoration:underline; font-weight:bold;\">".$i." ".$qtitle."</span><br />";
$i++;
}

while ($row2 = mysql_fetch_array($result2)) {
$aid = $row2['aid'];
$atitle = $row2['atitle'];

echo "".$atitle."<br />";
}
echo "<br />";
}
?>

Hi,

Try this and see if it works.
Replace first query with this

$query1 = "SELECT * FROM table1 ORDER BY qtitle";

It depends upon which table has qtitle as a column, and accordingly you can put the 'order by qtitle' in the respective query.

somehow, i'm able to solve it.. thanks for your help. below is the wrkin script..

<?php
$query1 = "SELECT * FROM table1";
$result1 = mysql_query($query1);

$num_row=mysql_num_rows($result1);
$i=1;
while($i<$num_row){

while ($row1 = mysql_fetch_array($result1)) {
$qid = $row1['qid'];
$qtitle = $row1['qtitle'];

$query2 = "SELECT * FROM table2 WHERE qid='$qid'";
$result2 = mysql_query($query2);

while ($i<$num_row){
echo "<span style=\"text-decoration:underline; font-weight:bold;\">".$i.". ".$qtitle."</span><br />";

while ($row2 = mysql_fetch_array($result2)) {
$aid = $row2['aid'];
$atitle = $row2['atitle'];

echo "".$atitle."<br />";
}
echo "<br />";
$i++;
}
}
?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.