Jump to content

Recommended Posts

  • Replies 117
  • Created
  • Last Reply

Top Posters In This Topic

Err, well i dont quite know why it would echo an 'M' But you are saying that $row = something or other, inside of quotes, which wont work, so this:
$row = 'mysql_fetch_assoc($result_1)';
should be:
$row =mysql_fetch_assoc($result_1);

Oh, and drop the rubbish about protecting your secret project. If you want help you have to be willing to tell people what you are trying to achieve and give all the information.

[quote]
Oh, and drop the rubbish about protecting your secret project. If you want help you have to be willing to tell people what you are trying to achieve and give all the information.
[/quote]

yeh ur right-theres just a few peeps i dont want finding out and they know i use this site alot.

ok thanx for ur hep il try both those waysn and report back.

what does fetch assoc do neway?
If you specify no parameters for mysql_fetch_array() It returns both a numerically indexed and an associative array,for example, if you were to have a table with 2 fields, id and name, itwould return:

$row[id];
$row[name];
$row[0];
$row[1];

This is obviously quite inneffiecent as it is larger and takes longer. With mysql_fetch_array you can specify to only return a numberically indexed array or an associative array. A numerically indexed array is the most efficient and quickest, but it can be hard to remember what all the numbers relate to. Using the parameter to return an associative array is basically the same as mysql_fetch_array(); Which is probably the best option for most people. So mysql_fetch_array() would return:

$row[id];
$row[name];
[quote author=businessman332211 link=topic=102480.msg415949#msg415949 date=1155618854]
By what I have heard(and tested) it's simply a less reliable form of mysql_fetch_array  assoc is meant more for object oriented programming, and really nothing else.  ANd mysql_fetch_array will do just as good at oop, as assoc.
[/quote]
WFT! I suggest you go and read the manual. mysql_fetch_assoc is the same as mysql_fetch_array. Excepty it returns an associative array, rather than two lots of the same results which is an array with associative and number indices. How is it less reliable than mysql_fetch_array? Also mysql_fetch_array or mysql_fetch_assosc has nothing to do with OOP.
look guys-the switching between array and assoc didnt do nething-il leave u to argue about it.

ginger robot: im slightly confused about what you are saying, any way u cud edit my code and put what u sed into action into it so i can see and uderstand for myself?

cheers

Pudgemeister
For too long I have used scripts kindly donated from php webmasters to get my website like I want. However, from now on I'm gonna work my ass off to get as good as the coders who donate there work. Everyone who doesnt bother to work, like I used too, should stop crying there eyes out with frustration and start to learn and read through the documentation provided by php.net.

:)
thanx for that but this site is here for help, not hinderence or people crying supposedly.

neway yeh the current code for the page that displays level m is:

island_home.php:

[code]
<?php
session_start();
if(empty($_SESSION['username']) or empty($_SESSION['id']) or empty($_SESSION['password'])) {//if there is nothing in the session
echo 'you are not logged in';
exit;//quit the page so they cant view anything else
}else{
echo 'You Are Now Logged In ';
echo $username;
echo '.';
include ('dbinfo.inc.php');
$sql_1 = "SELECT * FROM user_buildings WHERE username == '$username' AND password == '$password'";
$result_1 = mysql_query($sql_1);
$num_1 = 'mysql_num_rows($result_1)';
$row_1 = 'mysql_fetch_assoc($result_1)';
echo '<br><a href="buildings/mining_depot.php"><img src="images/buildings/mining_depot.png" alt="Mining Depot"></a>';
echo '<br>Level ';
echo $row_1['mining_depot'];
}
?>
[/code]
Like i said, remove the quotes:
[code]
<?php
session_start();
if(empty($_SESSION['username']) or empty($_SESSION['id']) or empty($_SESSION['password'])) {//if there is nothing in the session
echo 'you are not logged in';
exit;//quit the page so they cant view anything else
}else{
echo 'You Are Now Logged In ';
echo $username;
echo '.';
include ('dbinfo.inc.php');
$sql_1 = "SELECT * FROM user_buildings WHERE username == '$username' AND password == '$password'";
$result_1 = mysql_query($sql_1);
$num_1 = mysql_num_rows($result_1);//here
$row_1 = mysql_fetch_assoc($result_1);//and here
echo '<br><a href="buildings/mining_depot.php"><img src="images/buildings/mining_depot.png" alt="Mining Depot"></a>';
echo '<br>Level ';
echo $row_1['mining_depot'];
}
?>
[/code]

