Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 20th, 2004, 09:19 AM
Authorized User
 
Join Date: Jul 2004
Location: , , .
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.
Reply With Quote
  #2 (permalink)  
Old July 20th, 2004, 10:45 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , United Kingdom.
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
Reply With Quote
  #3 (permalink)  
Old July 20th, 2004, 11:19 AM
Authorized User
 
Join Date: Jul 2004
Location: , , .
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.
Reply With Quote
  #4 (permalink)  
Old July 20th, 2004, 11:35 AM
Authorized User
 
Join Date: Jul 2004
Location: , , .
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.
Reply With Quote
  #5 (permalink)  
Old July 20th, 2004, 11:44 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , United Kingdom.
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
Reply With Quote
  #6 (permalink)  
Old July 21st, 2004, 03:43 AM
Authorized User
 
Join Date: Jul 2004
Location: , , .
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.
Reply With Quote
  #7 (permalink)  
Old July 21st, 2004, 05:42 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , United Kingdom.
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
Reply With Quote
  #8 (permalink)  
Old July 21st, 2004, 05:48 AM
Authorized User
 
Join Date: Jul 2004
Location: , , .
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hmmm.. ic.


Michael.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 01:05 AM.


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