MySQL query's suceed in PHPMyAdmin but not in the PHP Script itself -
just while playing around querying in php ran trouble. title of post explains problem. when run query in phpmyadmin results different results in php programme itself. here code using. sorry if looks little odd i've been cutting , pasting things on place in frantic effort working.
$connect = array('username'=>'root', 'host'=>'127.0.0.1', 'password'=>''); $link = mysql_connect($connect['host'], $connect['username'], $connect['password']) or die('error creating link: ' . mysql_error()); mysql_select_db('testing_pages', $link) or die('error connecting database: ' . mysql_error()); $sql = "select `name` `names`"; $query = mysql_query($sql, $link) or die('query failed! check error:<br/><br/>' . mysql_error()); $query_2 = mysql_fetch_array($query); $query = $query_2; $loop = count($query); $count = 0; while($count <= $loop) { echo $query[$count] . '<br/>'; $count++; } see, im trying read names, pop array, print them out while loop. seems homecoming 1 result , thats first name in databse. when run exact query through phpmyadmin homecoming every name in database... odd thing, when using 'count' function number of values in array claims there 3 values, during loop prints out first name, sec 2 returns 'undefined index'.
hope dont seem noob right now... , hope explained well. can help.
mysql_fetch_array fetches 1 row in form of array. here docs.
and pay attending big warning message @ top of page when read docs...
php mysql sql
No comments:
Post a Comment