0

I have a query I'm using to pull in content based on a record number, but for some reason I can only grab certain records. When I output it onto a page, some records show up as completely blank.

$testSQL = mysql_query("SELECT * FROM `uploads` WHERE (`tableName`='data_table' AND `recordNum` = '112' AND `fieldName` = 'pdf')");

$testSQL = mysql_fetch_assoc($testSQL);

print_r($testSQL);

Theq query above outputs results, but when I change 'recordNum' to 80, I get nothing.

There is only one item for each record number. When I paste the query into mysql admin, it returns the correct result for both record 80 and record 112. But when I place full code on my page I can only get record 112. Any idea why one record is showing up as empty? The result is laid out exactly the same in mysql admin.

EDIT: Here's the output from mysql admin

-----------------------------------------------
num | order | tableName  | fieldName | recordNum
-----------------------------------------------
20  |  1    | data_table |  pdf      | 112
-----------------------------------------------
20  |  1    | data_table |  pdf      | 80

EDIT 2: recordNum is set up as a string (VARCHAR255) and it doesn't seem like there are any spaces aren't the values of recordNum - I just highlighted the text, is there a better way to determine that?

ANOTHER UPDATE

I did a test pull to grab all of the data and it only pulled in the first 64 records. MySQL admin is telling me there are 102 records. Is there anything that could be causing my query to be limited?

FINAL UPDATE

I had a bug further up on my page prior to running this sql query from a different query that was causing the problem

user2989731
  • 1,299
  • 3
  • 17
  • 33
  • 2
    Is recordNum specified as string in you db or as integer? – Jens Jun 06 '14 at 14:20
  • The most obvious thing I can think of is that record 80's `fieldname` value is not `pdf`. – Digital Chris Jun 06 '14 at 14:21
  • Can you show us the Output from mysql admin too? – Jens Jun 06 '14 at 14:22
  • 1
    @Jens '112' will be converted to 112 so it doesn't matter, even though this is bad practise. – Jonast92 Jun 06 '14 at 14:23
  • Copy and paste the content of the table from your admin panel to the question. – Jonast92 Jun 06 '14 at 14:25
  • What is the exact type of `recordNum` and what is the exact value of it on your second row? Note that if it is a string and there are spaces around it, your query condition will not match. – jeroen Jun 06 '14 at 14:34
  • recordNum is set up as a string (VARCHAR255) and it doesn't seem like there are any spaces aren't the values of recordNum - I just highlighted the text, is there a better way to determine that? – user2989731 Jun 06 '14 at 14:38
  • Does SELECT * FROM `uploads` WHERE `recordNum` = '80' return the line that you want? Narrow down the problem by identifying the constraint that is filtering the row that you want. – Kevin Postlewaite Jun 07 '14 at 01:57

0 Answers0