Current location: Hot Scripts Forums » Programming Languages » PHP » Stumped with SQL - please help.


Stumped with SQL - please help.

Reply
  #1 (permalink)  
Old 12-04-07, 04:23 PM
Sparky222B Sparky222B is offline
Newbie Coder
 
Join Date: Mar 2007
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Exclamation Stumped with SQL - please help.

I've been googling and I'm stumped.

PHP Code:

query mysql_query("SELECT Title FROM offers WHERE country LIKE '$ucountryid' ORDER BY offerid DESC");

while(
$Title mysql_fetch_row($query))
{
     
$URL mysql_query("SELECT URL FROM offers WHERE Title='$Title'");
     
$Description mysql_query("SELECT Description FROM offers WHERE Title='$Title'");
     
$price mysql_query("SELECT price FROM offers WHERE Title='$Title'");
     echo 
"<a href='".$URL."'>".$Title."</a> - ".$Description." (".$price.")<br>";
}; 
This seems to return:
Code:
Array - Resource id #32 (Resource id #33)
Array - Resource id #35 (Resource id #36)
What is going on here? Why doesn't it return the SINGLE matching result to those queries?

Last edited by Nico; 12-04-07 at 05:00 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 12-04-07, 04:25 PM
robertark's Avatar
robertark robertark is offline
Newbie Coder
 
Join Date: Dec 2007
Location: Springfield, MO
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
$Title is going to be an array more than likely. Try this:

PHP Code:

