473,394 Members | 1,865 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

PHP Query Problem/Error

384 256MB
I'm getting the error below, i've printed out the SQL query and its fine, it also works in the DB, SELECT sub_id,type FROM comments WHERE id='103' LIMIT 1, any ideas?
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\Apache\htdocs\config\sql.php on line 798
This is the code:
Expand|Select|Wrap|Line Numbers
  1. function getCommentLink($id) {
  2.   $link = "";
  3.   $type = "";
  4.  
  5.   $sql = "SELECT sub_id,type FROM comments WHERE id='".$id."' LIMIT 1";
  6.   echo $sql;
  7.   $sql = mysql_query($sql);
  8.   while ($row = mysql_fetch_array($sql)) //Line 798
  9.   {
  10.     $type = $row['type'];
  11.     $sql = mysql_query("SELECT id,title FROM ".$row['type']." WHERE id='".$row['sub_id']."' LIMIT 1");
  12.     while ($row = mysql_fetch_array($sql))
  13.     {
  14.       if($type == "news")
  15.       {
  16.         $type = "article-news";
  17.       }
  18.       else if($type == "reviews") 
  19.       {
  20.         $type = "article-reviews";
  21.       }
  22.       else if($type == "previews") 
  23.       {
  24.         $type = "article-previews";
  25.       }
  26.  
  27.       $link = "../../../".$type."/".$row['id']."-".preg_replace('#[^a-zA-Z0-9]+#','-',$row['title']).".htm";
  28.     }
  29.   }
  30.   return $link;
  31. }
Dec 10 '08 #1
5 1115
Markus
6,050 Expert 4TB
Is 'sub_id' and INT column? If so, you shouldn't have quotes around the value.

Expand|Select|Wrap|Line Numbers
  1. $sql = "SELECT sub_id,type FROM comments WHERE id={$id}"
  2.  
Thanks,
Markus.
Dec 10 '08 #2
ziycon
384 256MB
It is an int column but i have commas around it for extra security against SQL injection attacks.

Got it sorted, had the db connect function after the sql statement.
Dec 10 '08 #3
Markus
6,050 Expert 4TB
Line 27 is just ugly, ugly, ugly, btw.

You should have a couple of constants defined in your application that point to various locations. That way, you don't need to use '../', etc,. to find the right directory. Something like..

Expand|Select|Wrap|Line Numbers
  1. define("ART_PATH", "/html/your-site.com/html_docs/articles/");
  2.  
Then you can get to 'articles' easily and neatly.

Thanks,
Markus.
Dec 10 '08 #4
ziycon
384 256MB
I know its terrible, I'm going to sort all those constants out once i get the system working properly, just a bit of jigging about, thanks for the feedback.
Dec 10 '08 #5
Markus
6,050 Expert 4TB
@ziycon
Jolly good!

Glad you got it sorted,
Markus.
Dec 10 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: johnnyboy10017 | last post by:
I am having a hell of a time with what I think is a very simple query: It won't actually insert a new record into the specified table, but returns no error, in fact it returns "1" (or true) that...
2
by: jaysonsch | last post by:
Hello! I am having some problems with a database query that I am trying to do. I am trying to develop a way to search a database for an entry and then edit the existing values. Upon submit, the...
1
by: Sean C. | last post by:
Helpful folks, I have recently migrated our test server, which runs Win NT 4, from V7.2 FP11 to V8.1.3. Just about everything works wondefully, except I am having major problems getting the...
2
by: Mal | last post by:
Greetings. I have a perplexing problem....please help. I am having a problem with an insert query. (SQL below) When I run the query via code (executing the SQL string) it crashes Access and...
8
by: Adam Louis | last post by:
I would like help resolving this problem. I'm a novice who's been hired to query a hospital database and extract useful information, available to me only in a dynamically generated, downloadable...
6
by: Martin Lacoste | last post by:
Ok, before I headbutt the computer... don't know why when I add criteria in a query, I get an 'invalid procedure call'. I also don't know why after searching the help in access, the various access...
7
by: John Øllgård Jensen | last post by:
Hi Using MS Asccess 2000: In a query I'm trying to create a new field with following expression: FilmDate: Left(,4) The field "FilmNo" is another text field in the query. This is...
16
by: ARC | last post by:
Hello all, So I'm knee deep in this import utility program, and am coming up with all sorts of "gotcha's!". 1st off. On a "Find Duplicates Query", does anyone have a good solution for...
9
by: QCLee | last post by:
Sir can you help me to transfer my Access Query to MS excel? i have a command button on the form to export the parameter query named "HVACWindwardQuery" to excel spreadsheet and i got the codes...
9
by: dizzydangler | last post by:
Hi, all! After receiving a lot of help from ADezzi, Msquared, and NeoPa getting my ms access 2007 db functioning, I've run into another hitch that I haven't been able to solve. The database itself...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.