help with PHP / MySQL search results..

  RicScott 10:11 29 Jul 2006

I recently designed a php/MySQL web site. The database has 3 tables. properties, pages and users.
The data stored in the pages table displays fine, the Users table also works great. Now..
When I am trying to display the contents of the properties table, all goes PT.
I get errors on the page, if I silence the errors using '@' I obviously get a null return.
However, if I change the query to read from the pages table, then I get a perfect result, no problems.
The only problem is, I don't want to view the pages table where the properties are supposed to be!!..

If I put:
$query = "SELECT COUNT(*) FROM properties ORDER BY pageID ASC";

I get an error return on these lines:
$row = mysql_fetch_array ($result, MYSQL_NUM);
while ($row = mysql_fetch_array($result, MYSQL_ASSOC))

mysql_free_result ($result);

I have stripped the properties table right down to only having the primary key row in the table and it stilldoes it, but if I change the query over to pages, it displays fine and behaves as it should..

Am I doing something wrong or missing something out??
If I go into MySQL prompt, type in SELECT * FROM properties;
I get the result that I need on the pages, so I know that the DB is fine.


  harristweed 12:53 29 Jul 2006

If your counting why do you need "ORDER BY pageID ASC"


$query = "SELECT COUNT(*) as Num FROM properties ";

  RicScott 13:35 29 Jul 2006

Thanks for that HT..
Another I eventually figured out was to ORDER BY the primary key.. that seemed to work too...

All I need to do now is figure out a way of displaying the images from the DB...that's another story..

  harristweed 13:47 29 Jul 2006

How are you storing the images?

I assume they are uplaoded to a folder on the site ( I can't believe your storing them as binary in the db!)

How i do it is when you upload the pictures, rename them to include the primary key (auto number from the database)

Then all you need to do is link using the new name.

See an example: click here

  RicScott 14:06 29 Jul 2006

I was thinking of using binary...but seeing as you've siad that..

I have got a folder on the site for the property images etc already..

Just figuring it all out...having made the move from designer to's a completely different ball game..

All I used to do is design the pages..the developers handled all this I know why..

  harristweed 15:22 29 Jul 2006

welcome to the real world.

If you store jpg files as binary in your database, you will soon exceed your allowed space (usually limited to 10% of your disc space) Not to mention all the other problems.....

Heres how you get the last primary_key ( of whatever you have named it) from the database.

if ($lastid=mysql_insert_id($link_id));
$select = "SELECT primary_key FROM property WHERE primary_key = '$lastid'";
$results = mysql_query("$select", $link_id);
$query_data = mysql_fetch_row($results);
$key = $query_data[0];

Good luck!

  RicScott 15:09 30 Jul 2006

Thanks again...

This thread is now locked and can not be replied to.

Elsewhere on IDG sites

Dell XPS 13 9370 (2018) review

No need to scan sketches into your computer with Moleskine's new smart pen

How to use 3D Touch on iPhone

Comment importer des contacts d’un iPhone à un autre iPhone ?