Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > PHP and MySQL problems

PHP and MySQL problems
Thread Tools
Mac Enthusiast
Join Date: Jan 2001
Location: Alberta, Canada
Status: Offline
Reply With Quote
Oct 6, 2002, 02:39 PM
 
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
Reply With Quote
Oct 6, 2002, 03:51 PM
 
Instead of "=" try "=="
     
t6hawk  (op)
Mac Enthusiast
Join Date: Jan 2001
Location: Alberta, Canada
Status: Offline
Reply With Quote
Oct 6, 2002, 09:56 PM
 
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
Reply With Quote
Oct 7, 2002, 12:26 AM
 
You'll have to post more of the code, do you have a.........

SELECT * from -------- WHERE -------- = -----------

in there somewhere?
     
t6hawk  (op)
Mac Enthusiast
Join Date: Jan 2001
Location: Alberta, Canada
Status: Offline
Reply With Quote
Oct 7, 2002, 01:15 AM
 
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
Reply With Quote
Oct 20, 2002, 11:13 PM
 
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.
     
   
Thread Tools
Forum Links
Forum 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 On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 01:53 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2