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:
  #1  
Old October 17th, 2002, 06:56 PM
gagnonconsulting gagnonconsulting is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 5 gagnonconsulting User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Trouble with Matt's Column Sorting Tutorial

I am getting the following error when using the tutorial example that Matt provided on how to sort a retrieved table by column headings:

Fatal error: Call to undefined function: mysql_fetch_assoc()

Other functions, such as mysql_fetch_array() work. Is this a version problem, or am I missing something?

Thanks,
Rich

Reply With Quote
  #2  
Old October 17th, 2002, 07:01 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: 25
RE: Trouble with Matt's Column Sorting Tutorial

mysql_fetch_assoc was introduced in 4.0.3....

Reply With Quote
  #3  
Old October 15th, 2003, 08:27 PM
redneck_kiwi redneck_kiwi is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Talladega, AL 35160
Posts: 24 redneck_kiwi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: Trouble with Matt's Column Sorting Tutorial

I am working this same issue and have a similar problem. My database is called custinfo and the table involved is custcont.
Output from DESC custcont is:

+----------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+--------------+------+-----+---------+----------------+
| id | int(11) | | PRI | NULL | auto_increment |
| datecon | date | YES | | NULL | |
| ieipoc | varchar(25) | YES | | NULL | |
| custpoc | varchar(50) | YES | | NULL | |
| custname | varchar(25) | YES | | NULL | |
| subject | varchar(50) | YES | | NULL | |
| comment | varchar(250) | YES | | NULL | |
+----------+--------------+------+-----+---------+----------------+
7 rows in set (0.15 sec)

My code:

php Code:
Original - php Code
  1.  
  2. <HTML>
  3. <TITLE>Contact Database</TITLE>
  4. <BODY BGCOLOR="white" TEXT="black" LINK="blue" VLINK="violet" BACKGROUND="images/gray.gif">
  5. <CENTER><H1>Customer Contact Database</H1></CENTER>
  6.  
  7. <?php
  8. /* Set up to allow the user to sort the columns at will. The code following
  9. will allow this capacity */
  10. $default_sort = 'datecon';
  11. $allowed_order = array ('datecon', 'ieipoc', 'custpoc', 'custname');
  12.  
  13. /* If order is not set, or it is not in the allowed list, then set it to a defau
  14. lt value, otherwise, set it to what was passed in. */
  15. if (!isset ($_GET['order']) ||
  16.         !in_array ($_GET['order'], $allowed_order))
  17.         {
  18.                 $order = $default_sort;
  19.         }
  20. else
  21.         {
  22.                 $order = $_GET['order'];
  23.         }
  24.  
  25. /* Connect to the DB */
  26. mysql_connect ('localhost','root','********');
  27. mysql_select_db ('custinfo');
  28.  
  29. /* Construct and run our query */
  30. $query = "SELECT * FROM custcont ORDER BY $order";
  31. $result = mysql_query ($query);
  32.  
  33. /* Make sure data was retrieved */
  34. $numrows = mysql_num_rows($result);
  35.  
  36. if ($numrows ==0)
  37. {
  38.         echo "<CENTER>No Data Was Retrieved!</CENTER>";
  39.         exit;
  40. }
  41.  
  42. /* Now, grab the first row and start the table */
  43. $row = mysql_fetch_assoc($result);
  44.  
  45. echo '<TABLE BORDER=1>n';
  46. echo '<TR>n';
  47. foreach ($row as $heading=>$column)
  48. {
  49.         /* Check if the heading is in our allowed_order array
  50.                 If it is, hyperlink it so that we can order by
  51.                 this column. */
  52.         echo '<TD><B>';
  53.         if (in_array ($heading, $allowed_order))
  54.         {
  55.                 echo "<a href="{$_SERVER['PHP_SELF']}?order=$heading">$heading
  56. </A>";
  57.         }
  58.         else
  59.         {
  60.                 echo $heading;
  61.         }
  62.         echo '</B></TD>n';
  63. }
  64. echo '</TR>n';
  65.  
  66. /* Reset the $result set back to the first row and display the data */
  67. mysql_data_seek($result, 0);
  68. while ($row = mysql_fetch_assoc($result))
  69. {
  70.         echo '<TR>n';
  71.         foreach ($row as $column)
  72.         {
  73.                 echo '<TD>$column</TD>n';
  74.         }
  75.         echo '</TR>n';
  76. }
  77. echo '</TABLE>n';
  78.  
  79. /* End sort code */
  80.  
  81. ?>
  82.  
  83. <CENTER>
  84. <B><A TARGET="_blank" HREF="http://localhost/input.php">Input New Record
  85. </A></B>
  86. <B><A TARGET="_blank" HREF="http://localhost/search.php">Search For Reco
  87. rd</A></B>
  88. </CENTER>
  89. <P></P>
  90. <P></P>
  91. <BR></BR>
  92. <P><CENTER><I><B><H6>Copyright (c) 2003 by International Enterprises, Inc. All r
  93. ights reserved</H6></B></I></CENTER></P>
  94. </HTML>
  95.  


