Page 1 of 2
mysql fetch array prob (again)
Posted: Sat Aug 16, 2003 10:28 pm
by weasel
<?php
include('config.php');
$result = mysql_query("SELECT name, mname, discription FROM maps where id = 1");
$row = mysql_fetch_array($result);
$name = $row["name"];
$mname = $row["mname"];
$dis = $row["discription"];
echo $row[name];
echo $row[mname];
echo $row[discription];
?>
<table>
<tr>
<td>
map name:
</td>
<td>
<?php echo $row["mname"]; ?>
</td>
</tr>
<tr>
<td>
Map creator:
</td>
<td>
<?php echo $row["name"]; ?>
</td>
</tr>
</table>
this is the code im using... and i get this error
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/triggerh/public_html/maps/layout.php on line 6
any help please?
Posted: Sat Aug 16, 2003 11:57 pm
by nigma
First off: Does config.php connect you to the mySQL server and select the correct database for you? If it doesn't you will need to do that.
Second:
Try this:
Code: Select all
$result = mysql_query("select name, mname, discription from maps where id='1'");
if ($result)
{
$row = mysql_fetch_array($result);
$name = $rowї"name"];
$mname = $rowї"mname"];
$dis = $rowї"discription"];
echo $name;
echo $mname;
echo $dis;
}
else { }
instead of:
Code: Select all
$result = mysql_query("SELECT name, mname, discription FROM maps where id = 1");
$row = mysql_fetch_array($result);
$name = $rowї"name"];
$mname = $rowї"mname"];
$dis = $rowї"discription"];
echo $rowїname];
echo $rowїmname];
echo $rowїdiscription];
Posted: Sun Aug 17, 2003 11:31 am
by weasel
this is what the table looks like....
id name mname discription dllink
1 sleepwalker test.bms test discription
http://testlink.com
the id was hopfully for the map and have it auto increase by 1... (to easily add more maps)
ok... if your wondering... this is what im trying to do...(ill just copy and past from where i posted this on mss...
1. User registration/login
2. User upload(to upload there maps, and assign them info)(only be abil to upload .zip and .bms, .bms is the file type that novalogic uses for its maps)
3. An admin approval system(to make sure no one enters abusive content for map info)
4. an easy to use rating system
5. must be logged in to vote
6. posibly use phpBB table(so people can just use the forum to register, and be abil to add/vote on maps)(this being an option)
7. has 20 or so maps per page
8. when it reaches 20 maps per page it makes a new page, and has like a ... <| 1 2 3 |> type of a deal...
9. can sort between the diffrent map types (tdm, dm, tkoth, koth, ctf, a&d) and im sure thers a few more im missing...
and i would like for it to read the info out of a mysql table...
so far i have the user log in, and the news system...
and working on the map view/download/rating page...(thats what this will be)
well thx for any help
Posted: Sun Aug 17, 2003 11:55 am
by nigma
Did my code not work?
Posted: Sun Aug 17, 2003 12:51 pm
by weasel
nope, a guy from mss said that $row wasent defined... whatever that means

Posted: Sun Aug 17, 2003 12:56 pm
by nigma
Hmm... what is mss? I belive row was defined on this line:
Code: Select all
$row = mysql_fetch_array($result);
Posted: Sun Aug 17, 2003 12:58 pm
by weasel
ok... instead of using the include config.php... i put this
<?php
$dbhost = "localhost"; // host name, usually localhost
$dbuser = "triggerh_maps"; // username used to login
$dbpwd = "maps"; // password used to login
$dbname = "triggerh_THCSTATS"; // the name of your database
$result = mysql_query("select name, mname, discription from maps");
if ($result)
{
$row = mysql_fetch_array($result);
$name = $row["name"];
$mname = $row["mname"];
$dis = $row["discription"];
echo $name;
echo $mname;
echo $dis;
}
else { }
?>
<table>
<tr>
<td>
map name:
</td>
<td>
<?php echo $row["mname"]; ?>
</td>
</tr>
<tr>
<td>
Map creator:
</td>
<td>
<?php echo $row["name"]; ?>
</td>
</tr>
</table>
i diddent get any errors, but it diddent work...
heres there link
http://triggerhappycheaters.com/maps/layout1.php
Posted: Sun Aug 17, 2003 1:00 pm
by nigma
It didn't work because you never utilized your host, user, pass, etc. vars.
You forgot:
Code: Select all
mysql_connect($dbhost, $dbuser, $dbpwd);
mysql_select_db($dbname);
See what I mean?
row not defined
Posted: Sun Aug 17, 2003 1:07 pm
by phpScott
$row isn't defined because there is more then likely a problem with you query.
If you have access to phpMyAdmin cut and paste the query in there to see if it comes up with a error as it will tell you.
Another thing to watch for is capitalization in your query. If table names or columns are using capitals then your query must as well.
-------->OK capitalization must be correct on unix systems and windows is
more forgiving.
If none of those work then try to do a really basic search like
or something to see if there is any results coming from the table.
phpScott
Posted: Sun Aug 17, 2003 1:08 pm
by nigma
Scott < He didn't even connect to the dbase. Isn't that why $row wasn't defined?
Posted: Sun Aug 17, 2003 1:10 pm
by weasel
!!! ty very much!
so i dont need the
$dbhost = "localhost"; // host name, usually localhost
$dbuser = "triggerh_maps"; // username used to login
$dbpwd = "maps"; // password used to login
$dbname = "triggerh_THCSTATS"; // the name of your database
then?
Posted: Sun Aug 17, 2003 1:11 pm
by nigma
You don't need if you don't plan on using those variables to connect to the dbase? Those variables do nothing if not used somewhere. You used them nowhere.
Posted: Sun Aug 17, 2003 1:13 pm
by weasel
alright, thx a lot for the help and fast replys
Posted: Sun Aug 17, 2003 1:14 pm
by nigma
.... did it work? ...
Posted: Sun Aug 17, 2003 1:29 pm
by weasel
yep, thx a lot!