Current location: Hot Scripts Forums » Programming Languages » PHP » Want to make 3 Columns from my results..


Want to make 3 Columns from my results..

Reply
  #1 (permalink)  
Old 06-16-03, 02:53 PM
cebuy cebuy is offline
Newbie Coder
 
Join Date: Jun 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Want to make 3 Columns from my results..

With this code, I get an error. Look at http://www.localwebadvertising.com/local/2/us

Parse error: parse error, unexpected T_STRING, expecting ']' in /home/localweb/public_html/include/country.inc on line 30

PHP Code:

<?php

$db
=mysql_connect ("localhost""notable""nopass") or die ('I cannot connect to the database.');
mysql_select_db ("notable",$db); 

$sql="SELECT DISTINCT state * FROM notable";
$result=mysql_query($sql,$db);

//Store your states in an array, $state, and count them 

$n 0
while (
$row mysql_fetch_array($query_result)) { 
    
$state[] = $row['state']; 
    
$n++; 


// sort the array 

sort ($state); 

//if you want the 3 cols, div_point is number in each column 

$div_point floor(($n+2)/3); 


for (
$i=0$i<$div_point$i++) {  
    echo 
"<tr><td>$array[$i]</td>"
    echo 
"<td>$array[$i + $div_point]</td>"
    echo 
"<td>$array[$i + $div_point * 2]</td></tr>" 
}


echo 
"I want to go to <a href=\"/local/$url_affil_num/$url_country/$state/\">$state</a> </br>";

$cur++;

?>

Line 30 is echo "<td>$array[$i + $div_point]</td>";
Any idea what I am doing wrong?
Reply With Quote
  #2 (permalink)  
Old 06-16-03, 03:07 PM
!!! HotCGIScripts !!!'s Avatar
!!! HotCGIScripts !!! !!! HotCGIScripts !!! is offline
Guru Programmer
 
Join Date: Jun 2003
Location: USA
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
PHP Code:

for ($i=0$i<$div_point$i++) {  

    echo 
"<tr><td>".$array[$i]."</td>"
    echo 
"<td>".$array[$i $div_point]."</td>"
    echo 
"<td>".$array[$i $div_point 2]."</td></tr>" 

will work.
Reply With Quote
  #3 (permalink)  
Old 06-16-03, 03:19 PM
cebuy cebuy is offline
Newbie Coder
 
Join Date: Jun 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
I got these errors when I changed it...

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/localweb/public_html/include/country.inc on line 14

Warning: sort() expects parameter 1 to be array, null given in /home/localweb/public_html/include/country.inc on line 21
I want to go to
Reply With Quote
  #4 (permalink)  
Old 06-16-03, 04:00 PM
!!! HotCGIScripts !!!'s Avatar
!!! HotCGIScripts !!! !!! HotCGIScripts !!! is offline
Guru Programmer
 
Join Date: Jun 2003
Location: USA
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
Yes, of course.

"SELECT DISTINCT state * FROM notable"

is invalid query. May be remove * from it.
Reply With Quote
  #5 (permalink)  
Old 06-16-03, 04:35 PM
cebuy cebuy is offline
Newbie Coder
 
Join Date: Jun 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
ok. here is what I am trying to do.
Here is the mysql table info (will not add as many entries)
PHP Code:

  State   |   City

+--------+ -----------------+
   
AL          Crossville
   GA          Atlanta
   TN          Knoxville
   TN          Nashville
   TN          Memphis
   AL          Birmingham
   MS          Jackson  
   FL           Miami
   SC          Charleston
   CA          San Diego
   WA         Spokane 
   
OR          Portland
--------+---------------------- 
I want a result output of all the states alphabetically sorted in three columns.
This would result in something like ...
PHP Code:

AL        GA        SC

CA        MS        TN
FL        
OR        WA 
__________________
Thanks!
Chris Chandler
WebMaster of:
Loan Quote, Christian eBuy, & North Alabama,

Last edited by cebuy; 06-16-03 at 04:40 PM.
Reply With Quote
  #6 (permalink)  
Old 06-17-03, 12:40 AM
phpkid phpkid is offline
Hot Moderator ;)
 
Join Date: Jun 2003
Location: India
Posts: 69
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/localweb/public_html/include/country.inc on line 14

Warning: sort() expects parameter 1 to be array, null given in /home/localweb/public_html/include/country.inc on line 21
I want to go to
Means your query failed.
Try
SELECT DISTINCT state FROM table_name

Also, always make sure whether your query executed or not.

Do it like,

$query = 'your query goes here.';

$result = @mysql_query($query) or die('Can not execute query : ' . $query . "\n" . 'MySQL Said : '. mysql_error());

So if your query fails, it will tell you the query and why it failed.

Regards,
JD
__________________
http://www.phpkid.org
Reply With Quote
  #7 (permalink)  
Old 06-20-03, 04:46 AM
ridwank's Avatar
ridwank ridwank is offline
Newbie Coder
 
Join Date: Jun 2003
Location: Indonesia
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
THIS IS THE ALGORITHM FOR MAKING THREE COLUMN RESULT
But You could change the looping control structure
with mysql query.

<?
echo "<h3>ORIGINAL DATA </h3>";
$state=array("0","GA","SC","AL","MS","OR","FL","OR ","TN","CA");
for ($i=1;$i<count($state);$i++){
echo $state[$i]." . ";
}
sort ($state);

echo "<hr>";

echo "<h3>DISPLAYING HORISONTAL SORT </h3>";

echo "<table border=1><tr>";

for ($i=1;$i<count($state);$i++){
echo "<td><li>".$state[$i]."</td>";
if (($i % 3)==0){ echo "</tr><tr>"; }
}

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

echo "<hr>";

echo "<h3>DISPLAYING VERTICAL SORT</h3>";

echo "<table border=1><tr><td>";

for ($i=1;$i<count($state);$i++){
echo "<li>".$state[$i]."</li>";
if (($i % 3)==0){ echo "</td><td>"; }
}

echo "</td></tr></table>";
?>

__________________
-=ridwank=-

<b><a style='text-decoration:none' href="http://www.ridwank.com">CLICK : ridwank.com : PHP SCRIPT CENTER</a></b>

Last edited by ridwank; 06-20-03 at 05:19 AM.
Reply With Quote
  #8 (permalink)  
Old 06-20-03, 08:43 AM
jv2222 jv2222 is offline
The Freshmaker
 
Join Date: Jun 2003
Posts: 51
Thanks: 0
Thanked 0 Times in 0 Posts
This might help make your life easier when it comes to working with mySQL:

http://www.hotscripts.com/Detailed/18290.html

Cheers,
Justin
Reply With Quote
  #9 (permalink)  
Old 06-20-03, 10:17 AM
cebuy cebuy is offline
Newbie Coder
 
Join Date: Jun 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
THanks I will look into that.
Reply With Quote
  #10 (permalink)  
Old 06-20-03, 12:49 PM
MGCJerry's Avatar
MGCJerry MGCJerry is offline
Newbie Coder
 
Join Date: Jun 2003
Location: FL
Posts: 75
Thanks: 0
Thanked 1 Time in 1 Post
Quote:
Originally posted by jv2222
This might help make your life easier when it comes to working with mySQL:

http://www.hotscripts.com/Detailed/18290.html

Cheers,
Justin
I'm currently using this for a larger project, and it works wonders.

No, I'm not affiliated with them I just like using it.
__________________
Nothing witty...
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Best way to make money w PHP? jv2222 The Lounge 73 07-06-09 11:06 PM
query results in multiple columns SnowCrash PHP 2 10-09-03 03:08 AM
how to make a var with an alert ChaosKiller PHP 0 09-21-03 07:43 AM
Which way to display results from mysql Peter_web PHP 2 09-13-03 05:39 PM
Using CDONTS to email Checkbox results AkaMadDiSk ASP 1 07-23-03 05:32 PM


All times are GMT -5. The time now is 05:57 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.