Jump to content

Recommended Posts

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]

Link to comment
https://forums.phpfreaks.com/topic/251267-code-does-not-return-any-results/
Share on other sites

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 />";
}

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

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?

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?

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)

 

 

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();
}

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

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.