Pudgemeister Posted August 14, 2006 Author Share Posted August 14, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/16137-noobie-stuff-very-basics-explained-easily/page/5/#findComment-74691 Share on other sites More sharing options...
GingerRobot Posted August 14, 2006 Share Posted August 14, 2006 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 Link to comment https://forums.phpfreaks.com/topic/16137-noobie-stuff-very-basics-explained-easily/page/5/#findComment-74704 Share on other sites More sharing options...
Pudgemeister Posted August 14, 2006 Author Share Posted August 14, 2006 [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? Quote Link to comment https://forums.phpfreaks.com/topic/16137-noobie-stuff-very-basics-explained-easily/page/5/#findComment-74804 Share on other sites More sharing options...
GingerRobot Posted August 15, 2006 Share Posted August 15, 2006 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 Link to comment https://forums.phpfreaks.com/topic/16137-noobie-stuff-very-basics-explained-easily/page/5/#findComment-74979 Share on other sites More sharing options...
wildteen88 Posted August 15, 2006 Share Posted August 15, 2006 [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. Quote Link to comment https://forums.phpfreaks.com/topic/16137-noobie-stuff-very-basics-explained-easily/page/5/#findComment-75045 Share on other sites More sharing options...
Pudgemeister Posted August 15, 2006 Author Share Posted August 15, 2006 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?cheersPudgemeister Quote Link to comment https://forums.phpfreaks.com/topic/16137-noobie-stuff-very-basics-explained-easily/page/5/#findComment-75068 Share on other sites More sharing options...
redarrow Posted August 15, 2006 Share Posted August 15, 2006 if you post your current code then we can help what's the problam p,ease cheers. Quote Link to comment https://forums.phpfreaks.com/topic/16137-noobie-stuff-very-basics-explained-easily/page/5/#findComment-75084 Share on other sites More sharing options...
ThEMakeR Posted August 15, 2006 Share Posted August 15, 2006 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. :) Quote Link to comment https://forums.phpfreaks.com/topic/16137-noobie-stuff-very-basics-explained-easily/page/5/#findComment-75085 Share on other sites More sharing options...
Pudgemeister Posted August 15, 2006 Author Share Posted August 15, 2006 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]<?phpsession_start();if(empty($_SESSION['username']) or empty($_SESSION['id']) or empty($_SESSION['password'])) {//if there is nothing in the sessionecho '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] Quote Link to comment https://forums.phpfreaks.com/topic/16137-noobie-stuff-very-basics-explained-easily/page/5/#findComment-75158 Share on other sites More sharing options...
GingerRobot Posted August 15, 2006 Share Posted August 15, 2006 Like i said, remove the quotes:[code]<?phpsession_start();if(empty($_SESSION['username']) or empty($_SESSION['id']) or empty($_SESSION['password'])) {//if there is nothing in the sessionecho '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 hereecho '<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 Quote Link to comment https://forums.phpfreaks.com/topic/16137-noobie-stuff-very-basics-explained-easily/page/5/#findComment-75333 Share on other sites More sharing options...
nethnet Posted August 16, 2006 Share Posted August 16, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/16137-noobie-stuff-very-basics-explained-easily/page/5/#findComment-75525 Share on other sites More sharing options...
Pudgemeister Posted August 16, 2006 Author Share Posted August 16, 2006 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 13Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/pudgesuk/public_html/game_testing/island_home.php on line 14thats the error i get when taking them outof the single quote marks-the code looks like this now:[code]<?phpsession_start();if(empty($_SESSION['username']) or empty($_SESSION['id']) or empty($_SESSION['password'])) {//if there is nothing in the sessionecho '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] Quote Link to comment https://forums.phpfreaks.com/topic/16137-noobie-stuff-very-basics-explained-easily/page/5/#findComment-75779 Share on other sites More sharing options...
simcoweb Posted August 16, 2006 Share Posted August 16, 2006 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 Link to comment https://forums.phpfreaks.com/topic/16137-noobie-stuff-very-basics-explained-easily/page/5/#findComment-75784 Share on other sites More sharing options...
Daniel0 Posted August 16, 2006 Share Posted August 16, 2006 [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. Quote Link to comment https://forums.phpfreaks.com/topic/16137-noobie-stuff-very-basics-explained-easily/page/5/#findComment-75788 Share on other sites More sharing options...
simcoweb Posted August 16, 2006 Share Posted August 16, 2006 Ok, I see that and it is a 'string' being passed. Perhaps if he changed this code a bit to:[code]<?phpsession_start();if(empty($_SESSION['username']) or empty($_SESSION['id']) or empty($_SESSION['password'])) {//if there is nothing in the sessionecho '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 :) Quote Link to comment https://forums.phpfreaks.com/topic/16137-noobie-stuff-very-basics-explained-easily/page/5/#findComment-75792 Share on other sites More sharing options...
nethnet Posted August 17, 2006 Share Posted August 17, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/16137-noobie-stuff-very-basics-explained-easily/page/5/#findComment-75988 Share on other sites More sharing options...
Pudgemeister Posted August 17, 2006 Author Share Posted August 17, 2006 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 hehehecheersPudgemeister Quote Link to comment https://forums.phpfreaks.com/topic/16137-noobie-stuff-very-basics-explained-easily/page/5/#findComment-76111 Share on other sites More sharing options...
psychohagis Posted January 5, 2007 Share Posted January 5, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/16137-noobie-stuff-very-basics-explained-easily/page/5/#findComment-153688 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.