Output from this page is WEIRD:
IEI Face to Face Contact Database

IEI Customer Contact Database

n
n idn dateconn ieipocn custpocn custnamen subjectn commentn
n
n $columnn $columnn $columnn $columnn $columnn $columnn
$columnn
n

n

Input New Record Search For Record

Copyright (c) 2003 by International Enterprises, Inc. All rights reserved


Anyone have a clue to loan as to why the actual data is not displayed?

Thanks

rk

Reply With Quote
  #4  
Old October 15th, 2003, 09:39 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: 25
RE: Trouble with Matt's Column Sorting Tutorial

Try changing this line
'<TD>$column</TD>n';
so it would look like this:
'<TD>'.$column'.</TD>n';

Reply With Quote
  #5  
Old October 16th, 2003, 12:23 PM
redneck_kiwi redneck_kiwi is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Talladega, AL 35160
Posts: 24 redneck_kiwi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: Trouble with Matt's Column Sorting Tutorial

Doh! That fixed it. I looked and looked and looked at the code and didn;t see that I had the variable within the ticks....ah well, thanks for the pointer!

On another issue with this code, HOW can I change the column name display? Instead of 'datecon', I would prefer 'Date of Contact'? Also, can I prevent certain columns from being displayed at all? Would this be done from within the select statement?

TIA

rk

Reply With Quote
  #6  
Old October 16th, 2003, 12:36 PM
gagnonconsulting gagnonconsulting is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 5 gagnonconsulting User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: Trouble with Matt's Column Sorting Tutorial

Glad that helped. As far as column names, set them in the Select statement, like this:

$query = ("SELECT M.Firm, L.abrev Local, M.memberType Type, M.Name, M.Street, M.City, M.State, M.Zip, M.Phone, M.Ext, M.Fax, M.Email, M.WebURL"); $query .= (" FROM Member M, LocalAssn L");
$query .= (" WHERE M.LocalAssn_id=L.assn_id");

For instance, the word Local is substituted for the L.abrev column name in the results.

Rich

Reply With Quote
  #7  
Old October 16th, 2003, 12:41 PM
gagnonconsulting gagnonconsulting is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 5 gagnonconsulting User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: Trouble with Matt's Column Sorting Tutorial

If it is in the select statement, it will print, so change your select statement from * (all) to the explicit columns you want returned, as in the previous post example.

Rich

Reply With Quote
Reply

Viewing: Codewalkers ForumsOtherTutorials > Trouble with Matt's Column Sorting Tutorial


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




 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

Request Your Free Technology Downloads!
 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

Request Your Free Technology Downloads!
 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

Request Your Free Technology Downloads!
 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

Request Your Free Technology Downloads!
 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

Request Your Free Technology Downloads!
 

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




© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek