Tutorials
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOtherTutorials

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
AT&T devCentral & BlackBerry(r) Webcast Series: BlackBerry and GPS -Build Location Awareness into your BlackBerry Applications, July 10th-1:00PM EST. Register Today!
  #1  
Old March 17th, 2003, 06:15 AM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
Matt Wade tutorial help - results over 2 columns

I have been trying out Matt Wade's script from this site that spreads the results from a query over two columns.

The following code works except that I get too many result rows. What should happen is the following:

result1 result4
result2 result5
result3 result6

What I get is:

result1 result4
result2 result5
result3 result6
result4
result5
result6

Note that there are 6 rows in the database. I guess this script is returning 6 rows but I am not sure where it is going wrong....tired brain!

php Code:
Original - php Code
  1. <?php
  2.  
  3. $columns = 2;
  4.  
  5. $sql = "SELECT a_pic, a_title, a_date
  6.         FROM Activities
  7.         ORDER BY a_date";
  8.         
  9. $result = mysql_query($sql) or die("Couldn't execute query.");
  10.  
  11. $num_rows = mysql_num_rows($result);
  12.  
  13. $rows = ceil($num_rows / $columns);
  14.  
  15. while($row = mysql_fetch_array($result)) {
  16.   $data[] = $row['a_pic'];
  17.   $data1[] = $row['a_title'];
  18.   $data2[] = $row['a_date'];
  19.  
  20. }
  21.  
  22. echo "<table border="0">n";
  23.  
  24. for($i = 0; $i < $num_rows; $i++) {
  25.     echo "<tr>n";
  26.    
  27.     for($j = 0; $j < $columns; $j++) {
  28.     if(isset($data[$i + ($j * $rows)])) {
  29.     echo "<td><img src="" . $data[$i + ($j * $rows)] . ""></td>n";
  30.    
  31.     echo "<td valign="top">" . $data1[$i + ($j * $rows)] . "<br>" . $data2[$i + ($j * $rows)] . "</td>n";
  32.     }
  33.    
  34.   }
  35.  echo "</tr>n";
  36. }   
  37. echo "</table>n";
  38.  
  39. ?>

Reply With Quote
  #2  
Old March 17th, 2003, 11:02 AM
MadAlbert MadAlbert is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Brisbane
Posts: 5 MadAlbert User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to MadAlbert
RE: Matt Wade tutorial help - results over 2 columns

