Caliber Mengsk Posted September 29, 2011 Share Posted September 29, 2011 So, I'm working on trying to create a simple get data script right now. The people that worked at this place before me set up a database to get data from at a later time, and didn't set up an interface for doing so. I have no problem programming a few webpages to see everything, problem is, I'm getting results like this: id: 1 id: 1 Date: Fri Jun 17 05:43:54 2011 Date: Fri Jun 17 05:43:54 2011 Write_transfer_rate_average: 129.25x Write_transfer_rate_average: 129.25x Write_transfer_rate_start: Write_transfer_rate_start: Write_transfer_rate_middle: Write_transfer_rate_middle: Write_transfer_rate_end: 10.0x Write_transfer_rate_end: 10.0x As you can see, it's printing out the results twice, even though my code doesn't say to do that. At this point, I'm just doing a select all. "SELECT * FROM 2011testing" I don't see anything in my php code that would duplicate it, but here is that if it's needed. index.php <?php include('db.php'); $conn = db_conn('**TAKEN OUT FOR SECURITY**', '**TAKEN OUT FOR SECURITY**', '**TAKEN OUT FOR SECURITY**', '**TAKEN OUT FOR SECURITY**'); if($conn == false) { echo "Didn't connect correctly."; }else{ $failed = false; $sql = mysql_query("SELECT * FROM 2011testing") or $failed = true; if(!$failed) { while($row = mysql_fetch_array($sql)) { $x = 0; foreach($row as $r) { echo mysql_field_name($sql,$x) . ": " . $r . "<br />"; $x+=.5; //will be 1 instead of .5 after I figure out this problem. } echo "==================================================================================<br />"; } echo "Completed data collection."; }else{ echo "Failed to complete."; } } @db_disconn($conn); //@ comment for if the connection didn't work. I still want to display the rest of the page. ?> db.php <?php function db_conn($server, $username, $password, $db) { $connected = true; @$link = mysql_connect($server, $username, $password); if($link) { mysql_select_db('testing', $link); }else{ $connected = false; } if($connected) { return $link; } } function db_disconn($link) { mysql_close($link); } ?> Lastly, here is the table structure: 2011testing | CREATE TABLE `2011testing` ( `id` int(11) NOT NULL AUTO_INCREMENT, `Date` longtext COLLATE utf8_unicode_ci, `Write_transfer_rate_average` longtext COLLATE utf8_unicode_ci, `Write_transfer_rate_start` longtext COLLATE utf8_unicode_ci, `Write_transfer_rate_middle` longtext COLLATE utf8_unicode_ci, `Write_transfer_rate_end` longtext COLLATE utf8_unicode_ci, `Read_transfer_rate_average` longtext COLLATE utf8_unicode_ci, `Read_transfer_rate_start` longtext COLLATE utf8_unicode_ci, `Read_transfer_rate_middle` longtext COLLATE utf8_unicode_ci, `Read_transfer_rate_end` longtext COLLATE utf8_unicode_ci, `Random_seek_time_buffered` longtext COLLATE utf8_unicode_ci, `Random_seek_time_cached` longtext COLLATE utf8_unicode_ci, `Vendor` longtext COLLATE utf8_unicode_ci, `Model` longtext COLLATE utf8_unicode_ci, `Firmware` longtext COLLATE utf8_unicode_ci, `Serial_Number_External` longtext COLLATE utf8_unicode_ci, `Serial_Number_Internal` longtext COLLATE utf8_unicode_ci, `Status_Info` longtext COLLATE utf8_unicode_ci, `Vendor_Code` longtext COLLATE utf8_unicode_ci, `Date_recieved` longtext COLLATE utf8_unicode_ci, `User_Changes_Remaining` longtext COLLATE utf8_unicode_ci, `Vendor_Resets_Remaining` longtext COLLATE utf8_unicode_ci, `Current_Region` longtext COLLATE utf8_unicode_ci, `Test_ran` longtext COLLATE utf8_unicode_ci, `Note` longtext COLLATE utf8_unicode_ci, `Log` longtext COLLATE utf8_unicode_ci, PRIMARY KEY (`id`) ) ENGINE=MyISAM AUTO_INCREMENT=341 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci I don't see ANY reason why it is outputting duplicate results in either my php or mysql. Can anyone help with this? I do think I've had this problem before, but I just simply don't remember how I went about fixing this. OH! Mysql version is 14.14 Dist 5.1.46, OS is opensuse. Obviously it's not a problem connecting to the database, as I am actually getting results... just to many of them. XD Thanks in advance. I know it's probably something stupid simple, but I just can't figure it out for the life of me. Link to comment https://forums.phpfreaks.com/topic/248141-double-rows-two-rows-for-every-individual-value/ Share on other sites More sharing options...
PFMaBiSmAd Posted September 29, 2011 Share Posted September 29, 2011 By default, mysql_fetch_array returns an array with both numerical and associative indexes. Use mysql_fetch_assoc instead. Link to comment https://forums.phpfreaks.com/topic/248141-double-rows-two-rows-for-every-individual-value/#findComment-1274215 Share on other sites More sharing options...
Caliber Mengsk Posted September 29, 2011 Author Share Posted September 29, 2011 I knew it was something stupid simple. I actually use to use fetch assoc when I first learned php/mysql. O-o I wonder why I stopped using it... @_@ Been a couple years since I've programmed either also. Thanks for the help! Link to comment https://forums.phpfreaks.com/topic/248141-double-rows-two-rows-for-every-individual-value/#findComment-1274216 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.