Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,207,565 members, 7,999,462 topics. Date: Monday, 11 November 2024 at 08:06 AM

Help With PHP Array, Result Is Skipping A Row - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Help With PHP Array, Result Is Skipping A Row (925 Views)

Complete Array Of Countries And Nigerian States [open Source] / Converting Picture To Byte Array(blob) And Back To Picture (2) (3) (4)

(1) (Reply)

Help With PHP Array, Result Is Skipping A Row by mj(m): 7:55am On Sep 26, 2012
im trying to select the amount column in the database table but i notice that it is skipping a row in the table, this is my code; Thanks.
$Amount_results = mysql_query("select `Amount` from transaction"wink or die("Can not select amount :" . mysql_error());
$result_list = array();
while($row = mysql_fetch_array($Amount_results))
{
$result_list[] = $row['Amount'];

}
foreach ($result_list as $amount) {
echo $amount ."<br />";
}
Re: Help With PHP Array, Result Is Skipping A Row by Nobody: 6:01pm On Sep 26, 2012
you seem to be making this more difficult than it should

here is what usually do

i have a file database.php which i include using require_once

$hostname_conn = "localhost";
$database_conn = "mydb";
$username_conn = "dbuser";
$password_conn = "dbpass";
$conn = mysql_connect($hostname_conn, $username_conn, $password_conn) or trigger_error(mysql_error(),E_USER_ERROR);

function query($q){
global $database_conn;
global $conn;
mysql_select_db($database_conn, $conn);
$result = mysql_query($q, $conn) or die(mysql_error());
return $result;
}



then in all your codes, you will be able to code less

for the above, we just have something like this


require_once( "functions/database.php" ); #include the header file

$r_amount=query("select `Amount` from transaction"wink; #the query, now nice and neat

while($row_amount=mysql_fetch_assoc($r_amount){
echo $row_amount['Amount']."<br />";
}

i always like fetching the resource as an associative array, you are able to use the name to call it instead of the index which can change when you modify your database structure.

1 Like

Re: Help With PHP Array, Result Is Skipping A Row by mj(m): 8:49pm On Sep 26, 2012
@ webdezzi, thanks...

(1) (Reply)

Join The Ongoing Mobile Application Development Project / Looking Plc Programming? In Just A Week / Offline Computer Based Exams For Students

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 7
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.