This
for($i = 0; $i < $num_rows; $i++) {

should probably be

for($i = 0; $i < $rows; $i++) {

Reply With Quote
  #3  
Old March 17th, 2003, 12:16 PM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
RE: Matt Wade tutorial help - results over 2 columns

Thank you! That fixed it nicely http://codewalkers.com/forum/art/msgicons/icon6.gif

Reply With Quote
  #4  
Old March 18th, 2003, 08:26 AM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
RE: Matt Wade tutorial help - results over 2 columns

One more question: The above script displays the results in vertical order like so:

1 4
2 5
3 6

Anyone have an idea how I can adjust this to a horizontal order?

1 2
2 4
5 6

I can't figure this one out....help appreciated!

Reply With Quote
  #5  
Old August 24th, 2007, 01:05 PM
shah sahib shah sahib is offline
Registered User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Aug 2007
Posts: 1 shah sahib User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 55 sec
Reputation Power: 0
results in 2 colmns rather than in rows

hi

at the moment with the following code i get 1 result per row

cat 1
cat2
cat3

etc

i want the results like

catogary 1 catogray 2
catogay 3 catogary 4

etc this is my code please help

function list_pages() {
global $prefix, $db, $sitename, $admin, $multilingual, $module_name, $admin_file;
include("header.php");
title("$sitename: "._PAGESLIST."");
OpenTable();
echo "<center><font class=\"content\">"._LISTOFCONTENT." $sitename:</center><br><br>";
$result = $db->sql_query("SELECT * FROM ".$prefix."_pages_categories ORDER BY title");
$numrows = $db->sql_numrows($result);
$numrows2 = $db->sql_numrows($db->sql_query("SELECT * FROM ".$prefix."_pages WHERE cid!='0' AND active='1'"));
if ($numrows > 0 AND $numrows2 > 0) {
echo "<center>"._CONTENTCATEGORIES."</center><br><br>"
."<table border=\"3\" align=\"center\" width=\"95%\">";
while ($row = $db->sql_fetchrow($result)) {
$cid = intval($row['cid']);
$title = filter($row['title'], "nohtml");
$description = filter($row['description']);
$numrows3 = $db->sql_numrows($db->sql_query("SELECT * FROM ".$prefix."_pages WHERE cid='$cid'"));
if ($numrows3 > 0) {
echo "<tr><td valign=\"top\">&nbsp;<a href=\"modules.php?name=$module_name&pa=list_pages_categories&cid=$cid\">$title</a>&nbsp;</td>";
}
}
echo "</td></tr></table><br><br>"
."<center>"._NONCLASSCONT."</center><br><br>";
}
$result4 = $db->sql_query("SELECT pid, title, subtitle, clanguage FROM ".$prefix."_pages WHERE active='1' AND cid='0' ORDER BY date");
echo "<blockquote>";
while ($row4 = $db->sql_fetchrow($result4)) {
$pid = intval($row4['pid']);
$title = filter($row4['title'], "nohtml");
$subtitle = filter($row4['subtitle'], "nohtml");
$clanguage = $row4['clanguage'];
if ($multilingual == 1) {
$the_lang = "<img src=\"images/language/flag-".$clanguage.".png\" hspace=\"3\" border=\"0\" height=\"10\" width=\"20\">";
} else {
$the_lang = "";
}
if (!empty($subtitle)) {
$subtitle = " ($subtitle)";
} else {
$subtitle = "";
}
if (is_admin($admin)) {
echo "<strong><big>·</big></strong> $the_lang <a href=\"modules.php?name=$module_name&pa=showpage&pid=$pid\">$title</a> $subtitle [ <a href=\"".$admin_file.".php?op=content_edit&pid=$pid\">"._EDIT."</a> | <a href=\"".$admin_file.".php?op=content_change_status&pid=$pid&active=1\">"._DEACTIVATE."</a> | <a href=\"".$admin_file.".php?op=content_delete&pid=$pid\">"._DELETE."</a> ]<br>";
} else {
echo "<strong><big>·</big></strong> $the_lang <a href=\"modules.php?name=$module_name&pa=showpage&pid=$pid\">$title</a> $subtitle<br>";
}
}
echo "</blockquote>";
if (is_admin($admin)) {
$result5 = $db->sql_query("SELECT pid, cid, title, subtitle, clanguage FROM ".$prefix."_pages WHERE active='0' ORDER BY date");
echo "<br><br><center><b>"._YOURADMINLIST."</b></center><br><br>";
echo "<blockquote>";
while ($row5 = $db->sql_fetchrow($result5)) {
$pid = intval($row5['pid']);
$cid = intval($row5['cid']);
$title = filter($row5['title'], "nohtml");
$subtitle = filter($row5['subtitle'], "nohtml");
$clanguage = $row5['clanguage'];
if ($multilingual == 1) {
$the_lang = "<img src=\"images/language/flag-".$clanguage.".png\" hspace=\"3\" border=\"0\" height=\"10\" width=\"20\">";
} else {
$the_lang = "";
}
if (!empty($subtitle)) {
$subtitle = " ($subtitle) ";
} else {
$subtitle = " ";
}
echo "<strong><big>·</big></strong> $the_lang <a href=\"modules.php?name=$module_name&pa=showpage&pid=$pid\">$title</a> $subtitle [ <a href=\"".$admin_file.".php?op=content_edit&pid=$pid\">"._EDIT."</a> | <a href=\"".$admin_file.".php?op=content_change_status&pid=$pid&active=0\">"._ACTIVATE."</a> | <a href=\"".$admin_file.".php?op=content_delete&pid=$pid\">"._DELETE."</a> ]<br>";
}
echo "</blockquote>";
}
CloseTable();
include("footer.php");
}

Reply With Quote
Reply

Viewing: Codewalkers ForumsOtherTutorials > Matt Wade tutorial help - results over 2 columns


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway