Jump to content


Photo

Noobie Stuff: Very Basics Explained Easily


  • Please log in to reply
117 replies to this topic

#101 Pudgemeister

Pudgemeister
  • Members
  • PipPipPip
  • Advanced Member
  • 94 posts
  • LocationCornwall, England, UK,

Posted 14 August 2006 - 06:42 PM

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
[div align="center"][a href="http://imageshack.us" target="_blank"][/a]
[/div]

#102 GingerRobot

GingerRobot
  • Staff Alumni
  • Advanced Member
  • 4,086 posts
  • LocationUK

Posted 14 August 2006 - 07:20 PM

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.



#103 Pudgemeister

Pudgemeister
  • Members
  • PipPipPip
  • Advanced Member
  • 94 posts
  • LocationCornwall, England, UK,

Posted 14 August 2006 - 10:59 PM

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.


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?
[div align="center"][a href="http://imageshack.us" target="_blank"][/a]
[/div]

#104 GingerRobot

GingerRobot
  • Staff Alumni
  • Advanced Member
  • 4,086 posts
  • LocationUK

Posted 15 August 2006 - 08:37 AM

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];

#105 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 15 August 2006 - 11:44 AM

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.

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.

#106 Pudgemeister

Pudgemeister
  • Members
  • PipPipPip
  • Advanced Member
  • 94 posts
  • LocationCornwall, England, UK,

Posted 15 August 2006 - 12:39 PM

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
[div align="center"][a href="http://imageshack.us" target="_blank"][/a]
[/div]

#107 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 15 August 2006 - 01:13 PM

if you post your current code then we can help what's the problam p,ease cheers.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#108 ThEMakeR

ThEMakeR
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 15 August 2006 - 01:16 PM

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.

:)

#109 Pudgemeister

Pudgemeister
  • Members
  • PipPipPip
  • Advanced Member
  • 94 posts
  • LocationCornwall, England, UK,

Posted 15 August 2006 - 03:08 PM

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:

<?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'];
}
?>

[div align="center"][a href="http://imageshack.us" target="_blank"][/a]
[/div]

#110 GingerRobot

GingerRobot
  • Staff Alumni
  • Advanced Member
  • 4,086 posts
  • LocationUK

Posted 15 August 2006 - 09:22 PM

Like i said, remove the quotes:
<?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'];
}
?>

Ive no idea why/if it would cause a rogue character, but its certainly not correct to have these functions inside quotes

#111 nethnet

nethnet
  • Members
  • PipPipPip
  • Advanced Member
  • 284 posts
  • LocationPhiladelphia, PA, USA

Posted 16 August 2006 - 06:05 AM

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
"Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep."  --Scott Adams

Current project: nethnet.com

#112 Pudgemeister

Pudgemeister
  • Members
  • PipPipPip
  • Advanced Member
  • 94 posts
  • LocationCornwall, England, UK,

Posted 16 August 2006 - 05:03 PM

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:

<?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'];
}
?>

[div align="center"][a href="http://imageshack.us" target="_blank"][/a]
[/div]

#113 simcoweb

simcoweb
  • Members
  • PipPipPip
  • Advanced Member
  • 1,102 posts
  • LocationCA

Posted 16 August 2006 - 05:19 PM

Your query line needs brackets. Like this:

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

Otherwise it thinks it's a string. It's not recognizing it as a valid query.

#114 Daniel0

Daniel0
  • Staff Alumni
  • Advanced Member
  • 11,956 posts

Posted 16 August 2006 - 05:26 PM

Your query line needs brackets. Like this:

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

Otherwise it thinks it's a string. It's not recognizing it as a valid query.


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.

#115 simcoweb

simcoweb
  • Members
  • PipPipPip
  • Advanced Member
  • 1,102 posts
  • LocationCA

Posted 16 August 2006 - 05:44 PM

Ok, I see that and it is a 'string' being passed. Perhaps if he changed this code a bit to:

<?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'];
}
?>

so the 'mysql_query' is set in that string. Just trying to help :)

#116 nethnet

nethnet
  • Members
  • PipPipPip
  • Advanced Member
  • 284 posts
  • LocationPhiladelphia, PA, USA

Posted 17 August 2006 - 01:04 AM

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.
"Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep."  --Scott Adams

Current project: nethnet.com

#117 Pudgemeister

Pudgemeister
  • Members
  • PipPipPip
  • Advanced Member
  • 94 posts
  • LocationCornwall, England, UK,

Posted 17 August 2006 - 10:31 AM

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
[div align="center"][a href="http://imageshack.us" target="_blank"][/a]
[/div]

#118 psychohagis

psychohagis
  • Members
  • PipPipPip
  • Advanced Member
  • 80 posts

Posted 05 January 2007 - 07:51 PM

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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users