I have to retrevie data from the database using

"SELECT * FROM $tbl_name WHERE cat1 = technicalfest ORDER BY id DESC";

can any one tell me how to use multiple

Recommended Answers

All 6 Replies

Member Avatar for diafol

You can use mysqli to run multiple queries:

http://php.net/manual/en/mysqli.multi-query.php

However, you may find that your queries may be able to be combined into a single query (e.g. using UNION or IN). Supply your queries so that we can determine the best possible solution.

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 :)

Member Avatar for diafol

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.

Hi sabarinadh,

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

Except integer you should use quote.

Eg: cat1 = 'technical'

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 :)

Member Avatar for diafol

Ahem, I corrected the single quote thing in my last post. Anyway, did my code not work?

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.