Jump to content

Archived

This topic is now archived and is closed to further replies.

Pudgemeister

Noobie Stuff: Very Basics Explained Easily

Recommended Posts

ARG THIS IS SOO CONFUSING!

i got a mate whos a great hacker who is rackin his brains and another doing the same as hs been college n all.

god its so WEIRD!!!!!

we need sum1 uber pro here

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
[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?

Share this post


Link to post
Share on other sites
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];

Share this post


Link to post
Share on other sites
[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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
if you post your current code then we can help what's the problam p,ease cheers.

Share this post


Link to post
Share on other sites
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.

:)

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
[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.

Share this post


Link to post
Share on other sites
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 :)

Share this post


Link to post
Share on other sites
It can be a string like he had.  The problem is that he has "==" instead of "=" like it should be.  Change those double equals to single equals.  It's returning an error because of the SQL syntax.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

×

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.