medaswho Posted February 26, 2009 Share Posted February 26, 2009 in my application, i have one page that stores some data. and this form is supposed to retrieve. for some reason this retreival form gets some records while it doesn't get other records. i have no idea why this is. when i go into phpMySQLAdmin, ALL the data is in there, but this code only retrieves some records. i have played with all the commands i can think to play with(mysql_fetch_row,mysql_fetch_array, etc...) and nothing changes. at my wits end...can anyone solve this puzzle? <?php session_start(); // get the variables from the login form $sname = $_POST['sname']; $pass = $_POST['pass']; mysql_connect($host,$user,$password); mysql_select_db($dbname); $result = mysql_query("SELECT * FROM members WHERE screenname = '$sname' ") or die(mysql_error()); $row1 = mysql_fetch_row( $result ); echo $row1['0']."<br>"; echo $row1['1']."<br>"; echo $row1['2']."<br>"; echo $row1['3']."<br>"; echo $row1['4']."<br>"; echo $row1['5']."<br>"; Quote Link to comment https://forums.phpfreaks.com/topic/146969-solved-two-weeks-and-still-no-answer-on-this-one/ Share on other sites More sharing options...
premiso Posted February 26, 2009 Share Posted February 26, 2009 Your not looping the data. while($row1 = mysql_fetch_row( $result )) { echo $row1['0']."<br>"; echo $row1['1']."<br>"; echo $row1['2']."<br>"; echo $row1['3']."<br>"; echo $row1['4']."<br>"; echo $row1['5']."<br>"; } Should give you all the data that your query is setup to return (given that you limit it with the $_POST['sname']). Quote Link to comment https://forums.phpfreaks.com/topic/146969-solved-two-weeks-and-still-no-answer-on-this-one/#findComment-771517 Share on other sites More sharing options...
allworknoplay Posted February 26, 2009 Share Posted February 26, 2009 in my application, i have one page that stores some data. and this form is supposed to retrieve. for some reason this retreival form gets some records while it doesn't get other records. i have no idea why this is. when i go into phpMySQLAdmin, ALL the data is in there, but this code only retrieves some records. i have played with all the commands i can think to play with(mysql_fetch_row,mysql_fetch_array, etc...) and nothing changes. at my wits end...can anyone solve this puzzle? <?php session_start(); // get the variables from the login form $sname = $_POST['sname']; $pass = $_POST['pass']; mysql_connect($host,$user,$password); mysql_select_db($dbname); $result = mysql_query("SELECT * FROM members WHERE screenname = '$sname' ") or die(mysql_error()); $row1 = mysql_fetch_row( $result ); echo $row1['0']."<br>"; echo $row1['1']."<br>"; echo $row1['2']."<br>"; echo $row1['3']."<br>"; echo $row1['4']."<br>"; echo $row1['5']."<br>"; Hi, how is your loop structured? Quote Link to comment https://forums.phpfreaks.com/topic/146969-solved-two-weeks-and-still-no-answer-on-this-one/#findComment-771518 Share on other sites More sharing options...
medaswho Posted February 26, 2009 Author Share Posted February 26, 2009 thanks for your replies but at this point this is just testing...once i figure out why some records come and some don't a loop is not an issue. this code, as is, does print some records...others it does not. why would that be? Quote Link to comment https://forums.phpfreaks.com/topic/146969-solved-two-weeks-and-still-no-answer-on-this-one/#findComment-771523 Share on other sites More sharing options...
allworknoplay Posted February 26, 2009 Share Posted February 26, 2009 thanks for your replies but at this point this is just testing...once i figure out why some records come and some don't a loop is not an issue. this code, as is, does print some records...others it does not. why would that be? I'm not familiar with PHPmyadmin since I don't use it, but I would assume that when you use that, it uses loops too in order to display your records which you say is coming out correctly.. So why not use loops to see if you can get the same results? Quote Link to comment https://forums.phpfreaks.com/topic/146969-solved-two-weeks-and-still-no-answer-on-this-one/#findComment-771524 Share on other sites More sharing options...
premiso Posted February 26, 2009 Share Posted February 26, 2009 thanks for your replies but at this point this is just testing...once i figure out why some records come and some don't a loop is not an issue. this code, as is, does print some records...others it does not. why would that be? Sorry, this just does not make sense to me. You are meaning to fetch one record. The code you have can sometimes fetch one record, given the sname or sometimes fetch a completely different record of the sname? Do you have multiple records that have the sname? Maybe it is randomizing output, which it should not but is a possibility. There is nothing in your code that could be doing this? How are you testing the pulling of data with the query? There are a ton of unknowns and with us not knowing how experienced you are with php and mysql. MySQL is not a guessing game, honestly. It returns what input you give it. Is this the full code you are executing? Can you print out the table data (if less than 10 rows) and print out one of the queries you can run in phpMyAdmin and what it returns? Then what does that same query return, using a loop, in your code.... There are a ton of scenarios here and yea. It is basically a needle in the haystack, however to find this needle you just need to provide us with a bit more detailed information. EDIT: Could it be directly related to the POST data not coming through? Are you checking if a form was submitted and not just assuming that data is there? Quote Link to comment https://forums.phpfreaks.com/topic/146969-solved-two-weeks-and-still-no-answer-on-this-one/#findComment-771528 Share on other sites More sharing options...
medaswho Posted February 26, 2009 Author Share Posted February 26, 2009 phpmyadmin is just a utility to look at the structure of the database, but as for the loop. i have looped this data, i have done all kinds of things to this data. i have had a while loop in there, i have used mysql_fetch_array,mysql_fetch_row,mysql_fetch_object i different configurations,but nothing changes. the same records either are retrieved or not. Quote Link to comment https://forums.phpfreaks.com/topic/146969-solved-two-weeks-and-still-no-answer-on-this-one/#findComment-771530 Share on other sites More sharing options...
allworknoplay Posted February 26, 2009 Share Posted February 26, 2009 phpmyadmin is just a utility to look at the structure of the database, but as for the loop. i have looped this data, i have done all kinds of things to this data. i have had a while loop in there, i have used mysql_fetch_array,mysql_fetch_row,mysql_fetch_object i different configurations,but nothing changes. the same records either are retrieved or not. can you show us your table structure? And also, how may records do you have in it now? And provide some sample output as well from your testing.....what you are getting and what you THINK you should get..... Quote Link to comment https://forums.phpfreaks.com/topic/146969-solved-two-weeks-and-still-no-answer-on-this-one/#findComment-771532 Share on other sites More sharing options...
medaswho Posted February 26, 2009 Author Share Posted February 26, 2009 thank you for your reply "premiso", but i have two questions for you...why would it randomize? what would make mysql randomize the retrieval of data? and second question is: other then randomizing, no matter what else my code is doing , why would it work on some data and not other data? i assure you there is nothing special about the data. just names. all the same length, no special characters or caps or anything. and to answer one of your questions, i am not all that experienced but fairly well read, and this baffles me to no end. Quote Link to comment https://forums.phpfreaks.com/topic/146969-solved-two-weeks-and-still-no-answer-on-this-one/#findComment-771536 Share on other sites More sharing options...
premiso Posted February 26, 2009 Share Posted February 26, 2009 It should not, it would be a glitch. However, if you have duplicate screennames in the DB, this may happen, especially if you do not have a primary key set on the table which is an id, or a unique value. My bet is, the post data is causing the issue. Could be you need to trim it, or it is not posting when you think it is etc. Try this as your page and see what happens: <?php session_start(); if (isset($_POST['sname'])) { // get the variables from the login form $sname = $_POST['sname']; $pass = $_POST['pass']; mysql_connect($host,$user,$password); mysql_select_db($dbname); $result = mysql_query("SELECT * FROM members WHERE screenname = '$sname' ") or die(mysql_error()); while ($row1 = mysql_fetch_row( $result )) { echo $row1['0']."<br>"; echo $row1['1']."<br>"; echo $row1['2']."<br>"; echo $row1['3']."<br>"; echo $row1['4']."<br>"; echo $row1['5']."<br><br>"; } } ?> And just so you do realize that mysql randomizing data output is not normal, but given that I do not know how your tables are setup it is a possibility. phpMyAdmin most likely sorts the data by an ORDER BY to prevent this randomization, but yea. EDIT: Major edit, had to remove the ! from the isset beginning as that was completely wrong. Quote Link to comment https://forums.phpfreaks.com/topic/146969-solved-two-weeks-and-still-no-answer-on-this-one/#findComment-771539 Share on other sites More sharing options...
Philip Posted February 26, 2009 Share Posted February 26, 2009 Could it be directly related to the POST data not coming through? Are you checking if a form was submitted and not just assuming that data is there? Adding to this, are you sure the query is the exact same every time? $q = "SELECT * FROM members WHERE screenname = '$sname' "; echo $q; $result = mysql_query($q) or die(mysql_error()); $row1 = mysql_fetch_row( $result ); // the following will output the data returned from the fetch_row - showing the key names, etc echo '<pre>'; print_r($row1); echo '</pre>'; Quote Link to comment https://forums.phpfreaks.com/topic/146969-solved-two-weeks-and-still-no-answer-on-this-one/#findComment-771540 Share on other sites More sharing options...
medaswho Posted February 26, 2009 Author Share Posted February 26, 2009 thanks for your reply KingPhilip. yes the data is definitely in there. i can see it in phpmyadmin. Quote Link to comment https://forums.phpfreaks.com/topic/146969-solved-two-weeks-and-still-no-answer-on-this-one/#findComment-771546 Share on other sites More sharing options...
Philip Posted February 26, 2009 Share Posted February 26, 2009 I'm aware that you have data in there, but I'm more concerned about the query itself. When you are getting different results, are your queries the exact same every time? edit: sorry, I just realized that I put print_r in there. it's just habit to put in print_r when debugging mysql queries/results Quote Link to comment https://forums.phpfreaks.com/topic/146969-solved-two-weeks-and-still-no-answer-on-this-one/#findComment-771549 Share on other sites More sharing options...
premiso Posted February 26, 2009 Share Posted February 26, 2009 thanks for your reply KingPhilip. yes the data is definitely in there. i can see it in phpmyadmin. No, he means the $_POST data. As that can change, are you sure it is being populated and the data coming into that is what you expect it. Maybe echo the $_POST['sname'] out on the page to make sure that contains what you expect it. Quote Link to comment https://forums.phpfreaks.com/topic/146969-solved-two-weeks-and-still-no-answer-on-this-one/#findComment-771550 Share on other sites More sharing options...
medaswho Posted February 26, 2009 Author Share Posted February 26, 2009 premiso, i have tried echoing the post data, the user name and password. see this is not coming from other users yet so i know what is being sent as i am the one sending it. and i tried the code you just gave me. same results!! one thing you said is compeling though. you said if i had duplicate data it might cause mysql glitch. i am going to go thru and get rid of duplicates and see if that solves the problem. please stay tuned :-) Quote Link to comment https://forums.phpfreaks.com/topic/146969-solved-two-weeks-and-still-no-answer-on-this-one/#findComment-771551 Share on other sites More sharing options...
medaswho Posted February 26, 2009 Author Share Posted February 26, 2009 OK. got rid of all duplicate data...that did nothing...going to try code KingPhillip posted now Quote Link to comment https://forums.phpfreaks.com/topic/146969-solved-two-weeks-and-still-no-answer-on-this-one/#findComment-771553 Share on other sites More sharing options...
medaswho Posted February 26, 2009 Author Share Posted February 26, 2009 nothing doing!! some data works and some doesn't. i have no idea how this can be?????????? Quote Link to comment https://forums.phpfreaks.com/topic/146969-solved-two-weeks-and-still-no-answer-on-this-one/#findComment-771554 Share on other sites More sharing options...
Philip Posted February 26, 2009 Share Posted February 26, 2009 So, the queries are exactly the same? Quote Link to comment https://forums.phpfreaks.com/topic/146969-solved-two-weeks-and-still-no-answer-on-this-one/#findComment-771555 Share on other sites More sharing options...
medaswho Posted February 26, 2009 Author Share Posted February 26, 2009 the queries are EXACTLY the same Quote Link to comment https://forums.phpfreaks.com/topic/146969-solved-two-weeks-and-still-no-answer-on-this-one/#findComment-771559 Share on other sites More sharing options...
premiso Posted February 26, 2009 Share Posted February 26, 2009 the queries are EXACTLY the same Can you post data in your table, like 5-10 rows, and your table structure for us? And what you are getting returned the "random data". Quote Link to comment https://forums.phpfreaks.com/topic/146969-solved-two-weeks-and-still-no-answer-on-this-one/#findComment-771561 Share on other sites More sharing options...
trq Posted February 26, 2009 Share Posted February 26, 2009 nothing doing!! some data works and some doesn't. i have no idea how this can be? You might want to post the actual code your using (within tags), the actual data your passing to the query and an example of the output. ps: In the future, do not make your thread tittles all caps. Your question is no more important or urgent than anyone else's. Quote Link to comment https://forums.phpfreaks.com/topic/146969-solved-two-weeks-and-still-no-answer-on-this-one/#findComment-771563 Share on other sites More sharing options...
medaswho Posted February 26, 2009 Author Share Posted February 26, 2009 that is currently the actual code. it will change once i figure out what is going on, but for now that is the test code and the test data. Quote Link to comment https://forums.phpfreaks.com/topic/146969-solved-two-weeks-and-still-no-answer-on-this-one/#findComment-771596 Share on other sites More sharing options...
trq Posted February 26, 2009 Share Posted February 26, 2009 The code you have posted will only display one record. Thats it. You might want to post the actual code your using (within tags), the actual data your passing to the query and an example of the output. Quote Link to comment https://forums.phpfreaks.com/topic/146969-solved-two-weeks-and-still-no-answer-on-this-one/#findComment-771601 Share on other sites More sharing options...
medaswho Posted February 26, 2009 Author Share Posted February 26, 2009 and it does only post one record. but when i change the record i am asking for, some retrieve and some don't. that is the question. if this test code will get one record, why wouldn't it get them all? the code doesn't change nor does the query. only the result or lack there of. Quote Link to comment https://forums.phpfreaks.com/topic/146969-solved-two-weeks-and-still-no-answer-on-this-one/#findComment-771608 Share on other sites More sharing options...
trq Posted February 26, 2009 Share Posted February 26, 2009 if this test code will get one record, why wouldn't it get them all? Because your not looping through the result set. You still haven't shown us the actual data your passing to the query or an example of the output. Quote Link to comment https://forums.phpfreaks.com/topic/146969-solved-two-weeks-and-still-no-answer-on-this-one/#findComment-771610 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.