0

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 />";
}
?>
3
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by wayz1229
0

Hi,

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

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

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

0

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++;
}
}
?>
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.