mysql fetch array prob (again)
Moderator: General Moderators
mysql fetch array prob (again)
<?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?
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?
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:
instead of:
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 { }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];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
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
Hmm... what is mss? I belive row was defined on this line:
Code: Select all
$row = mysql_fetch_array($result);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
<?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
It didn't work because you never utilized your host, user, pass, etc. vars.
You forgot:
See what I mean?
You forgot:
Code: Select all
mysql_connect($dbhost, $dbuser, $dbpwd);
mysql_select_db($dbname);row not defined
$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
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
Code: Select all
SELECT * FROM mapsphpScott