Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Table row design with mysql data return
Old 11-29-2005, 01:29 PM Table row design with mysql data return
Average Talker

Posts: 23
Trades: 0
Here is the entire code i am working with, like i say getting same row 4 times not what i would like want all 16 records in a 4colsx4rows table.

PHP Code:
<?php
require_once '../lib/configs.php';

// If current page number, use it 
// if not, set one! 

if(!isset($_REQUEST['page'])){ 
    
$page 1
} else { 
    
$page $_REQUEST['page']; 


// Define the number of results per page 
$max_results 16

// Figure out the limit for the query based 
// on the current page number. 
$from = (($page $max_results) - $max_results);

// Perform MySQL query on only the current page number's results 
$query "SELECT * FROM ship_to LIMIT ".$from.", ".$max_results."";
echo 
"<table cellpadding=5 cellspacing=1 border=0 align=center bgcolor=#000000>\n";
$bgcolor "#E0E0E0"// light gray 
if (mysql_connect($defaults["db_server"], $defaults["db_username"], $defaults["db_password"])) {
    if (
mysql_select_db($defaults["db_database"])) {
        if (
$result mysql_query($query)) {
            if (
mysql_num_rows($result) > 0) {
                while (
$row mysql_fetch_assoc($result)) {
                    if(
$bgcolor == "#E0E0E0"){
                        
$bgcolor "#FFFFFF";
                    }else{
                        
$bgcolor "#E0E0E0";
                    } 
                    echo 
"<tr bgcolor=".$bgcolor.">\n";
                    for (
$i=0$i!=4$i++) {
                        echo 
"\t<td>".$row['name']."</td>\n";
                    }
                    echo 
"</tr>\n";
                }
            }
            
mysql_free_result($result);
        }
        else {
            die (
"<h3>SQL Error #".mysql_errno()."</h3>\n<h4>".mysql_error()."</h4>\n<h4>Line ".__LINE__." in ".__FILE__."</h4>\n");
        }
    }
    else {
        die (
"<h3>SQL Error #".mysql_errno()."</h3>\n<h4>".mysql_error()."</h4>\n<h4>Line ".__LINE__." in ".__FILE__."</h4>\n");
    }
}
else {
    die (
"<h3>SQL Error #".mysql_errno()."</h3>\n<h4>".mysql_error()."</h4>\n<h4>Line ".__LINE__." in ".__FILE__."</h4>\n");
}
echo 
"</table>\n";
// Figure out the total number of results in DB: 
$total_results mysql_result(mysql_query("SELECT COUNT(*) as Num FROM ship_to"),0); 

// Figure out the total number of pages. Always round up using ceil() 
$total_pages ceil($total_results $max_results); 

// Build Page Number Hyperlinks 
echo "<center>Select a Page<br />\n"

// Build Previous Link 
if($page 1){ 
    
$prev = ($page 1); 
    echo 
"<a href=\"pages.php?page=$prev\">&lt;&lt;Previous</a>\n "


for(
$i 1$i <= $total_pages$i++){ 
    if((
$page) == $i){ 
        echo 
"$i "
        } else { 
            echo 
"<a href=\"pages.php?page=$i\">$i</a> \n"
    } 


// Build Next Link 
if($page $total_pages){ 
    
$next = ($page 1); 
    echo 
"<a href=\"pages.php?page=$next\">Next&gt;&gt;</a>\n"

echo 
"</center>\n"
?>
tobeyt23 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 11-29-2005, 03:38 PM
Republikin's Avatar
Defies a Status

Posts: 3,189
Trades: 3
PHP Code:
for ($i=0$i!=4$i++) { 
                        echo 
"\t<td>".$row['name']."</td>\n"
                    } 
First, use $i<4 rather than $i!=4. Second, since your inside the same itteration of your master while loop $row['name'] is going to contain the same value for each of your sub-loops itterations until the next time the master loop runs, if that makes sense.
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
Republikin is offline
Reply With Quote
View Public Profile
 
Old 11-30-2005, 11:23 AM
Average Talker

Posts: 23
Trades: 0
So where should i place the the for loop?
tobeyt23 is offline
Reply With Quote
View Public Profile
 
Old 11-30-2005, 02:44 PM
Nahele's Avatar
Extreme Talker

Posts: 204
Trades: 1
You may want to change your while condition and then your for block:
PHP Code:
while ($row mysql_fetch_array($resultMYSQL_NUM)) {
  if(
$bgcolor == "#E0E0E0"){
    
$bgcolor "#FFFFFF";
  }else{
    
$bgcolor "#E0E0E0";
  } 
  echo 
"<tr bgcolor=".$bgcolor.">\n";
  for (
$i=0$i<4$i++) {
    echo 
"\t<td>".$row[$i]."</td>\n";
  }
  echo 
"</tr>\n";

This will loop through each row with the for loop and an array indexed 0-3. Your for loop will then display each entry of that row by referencing those index numbers.
__________________
The worst things in life allow us to appreciate the best things

virtual kudos (a.k.a. talkupation) always welcome where deserved.
Nahele is offline
Reply With Quote
View Public Profile
 
Old 11-30-2005, 04:39 PM
Average Talker

Posts: 23
Trades: 0
This is great and all but this is what i would like to do, I have an inventory of products to be displayed in a 4x4 table. Everything I have done and everything I have gotten for help shows 4cols with 16 rows. I am pulling out 16 records and then would like to display the records like so:

[1][2][3][4]
[5][6][7][8]
[9][10][11][12]
[13][14][15][16]
tobeyt23 is offline
Reply With Quote
View Public Profile
 
Old 11-30-2005, 06:11 PM
Nahele's Avatar
Extreme Talker

Posts: 204
Trades: 1
Wait, how is your information organized in a database. The code I gave you will = work if it is four columns such as 'product name', 'serial number', 'quantity', and 'price' and then 4 rows of entries. If your information is just 16 rows of products just under the column 'name', do something like this:
PHP Code:

for ($i=0$i<4$i++) {
  if(
$bgcolor == "#E0E0E0"){
    
$bgcolor "#FFFFFF";
  }else{
    
$bgcolor "#E0E0E0";
  } 
  echo 
"<tr bgcolor=".$bgcolor.">\n";
  for (
$j=0$j<4$j++) {
    
$row mysql_fetch_assoc($result);
    echo 
"\t<td>".$row['name']."</td>\n";
  }
  echo 
"</tr>\n";

__________________
The worst things in life allow us to appreciate the best things

virtual kudos (a.k.a. talkupation) always welcome where deserved.
Nahele is offline
Reply With Quote
View Public Profile
 
Old 12-01-2005, 09:35 AM
Average Talker

Posts: 23
Trades: 0
Thank you this is almost perfect ... I am only getting 15 of the 16 results to show up in the cells. Any ideas why this is ocurring? It is dropping off the first record that is returned from the query.
==================
Got it this is solved ... i was doing the above code with in my original while statement. All is good now, thanks for all the suggestions!

Last edited by tobeyt23; 12-01-2005 at 01:44 PM..
tobeyt23 is offline
Reply With Quote
View Public Profile
 
Old 12-01-2005, 10:40 PM
Nahele's Avatar
Extreme Talker

Posts: 204
Trades: 1
Try changing your max results to 17
__________________
The worst things in life allow us to appreciate the best things

virtual kudos (a.k.a. talkupation) always welcome where deserved.
Nahele is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Table row design with mysql data return
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 1.40222 seconds with 12 queries