3
Contributors
6
Replies
8
Views
5 Years
Discussion Span
Last Post by diafol
0

can u make it for me diafor .. i am trying but error occured

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");
$sql="SELECT * FROM $tbl_name where cat1=technical ORDER BY id DESC";
// OREDER BY id DESC is order result by descending

$result=mysql_query($sql);
?>

<?php

// Start looping table row
while($rows=mysql_fetch_array($result)){
?>

 data present here with echos


<?php
// Exit looping and close connection 
}
mysql_close();
?>

can u write this code which selects and order the data .. please :)

1

OK, since you've got the basics, I'll just add a bit to it. BTW 'multiple' confused me - I thought you wanted to run multiple queries. You just need to output the data.

mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

$sql="SELECT * FROM $tbl_name where cat1='technical' ORDER BY id DESC";

$result=mysql_query($sql);
echo "<ul>";
while($rows=mysql_fetch_array($result)){
    echo "<li>{$row['field1']} | {$row['field2']} | {$row['field3']} | {$row['field1']}</li>";
}
echo "</ul>";
mysql_close();

Change field1, field2, field3, field4 to fieldnames that actually exist in your DB table.

1

Hi sabarinadh,

In your query you have not added single quote to your cat1 value.

Except integer you should use quote.

Eg: cat1 = 'technical'

0

Hi Nithin i tried the above code but still some errors if you dont mine can u please develope the code which was used to retreive data from users where cat1=technicalfest and order by id desc :)

This topic has been dead for over six months. 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.