Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
mysql_fetch_array problemo
Old 03-08-2005, 01:12 AM mysql_fetch_array problemo
Junior Talker

Posts: 2
Location: Texas
Trades: 0
Hi, I'm new to this forum (but not really to PHP). I'm not sure if my problem is a variable problem or what, but here's the code I have:

Code:
<? 
if (isset($type)) {
$link = mysql_connect($host, $user, $pass) or die("Could not connect.");
mysql_select_db($db, $link) or die("Couldn't select database.");

$query = "SELECT * from $issue WHERE type='$type'";

$result = mysql_query($query, $link);

while ($row = mysql_fetch_array($result)) {
echo "<font size='3'><b>".$row['title']."</b></font><br>";
echo "<p align='right'>Written By: ".$row['author']."</p>";
echo $row['content'];
echo "<p>";
}
} else {
echo "Sorry, but you stumbled into the wrong area.";
}
?>
I keep recieving an error: "Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in c:\program files\apache group\apache\htdocs\yoraritard\main.html on line 18" (Line 18 is the while ($row = mysql_fetch_array($result)).)

The variable $type is passed through the browser (the address would be main.html?type=whatever).

Any suggestions?
hudster is offline
Reply With Quote
View Public Profile Visit hudster's homepage!
 
 
Register now for full access!
Old 03-08-2005, 01:52 AM
Phaedrus's Avatar
Ultra Talker

Posts: 271
Location: CA
Trades: 0
I don't see where $issue is set.
__________________

Please login or register to view this content. Registration is FREE
Phaedrus is offline
Reply With Quote
View Public Profile
 
Old 03-08-2005, 07:23 AM
Gaffer Sports's Avatar
Ultra Talker

Posts: 397
Name: Steve
Location: Scotland
Trades: 1
You will need to get the 'type' from the browser -

Code:
$type = $_GET['type'];
Secondly, I also do not see where you have set $issue as a variable. If that is not set, the query does not know what table to look at.

Steve.
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
Gaffer Sports is offline
Reply With Quote
View Public Profile Visit Gaffer Sports's homepage!
 
Old 03-08-2005, 09:21 AM
Kyrnt's Avatar
The Post-Mod Years

Posts: 2,536
Location: Western Maryland
Trades: 0
hudster, both Phaedrus and Gaffer point out good points -- $issue and $type are never set. Use print to debug your sql and also make the following call to see how many rows you are getting back:

PHP Code:
print "<p>Number of results returned by SQL query:  " mysql_num_rows$result ); 
However, if $result is not a valid mysql resource (that is, if the query failed), this call will produce the same error.
__________________
—Kyrnt
Kyrnt is offline
Reply With Quote
View Public Profile Visit Kyrnt's homepage!
 
Old 03-08-2005, 09:54 AM
Anacrusis's Avatar
Defies a Status

Posts: 2,099
Name: Adam
Location: Colchester CT
Trades: 0
I would display what $query looks like, perhaps the variables are not being set as expected or maybe there is something in there (quotes?) that may be throwing the query off
PHP Code:
$query "SELECT * from $issue WHERE type='$type'";
print 
"sql = " $query
Anacrusis is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to mysql_fetch_array problemo
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.27072 seconds with 12 queries