• Help
  • Search
  • Login
  • Register
  • Home

Forum: web design and graphics community

Celestial Star Forum > Web Development > Coding > Display rows in columns?
Pages: [1]
« previous next »
  Print  
Author Topic: Display rows in columns?  (Read 856 times)
paine
Angeling
*
Posts: 7


View Profile
Display rows in columns?
« on: July 11, 2005, 12:19:37 PM »

ok i've read everything here and no one seems to be trying to combine their next, prev II navigation with the displaying rows in columns code. I'm a little lost... here's my code

Code:
<?php 

$user
="-----"; 
$host="localhost"; 
$password="-----"; 
$database="-------"; 

$connection = mysql_connect&#40;$host,$user,$password&#41; 
or die &#40;"couldn't connect to server"&#41;; $db = mysql_select_db&#40;$database,$connection&#41; 
or die &#40;"Couldn't select database"&#41;; 

echo "<div align=\"center\"><table width=\"95%\"><tr>"; 

$query .="SELECT * from ---- order by id desc"; 
$result= mysql_query&#40;$query, $connection&#41; or die 
&#40;"Could not execute query &#58; $query ." . mysql_error&#40;&#41;&#41;; 

//CODE A
// Start paging variables 
$screen = $_GET['screen'&#93;; 
$PHP_SELF = $_SERVER['PHP_SELF'&#93;; 
$rows_per_page=5; // number of records per page 
$total_records=mysql_num_rows&#40;$result&#41;; 
$pages = ceil&#40;$total_records / $rows_per_page&#41;; // calculate number of pages required 

if &#40;!isset&#40;$screen&#41;&#41; 
$screen=0; 
$start= $screen * $rows_per_page; // determine start record 
$query .= "LIMIT $start, $rows_per_page"; 
$result= mysql_query&#40;$query&#41; or die 
&#40;"Could not execute query &#58; $query ." . mysql_error&#40;&#41;&#41;; 

while &#40;$row=mysql_fetch_array&#40;$result&#41;&#41; 
&#123; 

$id=$row["id"&#93;; 
$name=$row["name"&#93;; 
$artist=$row["artist"&#93;; 
$artisturl=$row["artisturl"&#93;; 
$series=$row["series"&#93;;  
$previewimage=$row["previewimage"&#93;; 

&#125;

$rows_per_page=24; 
$total_records=mysql_num_rows&#40;$result&#41;; 
$pages = ceil&#40;$total_records / $rows_per_page&#41;; 
mysql_free_result&#40;$result&#41;; 

if &#40;!isset&#40;$screen&#41;&#41; 
$screen=0; 
$start = $screen * $rows_per_page; 
$query .= " LIMIT $start, $rows_per_page"; 
$result= mysql_db_query&#40;$dbase, $q, $connection&#41; or die 
&#40;"Could not execute query &#58; $query ." . mysql_error&#40;&#41;&#41;; 

$divide=0; 

while &
#40;$data = mysql_fetch_array&#40;$result&#41;&#41; &#123; 

if&#40;$divide%2==0 && $divide!=0&#41;&#123; 
echo "</tr><tr>"; 
&
#125; 

echo "<td><center><img src=\"$previewimage\"></center><br>
ID&#58; $id<br>
Name&#58; $name<br>
Artist&#58; <a href=\"$artisturl\">$artist</a><td>"
; 

$divide++; 

&
#125; 


echo "</tr></table></div>"; 


        if &
#40;$screen > 0&#41; &#123; 
        
$j = $screen - 1; 
        
$url = "$PHP_SELF?screen=$j"; 
        echo 
"<a href=\"$url\">&laquo;;</a>";
        &
#125; 
         
        // page numbering links now 
        
$p = 5;                                
        
$lower = $p;                    
        
$upper = $screen+$p;       
        while&
#40;$upper>$pages&#41;&#123; 
            
$p = $p-1; 
            
$upper = $screen+$p; 
        &
#125; 
        
if&#40;$p<$lower&#41;&#123; 
            
$y = $lower-$p; 
            
$to = $screen-$y; 
            while&
#40;$to<0&#41;&#123; 
                
$to++; 
            &
#125; 
        
&#125; 
         
        
if&#40;!empty&#40;$to&#41;&#41; 
        
&#123; 
            
for &#40;$i=$to;$i<$screen;$i++&#41;&#123; 
                
$url = "$PHP_SELF?screen=" . $i; 
                
$j = $i + 1; 
                echo 
" | <a href=\"$url\">$j</a> | "; 
            &
#125; 
        
&#125; 
         
        
for &#40;$i=$screen;$i<$upper;$i++&#41; &#123; 
            
$url = "$PHP_SELF?screen=" . $i; 
            
$j = $i + 1; 
            echo 
" | <a href=\"$url\">$j</a> "; 
        &
#125; 
         
        
if &#40;$screen < $pages-1&#41; &#123; 
        
$j = $screen + 1; 
        
$url = "$PHP_SELF?screen=$j"; 
        echo 
"<a href=\"$url\">&raquo; </a>";  
        &
#125; 
?>


my error message is:

Code:
Could not execute query : SELECT * from kimava order by id descLIMIT 0, 5 .You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'descLIMIT 0, 5' at line 1
Logged
puretaurus21
Guest
Display rows in columns?
« Reply #1 on: August 01, 2005, 02:11:10 AM »

I think the error is in your query. Try this:

Code:
$query = "SELECT * from ---- order by id desc ";
Logged
Melfina
Administrator
Valkyrie Randgris
*****
Posts: 1289



View Profile WWW
Display rows in columns?
« Reply #2 on: August 01, 2005, 04:39:46 AM »

eww, I think the code for the pagination and such is a bit messed. It may be something more like this. Some parts were duplicated. Try doing what puretaurus said if that doesn't work:


Code:
<?php 

$user
="-----"; 
$host="localhost"; 
$password="-----"; 
$database="-------"; 

$connection = mysql_connect&#40;$host,$user,$password&#41; 
or die &#40;"couldn't connect to server"&#41;; 
$db = mysql_select_db&#40;$database,$connection&#41; 
or die &#40;"Couldn't select database"&#41;; 

echo "<div align=\"center\"><table width=\"95%\"><tr>"; 

$query .="SELECT * from ---- order by id desc"; 
$result= mysql_query&#40;$query, $connection&#41; or die 
&#40;"Could not execute query &#58; $query ." . mysql_error&#40;&#41;&#41;; 

//CODE A
// Start paging variables 
$screen = $_GET['screen'&#93;; 
$PHP_SELF = $_SERVER['PHP_SELF'&#93;; 
$rows_per_page=5; // number of records per page 
$total_records=mysql_num_rows&#40;$result&#41;; 
$pages = ceil&#40;$total_records / $rows_per_page&#41;; // calculate number of pages required 

if &#40;!isset&#40;$screen&#41;&#41; 
$screen=0; 
$start= $screen * $rows_per_page; // determine start record 
$query .= "LIMIT $start, $rows_per_page"; 
$result= mysql_query&#40;$query&#41; or die 
&#40;"Could not execute query &#58; $query ." . mysql_error&#40;&#41;&#41;; 

$divide=0; 

while &
#40;$row = mysql_fetch_array&#40;$result&#41;&#41; &#123; 

extract&#40;$row&#41;; //Shorter method to extract all columns and rows

if&#40;$divide%2==0 && $divide!=0&#41;&#123; 
echo "</tr><tr>"; 
&
#125; 

echo "<td><center><img src=\"$previewimage\"></center><br>
ID&#58; $id<br>
Name&#58; $name<br>
Artist&#58; <a href=\"$artisturl\">$artist</a><td>"
; 

$divide++; 

&
#125; 


echo "</tr></table></div>"; 


        if &
#40;$screen > 0&#41; &#123; 
        
$j = $screen - 1; 
        
$url = "$PHP_SELF?screen=$j"; 
        echo 
"<a href=\"$url\">&laquo;;</a>";
        &
#125; 
         
        // page numbering links now 
        
$p = 5;                                
        
$lower = $p;                    
        
$upper = $screen+$p;       
        while&
#40;$upper>$pages&#41;&#123; 
            
$p = $p-1; 
            
$upper = $screen+$p; 
        &
#125; 
        
if&#40;$p<$lower&#41;&#123; 
            
$y = $lower-$p; 
            
$to = $screen-$y; 
            while&
#40;$to<0&#41;&#123; 
                
$to++; 
            &
#125; 
        
&#125; 
         
        
if&#40;!empty&#40;$to&#41;&#41; 
        
&#123; 
            
for &#40;$i=$to;$i<$screen;$i++&#41;&#123; 
                
$url = "$PHP_SELF?screen=" . $i; 
                
$j = $i + 1; 
                echo 
" | <a href=\"$url\">$j</a> | "; 
            &
#125; 
        
&#125; 
         
        
for &#40;$i=$screen;$i<$upper;$i++&#41; &#123; 
            
$url = "$PHP_SELF?screen=" . $i; 
            
$j = $i + 1; 
            echo 
" | <a href=\"$url\">$j</a> "; 
        &
#125; 
         
        
if &#40;$screen < $pages-1&#41; &#123; 
        
$j = $screen + 1; 
        
$url = "$PHP_SELF?screen=$j"; 
        echo 
"<a href=\"$url\">&raquo; </a>";  
        &
#125; 
?>
Logged


MySpace  ~ MySpace Codex ~ Rune Nifelheim
Pages: [1]
  Print  
« previous next »
 
Jump to:  

  • Welcome, Guest
  • Members login
  • Register for free

General

  • General
  • New members
  • Announcements
  • Support / Suggestions

Art boards

  • Creative mediums
  • Requests and offers
  • Tutorials
  • Celestial Star tutorials

Web development

  • Coding
  • Web design
  • Advertisements / affiliation

Off-topic

  • The non-sense
  • Ententainment

Go up
eXTReMe Tracker
  • Valid XHTML
  • Valid CSS
Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC | Seo4Smf v0.2 © Webmaster's Talks
Loading...