Webmaster Forum

Go Back   Webmaster Forum > Web Development > Coding Forum

Coding Forum Problems with your code? Discuss coding issues, including JavaScript, PHP & MySQL, HTML & CSS, Flash & ActionScript, and more.


Reply
 
Thread Tools Display Modes
Share |
  #1  
Old 02-04-2009, 04:03 PM
2939195631902 2939195631902 is offline
Contributing Member
 
Join Date: 12-14-08
Posts: 140
iTrader: 0 / 0%
Lightbulb My sql Query string gives me error. I assume it has to do with the "where id= 80" par

My sql Query string gives me a error. I assume it has to do with the "where id= 80" part.



$game_info = get_table_data('games', 'id', 'ASC', 'rating', ' ', ''); // note there is a space between the second last set of single colons. So that it will trigger the function to add the where statement into the query.




// get all table data | Perform database query
function get_table_data($table, $order="id", $direction="ASC ", $column="*", $where="", $limit="") {
global $connection;
$query = "SELECT $column
FROM $table
ORDER BY $order $direction "; //must have space after $direction
if (!empty($where)) {
$query.="WHERE id = 80 "; //must have space after $limit. 80 is a example. I use it for testing the query.
if (!empty($limit)) {

$query.="LIMIT $limit ";

}
}
$table_set = mysql_query($query, $connection);
confirm_query($table_set);
return $table_set;
}
 
Reply With Quote

Advertisement

Advertisement

  #2  
Old 02-04-2009, 07:31 PM
Hades's Avatar
Hades Hades is offline
Senior Web Developer
 
Join Date: 01-23-07
Location: Argentina
Posts: 2,273
iTrader: 0 / 0%
Note that you are placing the WHERE statement after the ORDER BY.

The query should look like:
Code:
SELECT ... FROM ... WHERE ... ORDER BY ...
while yours looks like:
Code:
SELECT ... FROM ... ORDER BY ... WHERE ...
I suggest you change the script into:

Code:
$query = "SELECT $column FROM $table "; if (!empty($where)) { $query.="WHERE id = 80 "; } $query .= " ORDER BY $order $direction "; if (!empty($limit)) { $query.="LIMIT $limit "; } $table_set = mysql_query($query, $connection); confirm_query($table_set); return $table_set;
 
Reply With Quote
  #3  
Old 02-04-2009, 07:52 PM
2939195631902 2939195631902 is offline
Contributing Member
 
Join Date: 12-14-08
Posts: 140
iTrader: 0 / 0%
Exclamation

Quote:
Originally Posted by Hades View Post
Note that you are placing the WHERE statement after the ORDER BY.

The query should look like:
Code:
SELECT ... FROM ... WHERE ... ORDER BY ...
while yours looks like:
Code:
SELECT ... FROM ... ORDER BY ... WHERE ...
I suggest you change the script into:

Code:
$query = "SELECT $column FROM $table "; if (!empty($where)) { $query.="WHERE id = 80 "; } $query .= " ORDER BY $order $direction "; if (!empty($limit)) { $query.="LIMIT $limit "; } $table_set = mysql_query($query, $connection); confirm_query($table_set); return $table_set;

I tried switching the Where and Order by, but it didn't work either.

Also, could i still integrate the code you suggested into a function like i have above.
 
Reply With Quote
  #4  
Old 02-04-2009, 07:58 PM
Hades's Avatar
Hades Hades is offline
Senior Web Developer
 
Join Date: 01-23-07
Location: Argentina
Posts: 2,273
iTrader: 0 / 0%
can you either post the resulting query or the error that you get? maybe one of your variables is not set properly and the query produces an error.
 
Reply With Quote
  #5  
Old 02-04-2009, 08:10 PM
2939195631902 2939195631902 is offline
Contributing Member
 
Join Date: 12-14-08
Posts: 140
iTrader: 0 / 0%
Lightbulb Nvm i figured it out.

Quote:
Originally Posted by Hades View Post
can you either post the resulting query or the error that you get? maybe one of your variables is not set properly and the query produces an error.
NVM i used ur code and figured out the rest.

Thx for your response!!
 
Reply With Quote
Go Back   Webmaster Forum > Web Development > Coding Forum

Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Extensis "toolbox" photoshop error fastreplies Web Design Lobby 0 05-29-2008 01:51 AM
"No Input File Selected" Error in HtAccess, how do I fix? dcshoeco1 Coding Forum 5 03-27-2008 01:05 AM
Need help with creating an "error" on registration :) Alternus Coding Forum 2 06-10-2007 07:36 AM
"Method POST not allowed" error east_pole Web Design Lobby 3 02-16-2007 02:57 PM
PHP "Service Unavailable" caused by code error? gnznroses Coding Forum 14 03-12-2006 01:16 PM


V7N Network
Get exposure! V7N I Love Photography V7N SEO Blog V7N Directory


All times are GMT -7. The time now is 12:40 AM.
Powered by vBulletin
Copyright 2000-2014 Jelsoft Enterprises Limited.
Copyright © 2003 - 2018 VIX-WomensForum LLC