timmah1 Posted November 16, 2011 Share Posted November 16, 2011 I'm working on this database that was built by somebody else, and I'm having issues with. I'm attaching a photo of the database. The problem I'm having is that even when I hard-code variables in the statement, it still brings back "Sorry, but we can not find an entry to match your query" Is there something that I'm not seeing, or something that I'm doing wrong here? You can clearly see in the photo that I'm trying to grab the info with the id_pk 300000. <?php //$search = $_POST['search']; //$search = '300000'; $data = mysql_query("SELECT * FROM page_listings WHERE id_pk = '300000'"); while($result = mysql_fetch_array( $data )) { $name = $result['page_name']; $id = $result['id_pk']; $page = $result['html']; $cat = $result['category']; $dir = $result['directory']; echo "ID: " .$id ."<br>Page: ". $name ."<br>HTML: ". $page ."<br>Category: ". $cat ."<br>Directory: ". $dir ."<br />"; } $anymatches=mysql_num_rows($data); if ($anymatches == 0) { echo "Sorry, but we can not find an entry to match your query<br><br>"; } ?> Thanks in advance [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/251267-code-does-not-return-any-results/ Share on other sites More sharing options...
Zane Posted November 16, 2011 Share Posted November 16, 2011 WHERE id_pk = '300000' Assuming id_pk is an INT field.. you should take 3000000 out of quotes. Quote Link to comment https://forums.phpfreaks.com/topic/251267-code-does-not-return-any-results/#findComment-1288742 Share on other sites More sharing options...
floridaflatlander Posted November 16, 2011 Share Posted November 16, 2011 Should it be $anymatches=mysql_num_rows($results); ? Quote Link to comment https://forums.phpfreaks.com/topic/251267-code-does-not-return-any-results/#findComment-1288745 Share on other sites More sharing options...
timmah1 Posted November 16, 2011 Author Share Posted November 16, 2011 I took the 300000 out of quotes, and still nothing $data = mysql_query("SELECT * FROM page_listings WHERE id_pk = 300000"); while($result = mysql_fetch_array( $data )) { I've never encountered this before Quote Link to comment https://forums.phpfreaks.com/topic/251267-code-does-not-return-any-results/#findComment-1288751 Share on other sites More sharing options...
floridaflatlander Posted November 16, 2011 Share Posted November 16, 2011 Can you comment out the if ($anymatches.... and see if "or die("Error: ".mysqli_error($dbc)); gives you any clues" ? Quote Link to comment https://forums.phpfreaks.com/topic/251267-code-does-not-return-any-results/#findComment-1288753 Share on other sites More sharing options...
timmah1 Posted November 16, 2011 Author Share Posted November 16, 2011 Nothing $data = mysql_query("SELECT * FROM page_listings WHERE id_pk = 300000") or die("Error: ".mysql_error($data)); while($result = mysql_fetch_array( $data )) { $name = $result['page_name']; $id = $result['id_pk']; $page = $result['html']; $cat = $result['category']; $dir = $result['directory']; echo "ID: " .$id ."<br>Page: ". $name ."<br>HTML: ". $page ."<br>Category: ". $cat ."<br>Directory: ". $dir ."<br />"; } Quote Link to comment https://forums.phpfreaks.com/topic/251267-code-does-not-return-any-results/#findComment-1288754 Share on other sites More sharing options...
PFMaBiSmAd Posted November 16, 2011 Share Posted November 16, 2011 How did the data get into that table? You likely have a white-space/non-printing character at the start of each value that won't directly match the value you are putting into the query statement. Quote Link to comment https://forums.phpfreaks.com/topic/251267-code-does-not-return-any-results/#findComment-1288757 Share on other sites More sharing options...
timmah1 Posted November 16, 2011 Author Share Posted November 16, 2011 I manually inserted it into the db through phpMyAdmin. The id was automatically inserted, so I don't believe there would be any white space Quote Link to comment https://forums.phpfreaks.com/topic/251267-code-does-not-return-any-results/#findComment-1288758 Share on other sites More sharing options...
floridaflatlander Posted November 16, 2011 Share Posted November 16, 2011 Okay, "just for me" would have to be something like this ???? while($result = mysql_fetch_array( $data ) or die("Error: ".mysql_error($data))) Quote Link to comment https://forums.phpfreaks.com/topic/251267-code-does-not-return-any-results/#findComment-1288760 Share on other sites More sharing options...
timmah1 Posted November 16, 2011 Author Share Posted November 16, 2011 Ok, doing this $data = mysql_query("SELECT * FROM page_listings WHERE id_pk = 300000"); while($result = mysql_fetch_array( $data ) or die("Error: ".mysql_error($data))) produces the word Error:, nothing else If I take the id_pk below the one in the picture, 200110, and hard-code that in, it pulls the info. I can pull info for every record in the db, expect the one I manually inserted Quote Link to comment https://forums.phpfreaks.com/topic/251267-code-does-not-return-any-results/#findComment-1288763 Share on other sites More sharing options...
Pikachu2000 Posted November 16, 2011 Share Posted November 16, 2011 You only get the word error because you were given the wrong syntax with which to use or die(). It would be used with mysql_query(), not while(). What happens if you copy the query string and paste it in to phpMyAdmin? Does it return any results? If you browse the table, is the record actually there? Quote Link to comment https://forums.phpfreaks.com/topic/251267-code-does-not-return-any-results/#findComment-1288767 Share on other sites More sharing options...
timmah1 Posted November 16, 2011 Author Share Posted November 16, 2011 the table is there, that's what the picture shows. when I paste it in phpmyadmin, I get this Showing rows 0 - 0 ( 1 total, Query took 0.0004 sec) Quote Link to comment https://forums.phpfreaks.com/topic/251267-code-does-not-return-any-results/#findComment-1288769 Share on other sites More sharing options...
Pikachu2000 Posted November 16, 2011 Share Posted November 16, 2011 What is the output of DESCRIBE page_listings? Quote Link to comment https://forums.phpfreaks.com/topic/251267-code-does-not-return-any-results/#findComment-1288772 Share on other sites More sharing options...
timmah1 Posted November 16, 2011 Author Share Posted November 16, 2011 What is the output of DESCRIBE page_listings? I don't understand what you mean? Quote Link to comment https://forums.phpfreaks.com/topic/251267-code-does-not-return-any-results/#findComment-1288775 Share on other sites More sharing options...
Pikachu2000 Posted November 16, 2011 Share Posted November 16, 2011 It's the same as the 'Structure' tab in phpMyAdmin after you navigate to that table. I had another thought. Do you have two copies of this database in use, perhaps one online and one local? If you do, are you sure you're connecting to the right one? Quote Link to comment https://forums.phpfreaks.com/topic/251267-code-does-not-return-any-results/#findComment-1288779 Share on other sites More sharing options...
timmah1 Posted November 16, 2011 Author Share Posted November 16, 2011 I don't see anywhere with Describe, after I click on the Structure tab Also, I only have one database Quote Link to comment https://forums.phpfreaks.com/topic/251267-code-does-not-return-any-results/#findComment-1288786 Share on other sites More sharing options...
Pikachu2000 Posted November 16, 2011 Share Posted November 16, 2011 The output of DESCRIBE is the same as what you have in the structure tab for the table. Quote Link to comment https://forums.phpfreaks.com/topic/251267-code-does-not-return-any-results/#findComment-1288787 Share on other sites More sharing options...
xyph Posted November 16, 2011 Share Posted November 16, 2011 mysql> DESCRIBE `events`; +-------------+-------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------------+-------------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | day_of_week | varchar(9) | NO | | NULL | | | date | varchar(20) | NO | | NULL | | +-------------+-------------+------+-----+---------+----------------+ 3 rows in set (0.12 sec) Quote Link to comment https://forums.phpfreaks.com/topic/251267-code-does-not-return-any-results/#findComment-1288790 Share on other sites More sharing options...
timmah1 Posted November 16, 2011 Author Share Posted November 16, 2011 This it? Field Type Null Key Default Extra id_pk int(11) NO PRI NULL auto_increment directory varchar(350) NO NULL page_name varchar(350) NO MUL NULL html text NO NULL category varchar(150) YES NULL Quote Link to comment https://forums.phpfreaks.com/topic/251267-code-does-not-return-any-results/#findComment-1288791 Share on other sites More sharing options...
Pikachu2000 Posted November 16, 2011 Share Posted November 16, 2011 Yeah, that's it. And now it makes even less sense, since everything there looks fine. As a last resort at diagnosing the problem, try this and see what it returns. <?php $query = "SELECT id_pk FROM page_listings ORDER BY id_pk DESC LIMIT 10"; if( $result = mysql_query($query) ) { while($array = mysql_fetch_row($result) ) { echo $array[0] . '<br>'; } } else { echo 'Error: ' . mysql_error(); } Quote Link to comment https://forums.phpfreaks.com/topic/251267-code-does-not-return-any-results/#findComment-1288793 Share on other sites More sharing options...
timmah1 Posted November 16, 2011 Author Share Posted November 16, 2011 Yeah, that's it. And now it makes even less sense, since everything there looks fine. As a last resort at diagnosing the problem, try this and see what it returns. <?php $query = "SELECT id_pk FROM page_listings ORDER BY id_pk DESC LIMIT 10"; if( $result = mysql_query($query) ) { while($array = mysql_fetch_row($result) ) { echo $array[0] . '<br>'; } } else { echo 'Error: ' . mysql_error(); } This returns the following 205950 205949 205948 205947 205946 205945 205944 205943 205942 205941 Quote Link to comment https://forums.phpfreaks.com/topic/251267-code-does-not-return-any-results/#findComment-1288794 Share on other sites More sharing options...
Pikachu2000 Posted November 16, 2011 Share Posted November 16, 2011 It appears there is no record with the id_pk of 300000 in the table after all. Perhaps you mistakenly deleted it somehow? Quote Link to comment https://forums.phpfreaks.com/topic/251267-code-does-not-return-any-results/#findComment-1288795 Share on other sites More sharing options...
timmah1 Posted November 16, 2011 Author Share Posted November 16, 2011 But there is, and the weird thing, the last 10 are as follows 200101 200102 200103 200104 200105 200106 200107 200109 200110 300000 Here is a screen shot of phpmyadmin [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/251267-code-does-not-return-any-results/#findComment-1288797 Share on other sites More sharing options...
Pikachu2000 Posted November 16, 2011 Share Posted November 16, 2011 That table has to be in a different database than the one your php script is connecting to. The query is, for all intents and purposes, the same as the one in the code I provided, but NONE of the id_pk values are the same. That's the only explanation I can think of at the moment. Quote Link to comment https://forums.phpfreaks.com/topic/251267-code-does-not-return-any-results/#findComment-1288798 Share on other sites More sharing options...
floridaflatlander Posted November 17, 2011 Share Posted November 17, 2011 and ... did you figure it out ? Quote Link to comment https://forums.phpfreaks.com/topic/251267-code-does-not-return-any-results/#findComment-1288894 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.