Jump to content

PHP/MYSQL database results problem


1planetone

Recommended Posts

Hi there,
I am having little problem while I try to retrieve
data from mysql table, everything works fine but the
first row of the table display empty, here is how it is look like:
----------------------------------
empty ¦ results ok
----------------------------------
results ok ¦ results ok
----------------------------------
results ok ¦ results ok
----------------------------------
results ok ¦ results ok
----------------------------------
results ok ¦ results ok
----------------------------------

here is my code

[code]<?php
include_once ("dbase/mysql_connect.php");
?>

<table>

<?php

$limit = 25;
$query_count = "SELECT * FROM Rb_fiftyMl_bottle";
$result_count = mysql_query($query_count);
$totalrows = mysql_num_rows($result_count);

if(empty($page)){
$page = 1;
}

$limitvalue = $page * $limit - ($limit);
$query = "SELECT * FROM Rb_fiftyMl_bottle LIMIT $limitvalue, $limit";
$result = mysql_query($query) or die("Error: " . mysql_error());

if(mysql_num_rows($result) == 0){
echo("Nothing to Display!");
}

$bgcolor = "#CCCCCC"; // light gray

echo("<center><table>");

while($row = mysql_fetch_array($result)){
if ($bgcolor == "#CCCCCC"){
$bgcolor = "#FFF4CA";
}else{
$bgcolor = "#CCCCCC";
$product_name = $row['product_name'];
$product_id = $row['product_id'];
}

echo("<tr bgcolor=".$bgcolor.">");
echo("<td><a href=\"products_details.php?product_id=$product_id\">$product_name</a></td>");
echo("<td>");
echo($row["product_price"]);
echo("</td></tr>");
}

echo("</table>");

if($page!= 1){
$pageprev = $page-1;

echo("<a href=\"$PHP_SELF?page=$pageprev\">←</a> ");
}else{
echo("←  ");
}

$numofpages = $totalrows / $limit;

for($i = 1; $i <= $numofpages; $i++){
if($i == $page){
echo($i." ");
}else{
echo("<a href=\"$PHP_SELF?page=$i\">$i</a> ");
}
}

if(($totalrows % $limit)!= 0){
if($i == $page){
echo($i." ");
}else{
echo("<a href=\"$PHP_SELF?page=$i\">$i</a> ");
}
}

if(($totalrows - ($limit * $page)) >= 0){
$pagenext = $page+1;

echo("<a href=\"$PHP_SELF?page=$pagenext\">→</a>");
}else{
echo("→");
}

mysql_free_result($result);

?>

</table>[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.