Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
|
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 20th, 2004, 09:19 AM
Authorized User
 
Join Date: Jul 2004
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts
Default retrieving data using id.

I have a form that contains about 3 SQL calls to different tables with them all displaying the results. My last select statement which looks like:

Code:
SELECT * FROM manufacturers WHERE manufacturers_id = '$prod_id'
$prod_id is taken from another table once the selected record has been chosen. (I have tried this select statement directly into MySQL and it works like a treat but it does not seem to work on the form). Am I missing something?

This code does not seem to be working in extracting any data. I get the error message saying that there is no data in the manufacturers table. But there is data in there, all 40 rows.

I've been round this problem all yesterday and today and still no joy.
Is there a limit as to how many queries you can make on one PHP page?

Michael.
__________________
Michael.
 
Old July 20th, 2004, 10:45 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 256
Thanks: 0
Thanked 0 Times in 0 Posts
Default

What happened when you echoed your SELECT on screen before executing it? i.e.
$query = "SELECT * FROM manufacturers WHERE manufacturers_id = '$prod_id'";
echo $query;
$result=mysql_query($query);

?

How are you retrieving $prod_id? Are you sure you're not asking to retrieve SELECT * FROM manufacturers WHERE manufacturers_id = ''?

I only ask, because, no: there's no limit to the number of queries per page.

Dan
 
Old July 20th, 2004, 11:19 AM
Authorized User
 
Join Date: Jul 2004
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts
Default

When I echo the entire SELECT statement I get the following message:

Resource id #8

 
Quote:
quote:...Are you sure you're not asking to retrieve SELECT * FROM manufacturers WHERE manufacturers_id = ''?

What do you mean by this, an empty single character?

Michael.
 
Old July 20th, 2004, 11:35 AM
Authorized User
 
Join Date: Jul 2004
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I am retrieving $prod_id from the following SQL statement;

Code:
SELECT * FROM newsitems_options WHERE
newsitems_options_id = '$rec_id'
$prod_id is one of the fields in the newsitems_options table holding the manufacturers_id number.
 
Old July 20th, 2004, 11:44 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 256
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Well $result (or your equivalent of it) should be a Resource, but the querystring itself should be just a string of text. What I mean is, are you sure that $prod_id has a value, because if it hasn't PHP will swap-in '' (empty string) and you'll be searching for "manufacturers_id = ''".

By echoing the _actual_ string you are trying to execute, you'lll see if that's the case.

dan
 
Old July 21st, 2004, 03:43 AM
Authorized User
 
Join Date: Jul 2004
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi Dave,

I have outputted the results before and after the SQL statement and there is data in the $prod_id but its the actual SQL that doesnt seem to be extracting the results as required.
I dont understand!

What do you mean by a Resource?

Michael.
 
Old July 21st, 2004, 05:42 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 256
Thanks: 0
Thanked 0 Times in 0 Posts
Default

A resource is a non-simple data type that PHP is using to reference something. A resultset is a resource, for instance, because you can navigate around in it and pull data from it. The SQL statement should have just been a simple type (a string), if you echo'ed you $query (or whatever variable name you are using to store your query) and got:

Resource id #8

Then something is definitely wrong.
Dan
 
Old July 21st, 2004, 05:48 AM
Authorized User
 
Join Date: Jul 2004
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hmmm.. ic.


Michael.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Retrieving data from a Share drive Newbie19 VB.NET 2 June 26th, 2007 07:20 AM
Retrieving Data From Server x_ray Word VBA 0 June 12th, 2006 10:33 AM
Help! Retrieving data from a formview!?! FabRed VB Databases Basics 0 April 23rd, 2006 09:39 AM
URGENT:Retrieving data from the database jyoti_khera SQL Server ASP 1 October 21st, 2004 03:01 AM
retrieving data in excel from access. yesilkalem Access 1 May 25th, 2004 04:19 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.