 |
 |
PHP and MySQL problems
|
 |
|
 |
|
Mac Enthusiast
Join Date: Jan 2001
Location: Alberta, Canada
Status:
Offline
|
|
I'm just learning PHP and I've run into a problem. I'm trying to get PHP to pull data out of a MySQL database and insert it on the page. I've followed the tutorials I found and I keep getting errors with the following line:
while ($myrow = mysql_fetch_row($result)) {
Error: Warning: Supplied argument is not a valid MySQL result resource in /home/...../file.php on line 31
Some of the tutorials are from: WebMonkey and the one main other is from Books24x7.com
I've tried using other tutorials from other sources also and they get stuck in the same spot even if using the mysql_fetch_array tag instead. Any help would be greatly appreciated.
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Mar 2002
Location: Clogland
Status:
Offline
|
|
|
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Enthusiast
Join Date: Jan 2001
Location: Alberta, Canada
Status:
Offline
|
|
Originally posted by skalie:
Instead of "=" try "=="
Didn't work. Just caused the code to loop and repeat the error endlessly.

|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Mar 2002
Location: Clogland
Status:
Offline
|
|
You'll have to post more of the code, do you have a.........
SELECT * from -------- WHERE -------- = -----------
in there somewhere?
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Enthusiast
Join Date: Jan 2001
Location: Alberta, Canada
Status:
Offline
|
|
Originally posted by skalie:
You'll have to post more of the code, do you have a.........
SELECT * from -------- WHERE -------- = -----------
in there somewhere?
I finally got the script working.
Here is the entire script. I want to be able to have the script call specific tags such as: test.php?id=x or test.php?area=x
I can't get that to work. TIA.
<html>
<body>
(?php
$db = mysql_connect("localhost", "username", "passwd");
mysql_select_db("database",$db);
$result = mysql_query("SELECT * FROM acpo",$db);
if ($myrow = mysql_fetch_array($result)) {
echo "<table border=0 width=600>\n";
echo "<tr><td>Country</td><td>Area</td><td>Title</td><td>Date</td></tr>\n";
do {
printf("<tr><td><center><img src=\"news/%s.jpg\"></center></td><td>%s</td><td><a href=\"%s\">%s</a></td><td>%s</td></tr>\n", $myrow["country"], $myrow["area"], $myrow["url"], $myrow["title"], $myrow["date"]);
} while ($myrow = mysql_fetch_array($result));
echo "</table>\n";
} else {
echo "Sorry, no records were found!";
}
?>
(Last edited by t6hawk; Oct 7, 2002 at 02:05 AM.
)
|
|
|
| |
|
|
|
 |
|
 |
|
Junior Member
Join Date: Nov 1999
Status:
Offline
|
|
Okay, a couple things. Skalie's suggestion didn't work because '==' is a comparison operator, and '=' is a variable loading operator. In other words, you're putting a value into $result, so you have to use '='. You put a new value into $result each time through the loop, because each call to mysql_fetch_array does just that -- it fetches 1 row.
Now, you say you want the script to be able to call specific tags. I'm not certain what that means. If it means that you want the script to interact with variables in the URL, then you're going to need to get the data from something called PHP globals. $GLOBALS['PHP_GET_VARS'] is an array of all the var/key pairs in your URL. (to use your example, one of these would be $GLOBALS['PHP_GET_VARS']['id'] == 'x', evaluating to TRUE)
If you clarify, I can help.
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|