₦airaland Forum

Welcome, Guest: RegisterLoginWith GoogleTrendingRecentNew

Stats: 3,328,300 members, 8,435,095 topics. Date: Saturday, 27 June 2026 at 10:10 PM

Toggle theme

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

Nairaland ForumScience/TechnologyProgrammingHelp With PHP Array, Result Is Skipping A Row (984 Views)

1 Reply

Help With PHP Array, Result Is Skipping A Row by mj(op):
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.
Re: Help With PHP Array, Result Is Skipping A Row by mj(op): 8:49pm On Sep 26, 2012
@ webdezzi, thanks...
1 Reply

Complete Array Of Countries And Nigerian States [open Source]Converting Picture To Byte Array(blob) And Back To Picture234

Just Beginning To Learn Programming.Suggestions To Make Bible Topics App Better