Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.
Moderator: General Moderators
nexus6
Forum Newbie
Posts: 20 Joined: Fri Jun 17, 2005 3:50 am
Location: Denmark
Post
by nexus6 » Fri Jun 17, 2005 4:17 am
how can i merge this to codes into 1 $query ? is it possible?
I need both of the codes functionality for my admin.php. they both work seprately.
Code: Select all
$orderBy = "";
if (!empty($_GET['sort'])) {
$orderBy = "ORDER BY " .sqlite_escape_string($_GET['sort']);
}
$query = "SELECT * FROM beer $orderBy";
this is a nessesary code for my javascript "click to open row" function
and this is my select table from database code...
Code: Select all
if (isset($_GET['tableName'])) {
$table = sqlite_escape_string($_GET['tableName']);
}
$query = "SELECT * FROM $table ORDER BY title";
$result = sqlite_query($handle, $query) or die("Error in query: ".sqlite_error_string(sqlite_last_error($handle)));
Last edited by
nexus6 on Mon Jun 20, 2005 4:36 am, edited 1 time in total.
dreamline
Forum Contributor
Posts: 158 Joined: Fri May 28, 2004 2:37 am
Post
by dreamline » Sat Jun 18, 2005 10:50 am
I'm not sure if this is what you meant but here we go:
Code: Select all
$orderBy = "order by";
if (!empty($_GET['sort']))
{
$orderBy = "$orderBy " . sqlite_escape_string($_GET['sort']);
}
else
{
$orderBy ="$orderBy title";
}
if (isset($_GET['tableName']))
{
$table = sqlite_escape_string($_GET['tableName']);
}
else
{
$table='beer';
}
$query = "SELECT * FROM $table $orderBy";
$result = sqlite_query($handle, $query) or die("Error in query: ".sqlite_error_string(sqlite_last_error($handle)));
JCART | Please use Code: Select all
tags when posting php code. Review [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
nexus6
Forum Newbie
Posts: 20 Joined: Fri Jun 17, 2005 3:50 am
Location: Denmark
Post
by nexus6 » Sun Jun 19, 2005 8:09 pm
thank you very much!
this was exactly what i needed:)
one more thing - how do i post this Solved
dreamline
Forum Contributor
Posts: 158 Joined: Fri May 28, 2004 2:37 am
Post
by dreamline » Mon Jun 20, 2005 2:27 am
Just edit your post and add [solved] to the title..