Ive no idea why/if it would cause a rogue character, but its certainly not correct to have these functions inside quotes
Like GingerRobot said, your functions should not be in quotes.  What you are doing, essentially, is setting $num_1 and $row_1 equal to strings, not the functions you wish to perform.  So if you were to echo $row_1, the output would be "mysql_fetch_assoc($result_1)".  Then, you attempt to echo $row_1 as if it were an array (by using the key 'mining_depot').  This would work if $row_1 were an array, but it's a string as you have it, and when you try to echo a string using a key you get different results.  For example:

$string = "Random string";

echo $string[0];
echo $string[1];
echo $string[2];

echo $string[7];

You would get:

"ran " (because you are echoing the letter in slot 0, 1, 2, and then 7 [the space]).  You are using a word as your key, "mining_depot", and therefore you are telling PHP to "echo the letter amonst string $row_1 in slot number 'mining_depot'".  As you can tell, this doesn't make sense, and PHP is outputting an 'm' instead.  The reason why the m is showing up is because PHP is automatically converting the string 'mining_depot' to an integer (PHP does this when you provide a string when only an integer may be used).  When telling PHP to echo a letter in a string like you are doing, only an integer may be used, and 'mining_depot' is being converted to 0.  PHP.net will give you good information on type changes like this (string to integer in our case).  The 0 is then being used as the slot number, and that letter happens to be 'm' (because that's the first letter in "mysql_fetch_assoc($result_1)").

So, yeah, take those quotes off and it should work.  I just wanted you to get a better understanding of what was happening.

Good luck!

nethnet
You Are Now Logged In Pudgemeister.
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/pudgesuk/public_html/game_testing/island_home.php on line 13

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/pudgesuk/public_html/game_testing/island_home.php on line 14

thats the error i get when taking them outof the single quote marks-the code looks like this now:

[code]
<?php
session_start();
if(empty($_SESSION['username']) or empty($_SESSION['id']) or empty($_SESSION['password'])) {//if there is nothing in the session
echo 'you are not logged in';
exit;//quit the page so they cant view anything else
}else{
echo 'You Are Now Logged In ';
echo $username;
echo '.';
include ('dbinfo.inc.php');
$sql_1="SELECT * FROM user_buildings WHERE username == '$username' AND password == '$password'";
$result_1=mysql_query($sql_1);
$num_1=mysql_num_rows($result_1);
$row_1=mysql_fetch_array($result_1);
echo '<br><a href="buildings/mining_depot.php"><img src="images/buildings/mining_depot.png" alt="Mining Depot"></a>';
echo '<br>Level ';
echo $row_1['mining_depot'];
}
?>
[/code]
Your query line needs brackets. Like this:

[code]$sql_1=("SELECT * FROM user_buildings WHERE username == '$username' AND password == '$password'");[/code]

Otherwise it thinks it's a string. It's not recognizing it as a valid query.
[quote author=simcoweb link=topic=102480.msg416931#msg416931 date=1155748790]
Your query line needs brackets. Like this:

[code]$sql_1=("SELECT * FROM user_buildings WHERE username == '$username' AND password == '$password'");[/code]

Otherwise it thinks it's a string. It's not recognizing it as a valid query.
[/quote]

Incorrect. You are as a matter of fact defining a string and when passing the query argument to the function you are passing a string.
Ok, I see that and it is a 'string' being passed. Perhaps if he changed this code a bit to:

[code]<?php
session_start();
if(empty($_SESSION['username']) or empty($_SESSION['id']) or empty($_SESSION['password'])) {//if there is nothing in the session
echo 'you are not logged in';
exit;//quit the page so they cant view anything else
}else{
echo 'You Are Now Logged In ';
echo $username;
echo '.';
include ('dbinfo.inc.php');
$sql_1=mysql_query("SELECT * FROM user_buildings WHERE username == '$username' AND password == '$password'");
$result_1=($sql_1);
$num_1=mysql_num_rows($result_1);
$row_1=mysql_fetch_array($result_1);
echo '<br><a href="buildings/mining_depot.php"><img src="images/buildings/mining_depot.png" alt="Mining Depot"></a>';
echo '<br>Level ';
echo $row_1['mining_depot'];
}
?>[/code]

so the 'mysql_query' is set in that string. Just trying to help :)
nethnet-right on all acounts.

that rouge m was because of what you said a few posts above and the double equals sign i forgot i had put in there has fixed the error im getting.

the page runs normally now-and that rouge m has dissapeared and is finally displaying only numbers that are in the database.

thank you all-u were ver helpful...and amusing in ur dissagreements hehehe

cheers

Pudgemeister
  • 4 months later...
I agree with whoever said "If youve been learning for a year and you dont know this stuff, then you havent applied yourself"

Ive been learning for about four months and although im not fluent, im farely confident, and i actually know what those things are
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.