while($Title mysql_fetch_row($query))
{
/*
     $URL = mysql_query("SELECT URL FROM offers WHERE Title='$Title'");
     $Description = mysql_query("SELECT Description FROM offers WHERE Title='$Title'");
     $price = mysql_query("SELECT price FROM offers WHERE Title='$Title'");
     echo "<a href='".$URL."'>".$Title."</a> - ".$Description." (".$price.")<br>";
*/
  
print_r($Title);

You should probably call an element out of $Title, such as $Title['element1'], $Title['element2'], etc.

To clarify things, look in your table (whatever the table is being queried with $query above) and see what columns there are. Each column will be the actual 'element' - Sorry if I'm confusing you heh
__________________
Knowledge Is Power And Without Power, You're Nobody. -Self

Last edited by robertark; 12-04-07 at 04:32 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 12-04-07, 04:37 PM
Sparky222B Sparky222B is offline
Newbie Coder
 
Join Date: Mar 2007
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
That fixes the titles being echoed ($Title[0], etc), but the URL and other mysql_query lines still return Resource #s.

PHP Code:

while($Title mysql_fetch_row($query))
{
    
$Title2=$Title[0];
     
$URL mysql_query("SELECT URL FROM offers WHERE Title='$Title2'");
     
$Description mysql_query("SELECT Description FROM offers WHERE Title='$Title2'");
     
$price mysql_query("SELECT price FROM offers WHERE Title='$Title2'");
     echo 
"<a href='".$URL."'>".$Title2."</a> - ".$Description." (".$price.")<br>";
}; 
Code:
Ringtone Download - Resource id #32 (Resource id #33)
Test Offer - Resource id #35 (Resource id #36)
Quote:
Sorry if I'm confusing you heh
HAO I USE ARAYS? Seriously, come on.

Last edited by Nico; 12-04-07 at 05:00 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 12-04-07, 04:42 PM
robertark's Avatar
robertark robertark is offline
Newbie Coder
 
Join Date: Dec 2007
Location: Springfield, MO
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
PHP Code:

print_r($Description);
print_r($price); 
Print your results and see what they are, if that fails, try var_dump();
__________________
Knowledge Is Power And Without Power, You're Nobody. -Self
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 12-04-07, 04:44 PM
Sparky222B Sparky222B is offline
Newbie Coder
 
Join Date: Mar 2007
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Yeah, it occured to me - they dump as
Code:
 resource(34) of type (mysql result) NULL
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 12-04-07, 04:49 PM
robertark's Avatar
robertark robertark is offline
Newbie Coder
 
Join Date: Dec 2007
Location: Springfield, MO
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Without knowing your MySQL table setup, it's a pain to figure out where the problem may be coming from. Your PHP is right, however, go through your MySQL tables and confirm that each column you're calling (Description, Price, etc) actually exists and is non-null.
__________________
Knowledge Is Power And Without Power, You're Nobody. -Self
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #7 (permalink)  
Old 12-04-07, 04:51 PM
robertark's Avatar
robertark robertark is offline
Newbie Coder
 
Join Date: Dec 2007
Location: Springfield, MO
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
What is your $query (in the while loop) - Show me that first, please
__________________
Knowledge Is Power And Without Power, You're Nobody. -Self
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #8 (permalink)  
Old 12-04-07, 04:55 PM
Sparky222B Sparky222B is offline
Newbie Coder
 
Join Date: Mar 2007
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
They all exist and are non-null. Query is
PHP Code:

$query mysql_query("SELECT Title FROM offers WHERE country LIKE '$ucountryid' ORDER BY offerid DESC"); 

Nico: No SQL error is given; the query executes successfully, just doesn't return right.

Table creation structure:
sql Code:
  1. CREATE TABLE `offers` (
  2.   `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
  3.   `date` varchar(255) NOT NULL DEFAULT '',
  4.   `Title` varchar(255) NOT NULL DEFAULT '',
  5.   `URL` varchar(255) NOT NULL DEFAULT '',
  6.   `Country` varchar(200) NOT NULL DEFAULT '',
  7.   `Description` varchar(255) NOT NULL DEFAULT '',
  8.   `price` varchar(255) NOT NULL DEFAULT '',
  9.   `offerid` text,
  10.   PRIMARY KEY  (`id`)
  11. ) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=90 ;

Last edited by Nico; 12-04-07 at 05:01 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #9 (permalink)  
Old 12-04-07, 04:57 PM
End User's Avatar
End User End User is offline
Level II Curmudgeon
 
Join Date: Dec 2004
Posts: 3,027
Thanks: 14
Thanked 35 Times in 33 Posts
Quote:
Originally Posted by Sparky222B View Post
HAO I USE ARAYS? Seriously, come on.
Here is how you use arrays:

http://us2.php.net/array
__________________
I don't live on the edge, but sometimes I go there to visit.
-------------------------------------------------------------------------
Sanitize Your Data | Oracle Date & Substring Functions | Code Snippet Library | [url=http://www.codmb.com/Call Of Duty[/url]

Last edited by End User; 12-04-07 at 05:00 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #10 (permalink)  
Old 12-04-07, 04:59 PM
robertark's Avatar
robertark robertark is offline
Newbie Coder
 
Join Date: Dec 2007
Location: Springfield, MO
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by Sparky222B View Post
They all exist and are non-null. Query is
Code:
$query = mysql_query("SELECT Title FROM offers WHERE country LIKE '$ucountryid' ORDER BY offerid DESC");
Nico: No SQL error is given; the query executes successfully, just doesn't return right.

Table creation structure:
Code:
CREATE TABLE `offers` (
  `id` int(10) unsigned NOT NULL auto_increment,
  `date` varchar(255) NOT NULL default '',
  `Title` varchar(255) NOT NULL default '',
  `URL` varchar(255) NOT NULL default '',
  `Country` varchar(200) NOT NULL default '',
  `Description` varchar(255) NOT NULL default '',
  `price` varchar(255) NOT NULL default '',
  `offerid` text,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=90 ;
Try this:

PHP Code:

$query mysql_query("SELECT * FROM offers WHERE country LIKE '$ucountryid' ORDER BY offerid DESC") or die(mysql_error());
while(
$row mysql_fetch_assoc($query)) {
  
print_r($row);

Then from there, you could do something like:

PHP Code:

$query mysql_query("SELECT * FROM offers WHERE country LIKE '$ucountryid' ORDER BY offerid DESC") or die(mysql_error());
while(
$row mysql_fetch_assoc($query)) {
  
$date $row['date'];
  
$Title $row['Title'];
  
$URL $row['URL'];
  
$Country $row['Country'];
  
$Description $row['Description'];
  
$price $row['price'];
  
$offerId $row['offerid'];

  
# Echo accordingly...

Is this what you're trying to do?
__________________
Knowledge Is Power And Without Power, You're Nobody. -Self

Last edited by robertark; 12-04-07 at 05:01 PM. Reason: SELECT * FROM offers
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
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 On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
ERROR: ResultSet not open, operation 'next' not permitted. Verify that autocommit is qirana Everything Java 2 04-14-07 05:06 AM
2 Months Free Hosting -Windows 2003 | Cold Fusion MX | SQL Server | ASP.NET Gineey General Advertisements 0 01-11-06 06:31 AM
Help with ASP & FORMS blessedrub ASP 0 01-23-04 11:22 AM
ASP Calendar..HELP...pls jimthepict ASP 1 07-31-03 06:01 PM
change my field in this example sal21 ASP 3 07-14-03 03:49 AM


All times are GMT -5. The time now is 12:48 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.